[gtk+] headerbar: simplify some size allocation code
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] headerbar: simplify some size allocation code
- Date: Sat, 25 Jun 2016 00:59:57 +0000 (UTC)
commit eccfce50d6835206f7260937579bf363bdec1477
Author: Ray Strode <rstrode redhat com>
Date: Fri Jun 24 07:57:06 2016 -0400
headerbar: simplify some size allocation code
With a headerbar, the widget in the center may be a label, constructed
internally, or a custom widget, constructed externally. The size
allocation code needs to handle either case the same way for the most
part. There's more than one place in the code that checks which of
the two widgets to use and does some operation on the selected one.
This commit simplifies the code by checking up front which one is the
center (title) widget and storing that in a temporary variable,
This allows reducing duplicated logic later on in the function.
https://bugzilla.gnome.org/show_bug.cgi?id=724332
gtk/gtkheaderbar.c | 32 ++++++++++++++------------------
1 files changed, 14 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index c16cf8a..eba695b 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -989,6 +989,7 @@ gtk_header_bar_allocate_contents (GtkCssGadget *gadget,
gpointer unused)
{
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
+ GtkWidget *title_widget;
GtkHeaderBar *bar = GTK_HEADER_BAR (widget);
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
GtkRequestedSize *sizes;
@@ -1034,21 +1035,19 @@ gtk_header_bar_allocate_contents (GtkCssGadget *gadget,
title_minimum_size = 0;
title_natural_size = 0;
- if (priv->custom_title &&
+ if (priv->custom_title != NULL &&
gtk_widget_get_visible (priv->custom_title))
- {
- gtk_widget_get_preferred_width_for_height (priv->custom_title,
- height,
- &title_minimum_size,
- &title_natural_size);
- }
+ title_widget = priv->custom_title;
else if (priv->label_box != NULL)
- {
- gtk_widget_get_preferred_width_for_height (priv->label_box,
- height,
- &title_minimum_size,
- &title_natural_size);
- }
+ title_widget = priv->label_box;
+ else
+ title_widget = NULL;
+
+ if (title_widget)
+ gtk_widget_get_preferred_width_for_height (title_widget,
+ height,
+ &title_minimum_size,
+ &title_natural_size);
width -= title_natural_size;
start_width = 0;
@@ -1146,11 +1145,8 @@ gtk_header_bar_allocate_contents (GtkCssGadget *gadget,
if (direction == GTK_TEXT_DIR_RTL)
child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) -
child_allocation.width;
- if (priv->custom_title != NULL &&
- gtk_widget_get_visible (priv->custom_title))
- gtk_widget_size_allocate (priv->custom_title, &child_allocation);
- else if (priv->label_box != NULL)
- gtk_widget_size_allocate (priv->label_box, &child_allocation);
+ if (title_widget != NULL)
+ gtk_widget_size_allocate (title_widget, &child_allocation);
child_allocation.y = allocation->y;
child_allocation.height = height;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]