[gtk+/gtk-3-20] Scale: Set the correct value alignment



commit 3659eb65d079c832e02a273757e2d72c408099ad
Author: Timm Bäder <mail baedert org>
Date:   Tue May 10 18:33:37 2016 +0200

    Scale: Set the correct value alignment
    
    We're measuring both the width of the minimal and the maximal value for
    the value gadget, but only give the value the minimal width for its
    current value, resultnig in an always left-aligned value.
    
    Fix this by assigning the width of the value gadget to the value layout
    and letting pango align the text inside the layout.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766120

 gtk/gtkscale.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 32c6a33..6903f34 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -1910,8 +1910,23 @@ gtk_scale_get_layout (GtkScale *scale)
 
   if (!priv->layout)
     {
+      int min_layout_width;
+
       if (priv->draw_value)
-       priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
+        priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
+
+      gtk_css_gadget_get_preferred_size (priv->value_gadget,
+                                         GTK_ORIENTATION_HORIZONTAL, -1,
+                                         &min_layout_width, NULL,
+                                         NULL, NULL);
+      pango_layout_set_width (priv->layout, min_layout_width * PANGO_SCALE);
+
+      if (priv->value_pos == GTK_POS_LEFT)
+        pango_layout_set_alignment (priv->layout, PANGO_ALIGN_RIGHT);
+      else if (priv->value_pos == GTK_POS_RIGHT)
+        pango_layout_set_alignment (priv->layout, PANGO_ALIGN_LEFT);
+      else
+        pango_layout_set_alignment (priv->layout, PANGO_ALIGN_CENTER);
     }
 
   if (priv->draw_value)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]