Set the xalign property for Gtk::Labels (!40)
With the same case as from the previous commit, the very long "Mounted on ..." text is now wrapped, but the text may not be left justified. Slowly adjust the dialog width and see how the text wrapping is updated to fit the size adjustment but the text is centred rather than left justified. This is because setting the halign property to Gtk::ALIGN_START does not guarantee left alignment of text for wrapped or ellipsized Gtk::Labels. Use the xalign property instead. To set the xalign property there is a method in the GtkMisc (Gtk::Misc) base class: gtk_misc_set_alignment (Gtk::Misc::set_alignment) However, GtkMisc (Gtk::Misc) was deprecated in Gtk 3.14 (Gtkmm 3.14) and in Gtk 3.16 (gtkmm 3.16) set_alignment() was replaced with the introduction of two new methods: gtk_label_set_xalign (Gtk::Label::set_xalign) gtk_label_set_yalign (Gtk::Label::set_yalign) Add a check for Gtkmm method Gtk::Label::set_xalign() in configure.ac and use it when available. References: [1] Gtk3 Reference Documentation - gtk_misc_set_alignment() https://developer.gnome.org/gtk3/stable/GtkMisc.html#gtk-misc-set-alignment "gtk_misc_set_alignment has been deprecated since version 3.14 and should not be used in newly-written code. Use GtkWidget's alignment ("halign" and "valign") and margin properties or GtkLabel's "xalign" and "yalign" properties." [2] Gtkmm 3.16 Gtk::Misc Class Reference, set_alignment() method https://developer.gnome.org/gtkmm/3.16/classGtk_1_1Misc.html#a52b2675874cf46a3097938756b9fe9e8 [3] GNOME BugZilla - EmptyBoxes: instructions_label's alignment is off https://bugzilla.gnome.org/show_bug.cgi?id=735841 [4] Gtk commit from 2014-09-16: GtkLabel: add x/yalign properties https://gitlab.gnome.org/GNOME/gtk/commit/d39424fc [5] Gtk3 Reference Documentation - gtk_label_set_xalign() https://developer.gnome.org/gtk3/stable/GtkLabel.html#gtk-label-set-xalign [6] Gtkmm 3.16 Gtk::Label Class Reference, set_xalign() method https://developer.gnome.org/gtkmm/3.16/classGtk_1_1Label.html#acee7d4e87d7cc14080a7b8ded5f84e5e Closes !40 - Limit wrapping labels
This commit is contained in:
parent
769d19e0f9
commit
12f08d38b8
12
configure.ac
12
configure.ac
|
@ -242,6 +242,18 @@ if test "x$need_cxx_compile_stdcxx_11" = xyes; then
|
|||
fi
|
||||
|
||||
|
||||
dnl Check for gtkmm >= 3.16 to determine availability of Gtk::Label::set_xalign().
|
||||
AC_MSG_CHECKING([for Gtk::Label::set_xalign() method])
|
||||
PKG_CHECK_EXISTS(
|
||||
[gtkmm-3.0 >= 3.16.0],
|
||||
[AC_DEFINE([HAVE_LABEL_SET_XALIGN], 1,
|
||||
[Define to 1 if gtkmm provides Gtk::Label::set_xalign() method.])
|
||||
AC_MSG_RESULT([yes])
|
||||
],
|
||||
[AC_MSG_RESULT([no])]
|
||||
)
|
||||
|
||||
|
||||
dnl Check for gtkmm >= 3.22 to determine availability of Gtk::ScrolledWindow::set_propagate_natural_width().
|
||||
AC_MSG_CHECKING([for Gtk::ScrolledWindow::set_propagate_natural_width() method])
|
||||
PKG_CHECK_EXISTS(
|
||||
|
|
|
@ -128,7 +128,7 @@ public:
|
|||
, bool use_markup = true
|
||||
, bool wrap = false
|
||||
, bool selectable = false
|
||||
, Gtk::Align yalign = Gtk::ALIGN_CENTER
|
||||
, Gtk::Align valign = Gtk::ALIGN_CENTER
|
||||
) ;
|
||||
static Gtk::Image* mk_image(const Gtk::StockID& stock_id, Gtk::IconSize icon_size);
|
||||
static Glib::RefPtr<Gdk::Pixbuf> mk_pixbuf(Gtk::Widget& widget,
|
||||
|
|
10
src/Utils.cc
10
src/Utils.cc
|
@ -62,11 +62,17 @@ Gtk::Label * Utils::mk_label( const Glib::ustring & text
|
|||
, bool use_markup
|
||||
, bool wrap
|
||||
, bool selectable
|
||||
, Gtk::Align yalign
|
||||
, Gtk::Align valign
|
||||
)
|
||||
{
|
||||
Gtk::Label * label = manage(new Gtk::Label(text, Gtk::ALIGN_START, yalign));
|
||||
Gtk::Label *label = manage(new Gtk::Label(text));
|
||||
|
||||
#if HAVE_LABEL_SET_XALIGN
|
||||
label->set_xalign(0.0);
|
||||
#else
|
||||
label->set_alignment(0.0, 0.5);
|
||||
#endif
|
||||
label->set_valign(valign);
|
||||
label ->set_use_markup( use_markup ) ;
|
||||
if (wrap)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue