Compare commits

...

1 Commits

Author SHA1 Message Date
Nelson Benítez León
bd206f3b7a 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
2023-01-22 16:34:07 +00:00

View File

@@ -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);
}
}