[gimp] app: proper ellipsis & wrap on Image Properties label where it matters.



commit 377de0a65be6e1f2dee28675f937603e1733cfec
Author: Jehan <jehan girinstud io>
Date:   Thu Nov 12 01:09:14 2020 +0100

    app: proper ellipsis & wrap on Image Properties label where it matters.
    
    The color space label may be a bit long (depends on profile title which
    may just be anything and we don't control it), so I allow it to wrap.
    
    The file path on the other hand would not work well with wrapping. It
    already has ellipsis in center, but GTK always gives the max size it can
    as a default. So if the file is even just slightly deep in the file
    tree, we end up with extra-wide Image Properties dialog.
    My trick is to give a sensible max size at dialog creation (25
    characters max) but to disable this max size as soon as the window gets
    realized, hence allowing the label to actually grow up to the contents
    actual max size, were one to manually resize the window.

 app/widgets/gimpimagepropview.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
---
diff --git a/app/widgets/gimpimagepropview.c b/app/widgets/gimpimagepropview.c
index cabf0d7df1..c8622a70bb 100644
--- a/app/widgets/gimpimagepropview.c
+++ b/app/widgets/gimpimagepropview.c
@@ -73,6 +73,8 @@ static void        gimp_image_prop_view_undo_event   (GimpImage         *image,
                                                       GimpImagePropView *view);
 static void        gimp_image_prop_view_update       (GimpImagePropView *view);
 static void        gimp_image_prop_view_file_update  (GimpImagePropView *view);
+static void        gimp_image_prop_view_realize      (GimpImagePropView *view,
+                                                      gpointer           user_data);
 
 
 G_DEFINE_TYPE (GimpImagePropView, gimp_image_prop_view, GTK_TYPE_GRID)
@@ -127,6 +129,8 @@ gimp_image_prop_view_init (GimpImagePropView *view)
 
   gtk_label_set_ellipsize (GTK_LABEL (view->filename_label),
                            PANGO_ELLIPSIZE_MIDDLE);
+  /* See gimp_image_prop_view_realize(). */
+  gtk_label_set_max_width_chars (GTK_LABEL (view->filename_label), 25);
 
   view->filesize_label =
     gimp_image_prop_view_add_label (grid, row++, _("File Size:"));
@@ -159,6 +163,9 @@ gimp_image_prop_view_init (GimpImagePropView *view)
   view->vectors_label =
     gimp_image_prop_view_add_label (grid, row++, _("Number of paths:"));
 
+  g_signal_connect (view, "realize",
+                    G_CALLBACK (gimp_image_prop_view_realize),
+                    NULL);
 }
 
 static void
@@ -305,6 +312,9 @@ gimp_image_prop_view_label_set_filename (GtkWidget *label,
     {
       gtk_label_set_text (GTK_LABEL (label),
                           gimp_file_get_utf8_name (file));
+      /* In case the label is ellipsized. */
+      gtk_widget_set_tooltip_text (GTK_WIDGET (label),
+                                   gimp_file_get_utf8_name (file));
     }
   else
     {
@@ -476,6 +486,7 @@ gimp_image_prop_view_update (GimpImagePropView *view)
     }
 
   gtk_label_set_text (GTK_LABEL (view->colorspace_label), buf);
+  gtk_label_set_line_wrap (GTK_LABEL (view->colorspace_label), TRUE);
 
   /*  precision  */
   precision = gimp_image_get_precision (image);
@@ -531,3 +542,18 @@ gimp_image_prop_view_file_update (GimpImagePropView *view)
   /*  filetype  */
   gimp_image_prop_view_label_set_filetype (view->filetype_label, image);
 }
+
+static void
+gimp_image_prop_view_realize (GimpImagePropView *view,
+                              gpointer           user_data)
+{
+  /* Ugly trick to avoid extra-wide dialog at construction because of
+   * overlong file path. Basically I give a reasonnable max size at
+   * construction (if the path is longer, it is just ellipsized per set
+   * rules), then once the widget is realized, I remove the max size,
+   * allowing the widget to grow wider if ever the dialog were
+   * manually resized (we don't want to keep the label short and
+   * ellipsized if the dialog is explicitly made to have enough place).
+   */
+  gtk_label_set_max_width_chars (GTK_LABEL (view->filename_label), -1);
+}


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