[libhandy/benzea/fix-combo-row-checkmark: 2/2] combo-row: Improve checkmark visibility update routine




commit 8a76c8228ab9146744d729504b9d08a5b3350b9c
Author: Benjamin Berg <bberg redhat com>
Date:   Thu Jan 21 17:29:49 2021 +0100

    combo-row: Improve checkmark visibility update routine
    
    Going through the children of a list box is not a good idea. It may
    insert e.g. separators and similar that we don't know about.
    
    Simplify the code to use gtk_list_box_get_row_at_index instead.

 src/hdy-combo-row.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
---
diff --git a/src/hdy-combo-row.c b/src/hdy-combo-row.c
index de19ed1b..8d426dde 100644
--- a/src/hdy-combo-row.c
+++ b/src/hdy-combo-row.c
@@ -181,6 +181,7 @@ update (HdyComboRow *self)
   g_autofree gchar *name = NULL;
   GtkWidget *widget;
   guint n_items = priv->bound_model ? g_list_model_get_n_items (priv->bound_model) : 0;
+  int i;
 
   gtk_widget_set_visible (GTK_WIDGET (priv->current), !priv->use_subtitle);
   gtk_container_foreach (GTK_CONTAINER (priv->current), (GtkCallback) gtk_widget_destroy, NULL);
@@ -197,19 +198,14 @@ update (HdyComboRow *self)
 
   g_assert (priv->selected_index >= 0 && priv->selected_index <= n_items);
 
-  {
-    g_autoptr (GList) rows = gtk_container_get_children (GTK_CONTAINER (priv->list));
-    GList *l;
-    int i = 0;
-
-    for (l = rows; l; l = l->next) {
-      GtkWidget *row = GTK_WIDGET (l->data);
+  for (i = 0; i < n_items; i++)
+    {
+      GtkListBoxRow *row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (priv->list), i);
       GtkWidget *box = gtk_bin_get_child (GTK_BIN (row));
 
       gtk_widget_set_opacity (GTK_WIDGET (g_object_get_data (G_OBJECT (box), "checkmark")),
-                              (priv->selected_index == i++) ? 1 : 0);
+                              (priv->selected_index == i) ? 1 : 0);
     }
-  }
 
   item = g_list_model_get_item (priv->bound_model, priv->selected_index);
   if (priv->use_subtitle) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]