From: Alberto Garcia Date: Tue, 21 Apr 2009 18:05:45 +0000 (+0200) Subject: Optimize hildon_app_menu_repack_items() to resize the table just once X-Git-Tag: 2.1.76-1~12 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=7220b337024634b242f2c7f4ccc731535d77bd31;p=hildon Optimize hildon_app_menu_repack_items() to resize the table just once * hildon/hildon-app-menu.c (hildon_app_menu_repack_items): Resize table before adding new items to make sure that gtk_table_resize() is called just once. --- diff --git a/ChangeLog b/ChangeLog index c41fc62..990a489 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-05-25 Alberto Garcia + * hildon/hildon-app-menu.c (hildon_app_menu_repack_items): + Resize table before adding new items to make sure that + gtk_table_resize() is called just once. + +2009-05-25 Alberto Garcia + * hildon/hildon-app-menu-private.h * hildon/hildon-app-menu.c (item_visibility_changed) (filter_visibility_changed, hildon_app_menu_show_all) diff --git a/hildon/hildon-app-menu.c b/hildon/hildon-app-menu.c index 7e838e4..8b6974d 100644 --- a/hildon/hildon-app-menu.c +++ b/hildon/hildon-app-menu.c @@ -868,14 +868,18 @@ hildon_app_menu_repack_items (HildonAppMenu *menu, gint start_from) { HildonAppMenuPrivate *priv; - gint row, col; + gint row, col, nvisible, i; GList *iter; priv = HILDON_APP_MENU_GET_PRIVATE(menu); - /* Remove buttons from their parent */ - if (start_from != -1) { - for (iter = g_list_nth (priv->buttons, start_from); iter != NULL; iter = iter->next) { + i = nvisible = 0; + for (iter = priv->buttons; iter != NULL; iter = iter->next) { + /* Count number of visible items */ + if (GTK_WIDGET_VISIBLE (iter->data)) + nvisible++; + /* Remove buttons from their parent */ + if (start_from != -1 && i >= start_from) { GtkWidget *item = GTK_WIDGET (iter->data); GtkWidget *parent = gtk_widget_get_parent (item); if (parent) { @@ -883,10 +887,16 @@ hildon_app_menu_repack_items (HildonAppMenu *menu, gtk_container_remove (GTK_CONTAINER (parent), item); } } + i++; + } - /* If items have been removed, recalculate the size of the menu */ + /* If items have been removed, recalculate the size of the menu */ + if (start_from != -1) gtk_window_resize (GTK_WINDOW (menu), 1, 1); - } + + /* Set the final size now to avoid unnecessary resizes later */ + if (nvisible > 0) + gtk_table_resize (priv->table, ((nvisible - 1) / priv->columns) + 1, priv->columns); /* Add buttons */ row = col = 0; @@ -906,14 +916,6 @@ hildon_app_menu_repack_items (HildonAppMenu *menu, } } } - - /* The number of rows/columns might have changed, so we have to - * resize the table */ - if (col == 0) { - gtk_table_resize (priv->table, MAX (row, 1), priv->columns); - } else { - gtk_table_resize (priv->table, row + 1, priv->columns); - } } /**