77public class Slingshot.Widgets.Grid : Gtk .Box {
88 public signal void app_launched ();
99
10- private struct Page {
11- public uint rows;
12- public uint columns;
13- }
10+ private const int PAGE_ROWS = 3 ;
11+ private const int PAGE_COLUMNS = 5 ;
1412
1513 private Hdy . Carousel paginator;
16- private Page page;
17-
1814 private Gtk . EventControllerKey key_controller;
1915
2016 private uint _focused_column = 1 ;
2117 public uint focused_column {
2218 set {
23- var target_column = value . clamp (1 , page . columns );
19+ var target_column = value . clamp (1 , PAGE_COLUMNS );
2420 var target = get_widget_at (target_column, _focused_row);
2521 if (target != null && target is Widgets . AppButton ) {
2622 _focused_column = target_column;
@@ -36,7 +32,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
3632 private uint _focused_row = 1 ;
3733 public uint focused_row {
3834 set {
39- var target_row = value . clamp (1 , page . rows );
35+ var target_row = value . clamp (1 , PAGE_ROWS );
4036 var target = get_widget_at (_focused_column, target_row);
4137 if (target != null && target is Widgets . AppButton ) {
4238 _focused_row = target_row;
@@ -69,9 +65,6 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
6965 }
7066
7167 construct {
72- page. rows = 3 ;
73- page. columns = 5 ;
74-
7568 paginator = new Hdy .Carousel () {
7669 hexpand = true ,
7770 vexpand = true
@@ -114,12 +107,12 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
114107 var app_button = new Widgets .AppButton (app);
115108 app_button. app_launched. connect (() = > app_launched ());
116109
117- if (next_col_index == page . columns ) {
110+ if (next_col_index == PAGE_COLUMNS ) {
118111 next_col_index = 0 ;
119112 next_row_index++ ;
120113 }
121114
122- if (next_row_index == page . rows ) {
115+ if (next_row_index == PAGE_ROWS ) {
123116 grid = add_new_grid ();
124117 next_row_index = 0 ;
125118 next_col_index = 0 ;
@@ -147,8 +140,8 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
147140 };
148141
149142 // Fake grids in case there are not enough apps to fill the grid
150- for (var row = 0 ; row < page . rows ; row++ ) {
151- for (var column = 0 ; column < page . columns ; column++ ) {
143+ for (var row = 0 ; row < PAGE_ROWS ; row++ ) {
144+ for (var column = 0 ; column < PAGE_COLUMNS ; column++ ) {
152145 grid. attach (new Gtk .Grid (), column, row, 1 , 1 );
153146 }
154147 }
@@ -160,7 +153,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
160153 }
161154
162155 private Gtk .Widget ? get_widget_at (uint col , uint row ) {
163- if (col < 1 || col > page . columns || row < 1 || row > page . rows ) {
156+ if (col < 1 || col > PAGE_COLUMNS || row < 1 || row > PAGE_ROWS ) {
164157 return null ;
165158 } else {
166159 var grid = (Gtk . Grid ) paginator. get_children (). nth_data ((int ) paginator. get_position ());
@@ -240,7 +233,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
240233 current_grid_key-- ;
241234 } else if (focused_column == 1 && current_grid_key > 1 ) {
242235 current_grid_key-- ;
243- focused_column = page . columns ;
236+ focused_column = PAGE_COLUMNS ;
244237 } else {
245238 focused_column-- ;
246239 }
@@ -249,7 +242,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box {
249242 private void move_right (Gdk .ModifierType state ) {
250243 if ((state & Gdk . ModifierType . SHIFT_MASK ) > 0 ) {
251244 current_grid_key++ ;
252- } else if (focused_column == page . columns && current_grid_key < paginator. n_pages) {
245+ } else if (focused_column == PAGE_COLUMNS && current_grid_key < paginator. n_pages) {
253246 current_grid_key++ ;
254247 focused_column = 1 ;
255248 } else {
0 commit comments