[gtk+/wip/cosimoc/bars-gadget: 3/8] menubar: prefer early return
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cosimoc/bars-gadget: 3/8] menubar: prefer early return
- Date: Sun, 3 Jan 2016 02:48:19 +0000 (UTC)
commit f924f68a931d134fc65c231d58b26964e8ca300b
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Jan 2 14:59:56 2016 -0800
menubar: prefer early return
gtk/gtkmenubar.c | 181 +++++++++++++++++++++++++++---------------------------
1 files changed, 91 insertions(+), 90 deletions(-)
---
diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c
index b26ffe4..ef117eb 100644
--- a/gtk/gtkmenubar.c
+++ b/gtk/gtkmenubar.c
@@ -512,124 +512,125 @@ gtk_menu_bar_allocate (GtkCssGadget *gadget,
menu_shell = GTK_MENU_SHELL (widget);
priv = menu_bar->priv;
- if (menu_shell->priv->children)
- {
- remaining_space = *allocation;
- requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize));
+ if (!menu_shell->priv->children)
+ return;
- if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
- priv->pack_direction == GTK_PACK_DIRECTION_RTL)
- {
- int size = remaining_space.width;
- gboolean ltr = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (priv->pack_direction ==
GTK_PACK_DIRECTION_LTR);
+ remaining_space = *allocation;
+ requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize));
- for (children = menu_shell->priv->children; children; children = children->next)
- {
- GtkRequestedSize request;
- child = children->data;
+ if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
+ priv->pack_direction == GTK_PACK_DIRECTION_RTL)
+ {
+ int size = remaining_space.width;
+ gboolean ltr = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (priv->pack_direction ==
GTK_PACK_DIRECTION_LTR);
- if (!gtk_widget_get_visible (child))
- continue;
+ for (children = menu_shell->priv->children; children; children = children->next)
+ {
+ GtkRequestedSize request;
+ child = children->data;
- request.data = child;
- gtk_widget_get_preferred_width_for_height (child,
- remaining_space.height,
- &request.minimum_size,
- &request.natural_size);
- gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
- &toggle_size);
- request.minimum_size += toggle_size;
- request.natural_size += toggle_size;
+ if (!gtk_widget_get_visible (child))
+ continue;
- gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size);
+ request.data = child;
+ gtk_widget_get_preferred_width_for_height (child,
+ remaining_space.height,
+ &request.minimum_size,
+ &request.natural_size);
+ gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
+ &toggle_size);
+ request.minimum_size += toggle_size;
+ request.natural_size += toggle_size;
- g_array_append_val (requested_sizes, request);
+ gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size);
- size -= request.minimum_size;
- }
+ g_array_append_val (requested_sizes, request);
- size = gtk_distribute_natural_allocation (size,
- requested_sizes->len,
- (GtkRequestedSize *) requested_sizes->data);
+ size -= request.minimum_size;
+ }
- for (i = 0; i < requested_sizes->len; i++)
- {
- GtkAllocation child_allocation = remaining_space;
- GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i);
+ size = gtk_distribute_natural_allocation (size,
+ requested_sizes->len,
+ (GtkRequestedSize *) requested_sizes->data);
- child_allocation.width = request->minimum_size;
- remaining_space.width -= request->minimum_size;
+ for (i = 0; i < requested_sizes->len; i++)
+ {
+ GtkAllocation child_allocation = remaining_space;
+ GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i);
- if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
- GTK_MENU_ITEM (request->data)->priv->right_justify)
- ltr = !ltr;
+ child_allocation.width = request->minimum_size;
+ remaining_space.width -= request->minimum_size;
- if (ltr)
- remaining_space.x += request->minimum_size;
- else
- child_allocation.x += remaining_space.width;
+ if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
+ GTK_MENU_ITEM (request->data)->priv->right_justify)
+ ltr = !ltr;
- gtk_widget_size_allocate (request->data, &child_allocation);
- }
- }
- else
- {
- int size = remaining_space.height;
- gboolean ttb = (priv->pack_direction == GTK_PACK_DIRECTION_TTB);
+ if (ltr)
+ remaining_space.x += request->minimum_size;
+ else
+ child_allocation.x += remaining_space.width;
- for (children = menu_shell->priv->children; children; children = children->next)
- {
- GtkRequestedSize request;
- child = children->data;
+ gtk_widget_size_allocate (request->data, &child_allocation);
+ }
+ }
+ else
+ {
+ int size = remaining_space.height;
+ gboolean ttb = (priv->pack_direction == GTK_PACK_DIRECTION_TTB);
- if (!gtk_widget_get_visible (child))
- continue;
+ for (children = menu_shell->priv->children; children; children = children->next)
+ {
+ GtkRequestedSize request;
+ child = children->data;
- request.data = child;
- gtk_widget_get_preferred_height_for_width (child,
- remaining_space.width,
- &request.minimum_size,
- &request.natural_size);
- gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
- &toggle_size);
- request.minimum_size += toggle_size;
- request.natural_size += toggle_size;
+ if (!gtk_widget_get_visible (child))
+ continue;
- gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size);
+ request.data = child;
+ gtk_widget_get_preferred_height_for_width (child,
+ remaining_space.width,
+ &request.minimum_size,
+ &request.natural_size);
+ gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
+ &toggle_size);
+ request.minimum_size += toggle_size;
+ request.natural_size += toggle_size;
- g_array_append_val (requested_sizes, request);
+ gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size);
- size -= request.minimum_size;
- }
+ g_array_append_val (requested_sizes, request);
- size = gtk_distribute_natural_allocation (size,
- requested_sizes->len,
- (GtkRequestedSize *) requested_sizes->data);
+ size -= request.minimum_size;
+ }
- for (i = 0; i < requested_sizes->len; i++)
- {
- GtkAllocation child_allocation = remaining_space;
- GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i);
+ size = gtk_distribute_natural_allocation (size,
+ requested_sizes->len,
+ (GtkRequestedSize *) requested_sizes->data);
- child_allocation.height = request->minimum_size;
- remaining_space.height -= request->minimum_size;
+ for (i = 0; i < requested_sizes->len; i++)
+ {
+ GtkAllocation child_allocation = remaining_space;
+ GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i);
- if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
- GTK_MENU_ITEM (request->data)->priv->right_justify)
- ttb = !ttb;
+ child_allocation.height = request->minimum_size;
+ remaining_space.height -= request->minimum_size;
- if (ttb)
- remaining_space.y += request->minimum_size;
- else
- child_allocation.y += remaining_space.height;
+ if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
+ GTK_MENU_ITEM (request->data)->priv->right_justify)
+ ttb = !ttb;
- gtk_widget_size_allocate (request->data, &child_allocation);
- }
- }
+ if (ttb)
+ remaining_space.y += request->minimum_size;
+ else
+ child_allocation.y += remaining_space.height;
- g_array_free (requested_sizes, TRUE);
+ gtk_widget_size_allocate (request->data, &child_allocation);
+ }
}
+
+ g_array_free (requested_sizes, TRUE);
}
+
static void
gtk_menu_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]