[gimp/wip/Jehan/jumping-cursor-label: 93/93] app: avoid jumping of label.




commit f9b82f2a741dd92f975b14dbbd6dd79d9d8f91d2
Author: Jehan <jehan girinstud io>
Date:   Fri Feb 18 20:22:20 2022 +0100

    app: avoid jumping of label.
    
    This issue was not confirmed to happen on Linux and Windows, but was
    making ugly label resizes on macOS by just moving the cursor on canvas
    normally. See video in:
    https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/572#note_1389445
    
    Funnily enough though, it started to happen after commit 1baeffc9138,
    even on Linux/X11 at least, which was the commit meant to fix this on
    macOS!
    
    This max size computation algorithm should work well enough for any
    normal on-canvas usage, and even some off-canvas (yet close enough)
    usage.

 app/display/gimpstatusbar.c | 50 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 6 deletions(-)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index df1ba12140..7138a6ce9b 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -1242,17 +1242,25 @@ gimp_statusbar_update_cursor (GimpStatusbar       *statusbar,
   GimpDisplayShell *shell;
   GimpImage        *image;
   gchar             buffer[CURSOR_LEN];
+  gint              image_width       = 0;
+  gint              image_height      = 0;
 
   g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
 
   shell = statusbar->shell;
   image = gimp_display_get_image (shell->display);
 
-  if (! image                            ||
-      x <  0                             ||
-      y <  0                             ||
-      x >= gimp_image_get_width  (image) ||
-      y >= gimp_image_get_height (image))
+  if (image)
+    {
+      image_width  = gimp_image_get_width  (image);
+      image_height = gimp_image_get_height (image);
+    }
+
+  if (! image          ||
+      x <  0           ||
+      y <  0           ||
+      x >= image_width ||
+      y >= image_height)
     {
       gtk_widget_set_sensitive (statusbar->cursor_label, FALSE);
     }
@@ -1800,7 +1808,36 @@ gimp_statusbar_load_icon (GimpStatusbar *statusbar,
 
 static gboolean gimp_statusbar_queue_pos_redraw (gpointer data)
 {
-  GimpStatusbar *statusbar = GIMP_STATUSBAR (data);
+  GimpStatusbar    *statusbar = GIMP_STATUSBAR (data);
+  GimpDisplayShell *shell;
+  GimpImage        *image;
+  gint              image_width       = 0;
+  gint              image_height      = 0;
+  gint              label_width_chars = 2;
+
+  shell = statusbar->shell;
+  image = gimp_display_get_image (shell->display);
+
+  if (image)
+    {
+      image_width  = gimp_image_get_width  (image);
+      image_height = gimp_image_get_height (image);
+
+      /* The number of chars within up to 2 times the image bounds is:
+       * - max width chars: floor (log10 (2 * max_width)) + 1
+       * - max height chars: floor (log10 (2 * max_height)) + 1
+       * - the comma and a space: + 2
+       * - possibly 2 minus characters when going in negative
+       *   dimensions: + 2
+       * The goal of this is to avoid the label size jumping up and
+       * down. Actually it was not a problem on Linux, but this was
+       * reported on macOS.
+       * See: https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/572#note_1389445
+       * Of course, it could still happen for people going way
+       * off-canvas but that's acceptable edge-case.
+       */
+      label_width_chars = floor (log10 (2 * image_width)) + floor (log10 (2 * image_height)) + 6;
+    }
 
 #ifdef GDK_WINDOWING_QUARTZ
 /*
@@ -1824,6 +1861,7 @@ static gboolean gimp_statusbar_queue_pos_redraw (gpointer data)
 #endif
 
   g_free (statusbar->cursor_string_last);
+  gtk_label_set_width_chars (GTK_LABEL (statusbar->cursor_label), label_width_chars);
   gimp_statusbar_cursor_label_set_text (statusbar, statusbar->cursor_string_todraw);
   statusbar->cursor_string_last = statusbar->cursor_string_todraw;
   statusbar->cursor_string_todraw = NULL;


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