diff options
author | Nelson Benítez León <nbenitezl@gmail.com> | 2023-01-22 15:41:00 +0000 |
---|---|---|
committer | Nelson Benítez León <nbenitezl@gmail.com> | 2023-01-22 16:34:07 +0000 |
commit | bd206f3b7a409d7fadb5668e2e265ac3f61a0ab8 (patch) | |
tree | 917c863719dc337b1bd2dc012496ccb40db16fe1 | |
parent | 8f2ad8f1540fe91769237fcc0986744708747a2b (diff) | |
download | gtk+-fix_tooltip_width.tar.gz |
Improve window size for long text tooltipsfix_tooltip_width
When a tooltip reaches the hardcoded limit of 50
chars it will wrap to a new line, but keeps the
window's width same as if it were just one line.
From GtkLabel docs:
"For wrapping labels, width-chars is used as the
minimum width, if specified, and max-width-chars
is used as the natural width."
So we detect for this case and set label's width-chars
property, so we set the minimum size to a lesser value.
Fixes #5521
-rw-r--r-- | gtk/gtktooltipwindow.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gtk/gtktooltipwindow.c b/gtk/gtktooltipwindow.c index 491598a1f5..5de705cb7d 100644 --- a/gtk/gtktooltipwindow.c +++ b/gtk/gtktooltipwindow.c @@ -66,6 +66,8 @@ struct _GtkTooltipWindowClass GtkWidgetClass parent_class; }; +#define CHARS_WRAP_LIMIT 50 + static void gtk_tooltip_window_native_init (GtkNativeInterface *iface); G_DEFINE_TYPE_WITH_CODE (GtkTooltipWindow, gtk_tooltip_window, GTK_TYPE_WIDGET, @@ -417,7 +419,10 @@ update_label_width (GtkLabel *label) len = g_utf8_strlen (text, -1); - gtk_label_set_max_width_chars (label, MIN (len, 50)); + if (len > CHARS_WRAP_LIMIT) + gtk_label_set_width_chars (label, CHARS_WRAP_LIMIT); + + gtk_label_set_max_width_chars (label, MIN (len, CHARS_WRAP_LIMIT)); gtk_label_set_wrap (label, TRUE); } } |