Commit 12f08d38 authored by Luca Bacci's avatar Luca Bacci Committed by Mike Fleetwood

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

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
and use it when available.


[1] Gtk3 Reference Documentation - 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

[3] GNOME BugZilla - EmptyBoxes: instructions_label's alignment is off

[4] Gtk commit from 2014-09-16:
    GtkLabel: add x/yalign properties

[5] Gtk3 Reference Documentation - gtk_label_set_xalign()

[6] Gtkmm 3.16 Gtk::Label Class Reference, set_xalign() method

Closes !40 - Limit wrapping labels
parent 769d19e0
Pipeline #83870 passed with stages
in 21 minutes and 7 seconds
......@@ -242,6 +242,18 @@ if test "x$need_cxx_compile_stdcxx_11" = xyes; then
dnl Check for gtkmm >= 3.16 to determine availability of Gtk::Label::set_xalign().
AC_MSG_CHECKING([for Gtk::Label::set_xalign() method])
[gtkmm-3.0 >= 3.16.0],
[Define to 1 if gtkmm provides Gtk::Label::set_xalign() method.])
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])
......@@ -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,
......@@ -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));
label->set_alignment(0.0, 0.5);
label ->set_use_markup( use_markup ) ;
if (wrap)
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