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



commit 769d19e0f9a7f280ce83bc454c10af2f3a193706
Author: Luca Bacci <luca bacci982 gmail com>
Date:   Wed May 1 16:41:06 2019 +0200

    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:
        https://gitlab.gnome.org/GNOME/gtk/commit/680d7762baabb71aa77aeec793e3c70a2013d3b8
        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:
        https://gitlab.gnome.org/GNOME/gtk/commit/c8ce1106c11361f8b47dd4e9a08db571c7d66d82
        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

 src/Utils.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/src/Utils.cc b/src/Utils.cc
index 61da68f2..09f06647 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -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 ;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]