[libhandy/benzea/fix-combo-row-checkmark] combo-row: Improve checkmark visibility update routine
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/benzea/fix-combo-row-checkmark] combo-row: Improve checkmark visibility update routine
- Date: Fri, 22 Jan 2021 09:10:53 +0000 (UTC)
commit d400bd184ecb424206e62409620e8bb5ca22c6df
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 | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
---
diff --git a/src/hdy-combo-row.c b/src/hdy-combo-row.c
index de19ed1b..b40b9aa6 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;
+ gint 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,18 +198,12 @@ 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 (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));
- for (l = rows; l; l = l->next) {
- GtkWidget *row = GTK_WIDGET (l->data);
- 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);
- }
+ gtk_widget_set_opacity (GTK_WIDGET (g_object_get_data (G_OBJECT (box), "checkmark")),
+ (priv->selected_index == i) ? 1 : 0);
}
item = g_list_model_get_item (priv->bound_model, priv->selected_index);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]