Commit 769d19e0 authored by Luca Bacci's avatar Luca Bacci Committed by Mike Fleetwood

Set a default max_width_chars for wrapping Gtk::Labels (!40)

Opening the Partition Information dialog for a file system mounted on a
very long mount point, or on openSUSE which mounts the OS from 10 btrfs
subvolumes from the same partition, will cause the dialog to be very
wide as the "Mounted on ..." text is not wrapped.

Back in Gtk2, when width_chars / max_width_chars were not set, wrapping
labels had a default width beyond which text wrapped onto a new line
[1].

For Gtk3 this default width was first reworked a bit [2], and then was
removed for the very early Gtk3 3.0.10 release [3].

It is recommended that applications explicitly set default values,
otherwise wrapping labels never wrap when requesting their natural
allocation.

References:

[1] Gtk 2.24.32 source code - gtk/gtklabel.c:2975
    https://gitlab.gnome.org/GNOME/gtk/blob/2.24.32/gtk/gtklabel.c#L2975
        "This long string gives a good enough length for any line to
        have."

[2] Gtk commit from 2010-04-21:
    gtk@680d7762
    Make sure not to base the minimum size on "max-width-chars", only
    the natural size.
        "This string is just about long enough."

[3] Gtk commit from 2011-04-17:
    gtk@c8ce1106
    label: Don't try to guess a label's size

    People should use window default sizes or label
    width-chars/max-width-chars to find the ideal layout for a label
    instead of relying on magic.

Closes !40 - Limit wrapping labels
parent eeffd505
......@@ -68,7 +68,11 @@ Gtk::Label * Utils::mk_label( const Glib::ustring & text
Gtk::Label * label = manage(new Gtk::Label(text, Gtk::ALIGN_START, yalign));
label ->set_use_markup( use_markup ) ;
label ->set_line_wrap( wrap ) ;
if (wrap)
{
label->set_line_wrap(true);
label->set_max_width_chars(40);
}
label ->set_selectable( selectable ) ;
return label ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment