I am writing a Vala application and using GtkLabels' in it. Problem is, I made my main window not resizable and when I'm adding labels with a long text to it, the window gets very big (when the window was resizable, all labels were fitting perfectly). I tried to set_max_width_chars() to some value and it kind of works, but I guess this isn't the right way to do it (because users' fonts may vary and this won't work with fonts sizes that are different from mine).
So, the question: how to do it the right way?
You can't directly limit the width of a label (other than max-width-chars, which is in characters, not in pixels), but you can limit it indirectly by influencing the size of the box that contains it and by setting 4 not immediately obvious properties of the label.
RESULT:
RESULT:
max-width-chars of the label to a small positive value (1 would work just fine)ellipsize of the label to any value other than PANGO_ELLIPSIZE_NONE
hexpand of the label to TRUE (or set expand of the label to TRUE, with obvious consequences)fill of the label (as a child of the subbox it's in) to TRUE (if vexpand is also TRUE, you might want to restrict its filling to horizontal direction only)RESULT:
max-width-chars isThis works on labels and other text widgets that have ellipsize and max-width-chars (such as GtkCellRendererText inside a GtkTreeView).
Tested with GTK+-3.18.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With