[gtk+/wip/cosimoc/menuitem-gadget: 14/21] checkmenuitem: prefer early return
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cosimoc/menuitem-gadget: 14/21] checkmenuitem: prefer early return
- Date: Sat, 19 Dec 2015 02:01:15 +0000 (UTC)
commit aecff97020317d861791329e3cddc983dcdb377c
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Dec 18 09:59:23 2015 -0800
checkmenuitem: prefer early return
gtk/gtkcheckmenuitem.c | 93 +++++++++++++++++++++++------------------------
1 files changed, 46 insertions(+), 47 deletions(-)
---
diff --git a/gtk/gtkcheckmenuitem.c b/gtk/gtkcheckmenuitem.c
index b14e35c..4ed3f5c 100644
--- a/gtk/gtkcheckmenuitem.c
+++ b/gtk/gtkcheckmenuitem.c
@@ -637,62 +637,61 @@ gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
{
GtkCheckMenuItemPrivate *priv = check_menu_item->priv;
GtkWidget *widget;
+ GtkAllocation allocation;
+ GtkStyleContext *context;
+ guint border_width;
+ guint offset;
+ guint toggle_size;
+ guint toggle_spacing;
+ guint indicator_size;
gint x, y;
+ GtkStateFlags state;
+ GtkBorder padding;
widget = GTK_WIDGET (check_menu_item);
- if (gtk_widget_is_drawable (widget))
- {
- GtkAllocation allocation;
- GtkStyleContext *context;
- guint border_width;
- guint offset;
- guint toggle_size;
- guint toggle_spacing;
- guint indicator_size;
- GtkStateFlags state;
- GtkBorder padding;
-
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
- gtk_style_context_get_padding (context, state, &padding);
-
- gtk_widget_get_allocation (widget, &allocation);
-
- gtk_widget_style_get (widget,
- "toggle-spacing", &toggle_spacing,
- "indicator-size", &indicator_size,
- NULL);
-
- toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size;
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- offset = border_width + padding.left + 2;
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
- {
- x = offset +
- (toggle_size - toggle_spacing - indicator_size) / 2;
- }
- else
- {
- x = allocation.width -
- offset - toggle_size + toggle_spacing +
- (toggle_size - toggle_spacing - indicator_size) / 2;
- }
+ if (!gtk_widget_is_drawable (widget))
+ return;
- y = (allocation.height - indicator_size) / 2;
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, state, &padding);
- gtk_style_context_save_to_node (context, priv->indicator_node);
+ gtk_widget_get_allocation (widget, &allocation);
- if (priv->draw_as_radio)
- gtk_render_option (context, cr, x, y,
- indicator_size, indicator_size);
- else
- gtk_render_check (context, cr, x, y,
- indicator_size, indicator_size);
+ gtk_widget_style_get (widget,
+ "toggle-spacing", &toggle_spacing,
+ "indicator-size", &indicator_size,
+ NULL);
- gtk_style_context_restore (context);
+ toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size;
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ offset = border_width + padding.left + 2;
+
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+ {
+ x = offset +
+ (toggle_size - toggle_spacing - indicator_size) / 2;
+ }
+ else
+ {
+ x = allocation.width -
+ offset - toggle_size + toggle_spacing +
+ (toggle_size - toggle_spacing - indicator_size) / 2;
}
+
+ y = (allocation.height - indicator_size) / 2;
+
+ gtk_style_context_save_to_node (context, priv->indicator_node);
+
+ if (priv->draw_as_radio)
+ gtk_render_option (context, cr, x, y,
+ indicator_size, indicator_size);
+ else
+ gtk_render_check (context, cr, x, y,
+ indicator_size, indicator_size);
+
+ gtk_style_context_restore (context);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]