label: Handle width-chars > text width

This was broken in wrapping labels.

Testcase included.
This commit is contained in:
Benjamin Otte 2021-11-09 17:49:40 +01:00
parent bf40b89b53
commit 1e47b1c610
4 changed files with 28 additions and 0 deletions

View File

@ -1174,6 +1174,7 @@ get_width_for_height (GtkLabel *self,
/* Minimum width is as many line breaks as possible */
layout = gtk_label_get_measuring_layout (self, NULL, MAX (minimum_default, 0));
pango_layout_get_size (layout, minimum_width, NULL);
*minimum_width = MAX (*minimum_width, minimum_default);
/* Natural width is natural width - or as wide as possible */
layout = gtk_label_get_measuring_layout (self, layout, natural_default);

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="decorated">0</property>
<child>
<object class="GtkLabel" id="label1">
<property name="label" translatable="yes">Hello World</property>
<property name="width-chars">20</property>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="decorated">0</property>
<child>
<object class="GtkLabel" id="label1">
<property name="label" translatable="yes">Hello World</property>
<property name="wrap">1</property>
<property name="width-chars">20</property>
</object>
</child>
</object>
</interface>

View File

@ -369,6 +369,8 @@ testdata = [
'label-text-shadow-changes-modify-clip.ui',
'label-width-chars-dont-shrink.ref.ui',
'label-width-chars-dont-shrink.ui',
'label-wrap-width-chars.ref.ui',
'label-wrap-width-chars.ui',
'label-wrapped-huge-max-width-chars.ref.ui',
'label-wrapped-huge-max-width-chars.ui',
# this seems to make assumptions on text positioning