From bd206f3b7a409d7fadb5668e2e265ac3f61a0ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20Ben=C3=ADtez=20Le=C3=B3n?= Date: Sun, 22 Jan 2023 15:41:00 +0000 Subject: [PATCH] Improve window size for long text tooltips 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 --- gtk/gtktooltipwindow.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); } }