[gtk] label: Simplify ensure_layout()
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] label: Simplify ensure_layout()
- Date: Sun, 4 Mar 2018 18:17:14 +0000 (UTC)
commit 891c37a4cbad0705fa0ffca004d3cfe46885d8e0
Author: Timm Bäder <mail baedert org>
Date: Wed Feb 28 15:27:48 2018 +0100
label: Simplify ensure_layout()
use an early return for an already existing layout.
gtk/gtklabel.c | 70 +++++++++++++++++++++++++++-------------------------------
1 file changed, 33 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 33e978676a..086bc6cb0f 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3335,50 +3335,46 @@ static void
gtk_label_ensure_layout (GtkLabel *label)
{
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
- GtkWidget *widget;
+ PangoAlignment align;
gboolean rtl;
- widget = GTK_WIDGET (label);
-
- rtl = _gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
-
- if (!priv->layout)
- {
- PangoAlignment align = PANGO_ALIGN_LEFT; /* Quiet gcc */
+ if (priv->layout)
+ return;
- priv->layout = gtk_widget_create_pango_layout (widget, priv->text);
+ align = PANGO_ALIGN_LEFT; /* Quiet gcc */
+ rtl = _gtk_widget_get_direction (GTK_WIDGET (label)) == GTK_TEXT_DIR_RTL;
+ priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (label), priv->text);
- gtk_label_update_layout_attributes (label);
+ gtk_label_update_layout_attributes (label);
- switch (priv->jtype)
- {
- case GTK_JUSTIFY_LEFT:
- align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
- break;
- case GTK_JUSTIFY_RIGHT:
- align = rtl ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT;
- break;
- case GTK_JUSTIFY_CENTER:
- align = PANGO_ALIGN_CENTER;
- break;
- case GTK_JUSTIFY_FILL:
- align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
- pango_layout_set_justify (priv->layout, TRUE);
- break;
- default:
- g_assert_not_reached();
- }
+ switch (priv->jtype)
+ {
+ case GTK_JUSTIFY_LEFT:
+ align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
+ break;
+ case GTK_JUSTIFY_RIGHT:
+ align = rtl ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT;
+ break;
+ case GTK_JUSTIFY_CENTER:
+ align = PANGO_ALIGN_CENTER;
+ break;
+ case GTK_JUSTIFY_FILL:
+ align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
+ pango_layout_set_justify (priv->layout, TRUE);
+ break;
+ default:
+ g_assert_not_reached();
+ }
- pango_layout_set_alignment (priv->layout, align);
- pango_layout_set_ellipsize (priv->layout, priv->ellipsize);
- pango_layout_set_wrap (priv->layout, priv->wrap_mode);
- pango_layout_set_single_paragraph_mode (priv->layout, priv->single_line_mode);
- if (priv->lines > 0)
- pango_layout_set_height (priv->layout, - priv->lines);
+ pango_layout_set_alignment (priv->layout, align);
+ pango_layout_set_ellipsize (priv->layout, priv->ellipsize);
+ pango_layout_set_wrap (priv->layout, priv->wrap_mode);
+ pango_layout_set_single_paragraph_mode (priv->layout, priv->single_line_mode);
+ if (priv->lines > 0)
+ pango_layout_set_height (priv->layout, - priv->lines);
- if (priv->ellipsize || priv->wrap)
- pango_layout_set_width (priv->layout, gtk_widget_get_width (GTK_WIDGET (label)) * PANGO_SCALE);
- }
+ if (priv->ellipsize || priv->wrap)
+ pango_layout_set_width (priv->layout, gtk_widget_get_width (GTK_WIDGET (label)) * PANGO_SCALE);
}
static GtkSizeRequestMode
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]