From 5285a413bf8b70cb36ca7c0b11ad00b6a37fa0cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 8 Mar 2026 11:05:08 -0700 Subject: [PATCH] GridView: make page size constants --- src/Views/GridView.vala | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/Views/GridView.vala b/src/Views/GridView.vala index c55090a7..fd1e7ec7 100644 --- a/src/Views/GridView.vala +++ b/src/Views/GridView.vala @@ -7,20 +7,16 @@ public class Slingshot.Widgets.Grid : Gtk.Box { public signal void app_launched (); - private struct Page { - public uint rows; - public uint columns; - } + private const int PAGE_ROWS = 3; + private const int PAGE_COLUMNS = 5; private Hdy.Carousel paginator; - private Page page; - private Gtk.EventControllerKey key_controller; private uint _focused_column = 1; public uint focused_column { set { - var target_column = value.clamp (1, page.columns); + var target_column = value.clamp (1, PAGE_COLUMNS); var target = get_widget_at (target_column, _focused_row); if (target != null && target is Widgets.AppButton) { _focused_column = target_column; @@ -36,7 +32,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box { private uint _focused_row = 1; public uint focused_row { set { - var target_row = value.clamp (1, page.rows); + var target_row = value.clamp (1, PAGE_ROWS); var target = get_widget_at (_focused_column, target_row); if (target != null && target is Widgets.AppButton) { _focused_row = target_row; @@ -69,9 +65,6 @@ public class Slingshot.Widgets.Grid : Gtk.Box { } construct { - page.rows = 3; - page.columns = 5; - paginator = new Hdy.Carousel () { hexpand = true, vexpand = true @@ -114,12 +107,12 @@ public class Slingshot.Widgets.Grid : Gtk.Box { var app_button = new Widgets.AppButton (app); app_button.app_launched.connect (() => app_launched ()); - if (next_col_index == page.columns) { + if (next_col_index == PAGE_COLUMNS) { next_col_index = 0; next_row_index++; } - if (next_row_index == page.rows) { + if (next_row_index == PAGE_ROWS) { grid = add_new_grid (); next_row_index = 0; next_col_index = 0; @@ -147,8 +140,8 @@ public class Slingshot.Widgets.Grid : Gtk.Box { }; // Fake grids in case there are not enough apps to fill the grid - for (var row = 0; row < page.rows; row++) { - for (var column = 0; column < page.columns; column++) { + for (var row = 0; row < PAGE_ROWS; row++) { + for (var column = 0; column < PAGE_COLUMNS; column++) { grid.attach (new Gtk.Grid (), column, row, 1, 1); } } @@ -160,7 +153,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box { } private Gtk.Widget? get_widget_at (uint col, uint row) { - if (col < 1 || col > page.columns || row < 1 || row > page.rows) { + if (col < 1 || col > PAGE_COLUMNS || row < 1 || row > PAGE_ROWS) { return null; } else { var grid = (Gtk.Grid) paginator.get_children ().nth_data ((int) paginator.get_position ()); @@ -240,7 +233,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box { current_grid_key--; } else if (focused_column == 1 && current_grid_key > 1) { current_grid_key--; - focused_column = page.columns; + focused_column = PAGE_COLUMNS; } else { focused_column--; } @@ -249,7 +242,7 @@ public class Slingshot.Widgets.Grid : Gtk.Box { private void move_right (Gdk.ModifierType state) { if ((state & Gdk.ModifierType.SHIFT_MASK) > 0) { current_grid_key++; - } else if (focused_column == page.columns && current_grid_key < paginator.n_pages) { + } else if (focused_column == PAGE_COLUMNS && current_grid_key < paginator.n_pages) { current_grid_key++; focused_column = 1; } else {