mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 21:21:21 +00:00
label: Don't set ellipsized size as natural size
Natural size should never ellipsize. Tests added.
This commit is contained in:
parent
ade7509b97
commit
07cfdd8ca0
@ -1185,10 +1185,17 @@ get_width_for_height (GtkLabel *self,
|
||||
{
|
||||
int min, max, mid, text_width, text_height;
|
||||
|
||||
/* Can't use a measuring layout here, because we need to force
|
||||
* ellipsizing mode */
|
||||
gtk_label_ensure_layout (self);
|
||||
layout = pango_layout_copy (self->layout);
|
||||
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
|
||||
|
||||
/* binary search for the smallest width where the height doesn't
|
||||
* eclipse the given height */
|
||||
min = MAX (minimum_default, 0);
|
||||
layout = gtk_label_get_measuring_layout (self, NULL, -1);
|
||||
|
||||
pango_layout_set_width (layout, -1);
|
||||
pango_layout_get_size (layout, &max, NULL);
|
||||
|
||||
min = PANGO_PIXELS_CEIL (min);
|
||||
@ -1196,7 +1203,7 @@ get_width_for_height (GtkLabel *self,
|
||||
while (min < max)
|
||||
{
|
||||
mid = (min + max) / 2;
|
||||
layout = gtk_label_get_measuring_layout (self, layout, mid * PANGO_SCALE);
|
||||
pango_layout_set_width (layout, mid * PANGO_SCALE);
|
||||
pango_layout_get_size (layout, &text_width, &text_height);
|
||||
text_width = PANGO_PIXELS_CEIL (text_width);
|
||||
if (text_width > mid)
|
||||
@ -1207,8 +1214,19 @@ get_width_for_height (GtkLabel *self,
|
||||
max = mid;
|
||||
}
|
||||
|
||||
*minimum_width = min * PANGO_SCALE;
|
||||
*natural_width = min * PANGO_SCALE;
|
||||
|
||||
if (self->ellipsize != PANGO_ELLIPSIZE_NONE)
|
||||
{
|
||||
g_object_unref (layout);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
*minimum_width = *natural_width;
|
||||
}
|
||||
}
|
||||
|
||||
g_object_unref (layout);
|
||||
|
15
testsuite/reftests/hbox-with-ellipsizing-label.ref.ui
Normal file
15
testsuite/reftests/hbox-with-ellipsizing-label.ref.ui
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">Hello World</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
16
testsuite/reftests/hbox-with-ellipsizing-label.ui
Normal file
16
testsuite/reftests/hbox-with-ellipsizing-label.ui
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">Hello World</property>
|
||||
<property name="ellipsize">end</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">Hello World</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="wrap-mode">char</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
18
testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ui
Normal file
18
testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ui
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">Hello World</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="wrap-mode">char</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
@ -2,7 +2,6 @@
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="decorated">0</property>
|
||||
<signal name="realize" handler="reftest:set_default_direction_ltr"/>
|
||||
<child>
|
||||
<object class="GtkGrid" id="grid1">
|
||||
<property name="row_spacing">1</property>
|
||||
|
@ -2,7 +2,6 @@
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="decorated">0</property>
|
||||
<signal name="realize" handler="reftest:set_default_direction_ltr"/>
|
||||
<child>
|
||||
<object class="GtkGrid" id="grid1">
|
||||
<property name="row-spacing">1</property>
|
||||
|
@ -310,6 +310,10 @@ testdata = [
|
||||
'gtk-icontheme-sizing.css',
|
||||
'gtk-icontheme-sizing.ref.ui',
|
||||
'gtk-icontheme-sizing.ui',
|
||||
'hbox-with-ellipsizing-label.ref.ui',
|
||||
'hbox-with-ellipsizing-label.ui',
|
||||
'hbox-with-ellipsizing-wrapping-label.ref.ui',
|
||||
'hbox-with-ellipsizing-wrapping-label.ui',
|
||||
'icon-effect-missing.css',
|
||||
'icon-effect-missing.ref.ui',
|
||||
'icon-effect-missing.ui',
|
||||
|
Loading…
Reference in New Issue
Block a user