[gimp] app: fix canvas jumping because of the status bar label being too wide



commit 291e84281abe59d10872fbd158d514972dde37df
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jan 2 17:49:53 2019 +0100

    app: fix canvas jumping because of the status bar label being too wide
    
    Set the label to ELLIPSIZE_END and add some packing options, and
    switch from using pango attributes to simply prepending the right
    number of spaces to leave enough room for the icon. The attributes
    were somehow breaking ellipsation.

 app/display/gimpstatusbar.c | 46 +++++++++++++++++++--------------------------
 app/display/gimpstatusbar.h |  1 +
 2 files changed, 20 insertions(+), 27 deletions(-)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index 9c31c3c674..90d760ee07 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -295,7 +295,8 @@ gimp_statusbar_init (GimpStatusbar *statusbar)
 
   statusbar->label = gtk_label_new ("");
   gtk_label_set_ellipsize (GTK_LABEL (statusbar->label), PANGO_ELLIPSIZE_END);
-  gtk_widget_set_halign (GTK_WIDGET (statusbar->label), GTK_ALIGN_START);
+  gtk_label_set_justify (GTK_LABEL (statusbar->label), GTK_JUSTIFY_LEFT);
+  gtk_widget_set_halign (statusbar->label, GTK_ALIGN_START);
   gtk_box_pack_start (GTK_BOX (hbox), statusbar->label, TRUE, TRUE, 1);
   gtk_widget_show (statusbar->label);
 
@@ -388,10 +389,15 @@ static void
 gimp_statusbar_style_updated (GtkWidget *widget)
 {
   GimpStatusbar *statusbar = GIMP_STATUSBAR (widget);
+  PangoLayout   *layout;
+
+  GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
 
   g_clear_pointer (&statusbar->icon_hash, g_hash_table_unref);
 
-  GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
+  layout = gtk_widget_create_pango_layout (widget, " ");
+  pango_layout_get_pixel_size (layout, &statusbar->icon_space_width, NULL);
+  g_object_unref (layout);
 }
 
 static GimpProgress *
@@ -673,39 +679,25 @@ gimp_statusbar_set_text (GimpStatusbar *statusbar,
 
       if (statusbar->icon)
         {
-          PangoAttrList  *attrs;
-          PangoAttribute *attr;
-          PangoRectangle  rect;
-          gchar          *tmp;
-          gint            scale_factor;
-
-          tmp = g_strconcat (" ", text, NULL);
-          gtk_label_set_text (GTK_LABEL (statusbar->label), tmp);
-          g_free (tmp);
+          gchar *tmp;
+          gint   scale_factor;
+          gint   n_spaces;
+          gchar  spaces[] = "                                 ";
 
           scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (statusbar));
 
-          rect.x      = 0;
-          rect.y      = 0;
-          rect.width  = PANGO_SCALE * (gdk_pixbuf_get_width (statusbar->icon) /
-                                       scale_factor +
-                                       ICON_SPACING);
-          rect.height = 0;
-
-          attrs = pango_attr_list_new ();
+          /* prepend enough spaces for the icon plus one space */
+          n_spaces = (gdk_pixbuf_get_width (statusbar->icon) / scale_factor +
+                      ICON_SPACING) / statusbar->icon_space_width;
+          n_spaces++;
 
-          attr = pango_attr_shape_new (&rect, &rect);
-          attr->start_index = 0;
-          attr->end_index   = 1;
-          pango_attr_list_insert (attrs, attr);
-
-          gtk_label_set_attributes (GTK_LABEL (statusbar->label), attrs);
-          pango_attr_list_unref (attrs);
+          tmp = g_strconcat (spaces + strlen (spaces) - n_spaces, text, NULL);
+          gtk_label_set_text (GTK_LABEL (statusbar->label), tmp);
+          g_free (tmp);
         }
       else
         {
           gtk_label_set_text (GTK_LABEL (statusbar->label), text);
-          gtk_label_set_attributes (GTK_LABEL (statusbar->label), NULL);
         }
     }
 }
diff --git a/app/display/gimpstatusbar.h b/app/display/gimpstatusbar.h
index 54682c2a3b..9b333d8225 100644
--- a/app/display/gimpstatusbar.h
+++ b/app/display/gimpstatusbar.h
@@ -46,6 +46,7 @@ struct _GimpStatusbar
 
   GdkPixbuf           *icon;
   GHashTable          *icon_hash;
+  gint                 icon_space_width;
 
   guint                temp_context_id;
   guint                temp_timeout_id;


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