From 37b8a5cb27cea9569b975aabc8c96272ac590ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 9 Apr 2026 13:23:06 -0700 Subject: [PATCH 1/2] VAutoHider: use ListBox --- data/Application.css | 4 ++ src/Grid/VAutoHider.vala | 96 +++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/data/Application.css b/data/Application.css index 5a0a66835..ca75f8f9c 100644 --- a/data/Application.css +++ b/data/Application.css @@ -69,6 +69,10 @@ margin: 3px; } +.cell list { + background: inherit; +} + .event { background: @selected_bg_color; border-radius: 3px; diff --git a/src/Grid/VAutoHider.vala b/src/Grid/VAutoHider.vala index aca35a0d3..50b38d688 100644 --- a/src/Grid/VAutoHider.vala +++ b/src/Grid/VAutoHider.vala @@ -8,28 +8,24 @@ public class Maya.View.VAutoHider : Gtk.Bin { private Gtk.Label more_label; - private Gtk.Box main_box; + private Gtk.ListBox main_box; construct { more_label = new Gtk.Label ("") { valign = END }; - main_box = new Gtk.Box (VERTICAL, 0); - main_box.pack_end (more_label); + main_box = new Gtk.ListBox (); + main_box.set_sort_func (sort_func); + + main_box.add (more_label); base.add (main_box); } public override void add (Gtk.Widget widget) { - var children = main_box.get_children (); - children.append (widget); - - children.sort (compare_children); - - int index = children.index (widget); main_box.add (widget); - main_box.reorder_child (widget, index); + main_box.invalidate_sort (); widget.destroy.connect (() => { queue_resize (); @@ -39,67 +35,53 @@ public class Maya.View.VAutoHider : Gtk.Bin { } public void update (Gtk.Widget widget) { - var children = main_box.get_children (); - - children.sort (compare_children); - - int index = children.index (widget); - main_box.reorder_child (widget, index); + main_box.invalidate_sort (); } public override void size_allocate (Gtk.Allocation allocation) { base.size_allocate (allocation); - int global_height = allocation.height; - int children_length = (int)main_box.get_children ().length () - 1; - if (children_length == 0) { + + if (main_box.get_row_at_index (1) == null) { more_label.hide (); return; } - int height = 0; int more_label_height; - int shown_children = 0; more_label.show (); more_label.vexpand = false; more_label.get_preferred_height (out more_label_height, null); - more_label.vexpand = true; more_label.hide (); - foreach (var child in main_box.get_children ()) { - if (child == more_label) - continue; - bool last = (shown_children == children_length - 1); + int global_height = allocation.height; + int height = 0; + int shown_children = 0; + for (int i = 0; main_box.get_row_at_index (i) != null; i++) { + var child = main_box.get_row_at_index (i); + + if (((Gtk.ListBoxRow) child).get_child () == more_label) { + continue; + } int child_height; child.show (); child.get_preferred_height (out child_height, null); - ((Maya.View.EventButton) child).hide_without_animate (); - bool should_hide; if (global_height - more_label_height < child_height + height) { - should_hide = true; - if (last && (global_height >= child_height + height)) { - should_hide = false; - } - } else { - should_hide = false; - height += child_height; + child.hide (); + continue; } - if (should_hide) { - ((Maya.View.EventButton) child).hide_without_animate (); - } else { - ((Maya.View.EventButton) child).show_without_animate (); - shown_children++; - } + ((Maya.View.EventButton) ((Gtk.ListBoxRow) child).get_child ()).show_without_animate (); + height += child_height; + shown_children++; } - int more = children_length - shown_children; - if (shown_children != children_length && more > 0) { + var children_length = (int) main_box.get_children ().length () - 1; + var more = children_length - shown_children; + if (more > 0) { more_label.show (); - more_label.set_label (_("%u more…").printf ((uint)more)); - } else { - more_label.hide (); + more_label.vexpand = true; + more_label.label = _("%i more…").printf (more); } } @@ -117,16 +99,18 @@ public class Maya.View.VAutoHider : Gtk.Bin { natural_height = minimum_height; } - public static GLib.CompareFunc compare_children = (a, b) => { - EventButton a2 = a as EventButton; - EventButton b2 = b as EventButton; - - if (a2 == null) { + private static int sort_func (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { + if (row1.get_child () is Gtk.Label) { return 1; - } else if (b2 == null) { - return 0; - } else { - return Util.compare_events (a2.comp, b2.comp); } - }; + + if (row2.get_child () is Gtk.Label) { + return -1; + } + + var button_1 = (EventButton) row1.get_child (); + var button_2 = (EventButton) row2.get_child (); + + return Util.compare_events (button_1.comp, button_2.comp); + } } From eeb996d6979a5e249bd08782ec7c62a183a25df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 13 Apr 2026 10:32:03 -0700 Subject: [PATCH 2/2] more minor cleanup --- src/Grid/VAutoHider.vala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Grid/VAutoHider.vala b/src/Grid/VAutoHider.vala index fd0d8b9e9..a5d9208fb 100644 --- a/src/Grid/VAutoHider.vala +++ b/src/Grid/VAutoHider.vala @@ -8,7 +8,6 @@ public class Maya.View.VAutoHider : Gtk.Bin { private Gtk.Label more_label; - private Gtk.ListBox list_box; private GLib.ListStore event_store; construct { @@ -22,7 +21,7 @@ public class Maya.View.VAutoHider : Gtk.Bin { var list_box = new Gtk.ListBox (); list_box.bind_model (event_store, create_widget_func); - base.add (list_box); + child = list_box; } public void append (EventButton event_button) { @@ -35,13 +34,13 @@ public class Maya.View.VAutoHider : Gtk.Bin { queue_resize (); } - public void update (Gtk.Widget widget) { + public void update (EventButton widget) { uint index = -1; if (event_store.find (widget, out index)) { event_store.remove (index); } - event_store.insert_sorted (widget, compare_func); + append (widget); } public override void size_allocate (Gtk.Allocation allocation) {