[gimp/wip/Jehan/jumping-cursor-label] app: avoid jumping of label on macOS.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/jumping-cursor-label] app: avoid jumping of label on macOS.
- Date: Fri, 18 Feb 2022 19:25:56 +0000 (UTC)
commit fa458d093f80ab4534bba4baf6950132073a47de
Author: Jehan <jehan girinstud io>
Date: Fri Feb 18 20:22:20 2022 +0100
app: avoid jumping of label on macOS.
This issue is confirmed not happening on Linux and Windows, but makes
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
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 | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index a6b16b158e..2107ed152e 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -1231,6 +1231,9 @@ gimp_statusbar_update_cursor (GimpStatusbar *statusbar,
GimpDisplayShell *shell;
GimpImage *image;
gchar buffer[CURSOR_LEN];
+ gint image_width = 0;
+ gint image_height = 0;
+ gint label_width_chars = 2;
#ifdef GDK_WINDOWING_QUARTZ
/*
@@ -1261,11 +1264,32 @@ gimp_statusbar_update_cursor (GimpStatusbar *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);
+
+ /* 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;
+ }
+
+ if (! image ||
+ x < 0 ||
+ y < 0 ||
+ x >= image_width ||
+ y >= image_height)
{
gtk_widget_set_sensitive (statusbar->cursor_label, FALSE);
}
@@ -1321,6 +1345,7 @@ gimp_statusbar_update_cursor (GimpStatusbar *statusbar,
"", x, ", ", y, "");
}
+ gtk_label_set_width_chars (GTK_LABEL (statusbar->cursor_label), label_width_chars);
gtk_label_set_text (GTK_LABEL (statusbar->cursor_label), buffer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]