[gimp] app: fix max size computation for status message.



commit 118c0c6734538fe68e385185831034643be3abc0
Author: Jehan <jehan girinstud io>
Date:   Tue Feb 9 16:02:29 2021 +0100

    app: fix max size computation for status message.
    
    Our error/message handling code was checking if the status bar label was
    big enough to hold the message by checking the GtkLabel allocation. This
    means that error message ended up on status bar only if a status text
    bigger than the error message was previously displayed.
    Even setting gtk_widget_set_hexpand() or the "expand" container child
    property on the label, I could not find a way for GTK to actually give
    it as much space as possible on the status bar.
    
    Instead, I am computing the full container box size, starting from the
    label x coordinate (assuming the label is the last shown widget on the
    status bar, as usually the progress bar and the cancel buttons are not
    shown in the same time as the message label). This gives me a much more
    appropriate result of the maximum size which this label can hold without
    ellipsizing.

 app/display/gimpstatusbar.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index 7c9f105135..a7b29a633b 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -623,32 +623,37 @@ gimp_statusbar_progress_message (GimpProgress        *progress,
 
   if (pango_layout_get_line_count (layout) == 1)
     {
-      GtkAllocation label_allocation;
-      gint          width;
+      GtkWidget     *label_box = gtk_widget_get_parent (statusbar->label);
+      GtkAllocation  label_allocation;
+      gint           text_width, max_label_width, x;
 
-      gtk_widget_get_allocation (statusbar->label, &label_allocation);
-
-      pango_layout_get_pixel_size (layout, &width, NULL);
-
-      if (width < label_allocation.width)
+      gtk_widget_get_allocation (label_box, &label_allocation);
+      if (gtk_widget_translate_coordinates (statusbar->label, label_box, 0, 0,
+                                            &x, NULL))
         {
-          if (icon_name)
+          max_label_width = label_allocation.width - x;
+          pango_layout_get_pixel_size (layout, &text_width, NULL);
+
+          if (text_width < max_label_width)
             {
-              GdkPixbuf *pixbuf;
-              gint       scale_factor;
+              if (icon_name)
+                {
+                  GdkPixbuf *pixbuf;
+                  gint       scale_factor;
 
-              pixbuf = gimp_statusbar_load_icon (statusbar, icon_name);
+                  pixbuf = gimp_statusbar_load_icon (statusbar, icon_name);
 
-              scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (statusbar));
-              width += ICON_SPACING + gdk_pixbuf_get_width (pixbuf) / scale_factor;
+                  scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (statusbar));
+                  text_width += ICON_SPACING + gdk_pixbuf_get_width (pixbuf) / scale_factor;
 
-              g_object_unref (pixbuf);
+                  g_object_unref (pixbuf);
 
-              handle_msg = (width < label_allocation.width);
-            }
-          else
-            {
-              handle_msg = TRUE;
+                  handle_msg = (text_width < max_label_width);
+                }
+              else
+                {
+                  handle_msg = TRUE;
+                }
             }
         }
     }


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