summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/gtklabel.c24
-rw-r--r--testsuite/reftests/hbox-with-ellipsizing-label.ref.ui15
-rw-r--r--testsuite/reftests/hbox-with-ellipsizing-label.ui16
-rw-r--r--testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ref.ui17
-rw-r--r--testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ui18
-rw-r--r--testsuite/reftests/label-sizing.ref.ui1
-rw-r--r--testsuite/reftests/label-sizing.ui1
-rw-r--r--testsuite/reftests/meson.build4
8 files changed, 91 insertions, 5 deletions
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 11ebad9c2d..b3744ae838 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -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);
diff --git a/testsuite/reftests/hbox-with-ellipsizing-label.ref.ui b/testsuite/reftests/hbox-with-ellipsizing-label.ref.ui
new file mode 100644
index 0000000000..1e6871cb40
--- /dev/null
+++ b/testsuite/reftests/hbox-with-ellipsizing-label.ref.ui
@@ -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>
diff --git a/testsuite/reftests/hbox-with-ellipsizing-label.ui b/testsuite/reftests/hbox-with-ellipsizing-label.ui
new file mode 100644
index 0000000000..ff36ee32b3
--- /dev/null
+++ b/testsuite/reftests/hbox-with-ellipsizing-label.ui
@@ -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>
diff --git a/testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ref.ui b/testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ref.ui
new file mode 100644
index 0000000000..f0151d113f
--- /dev/null
+++ b/testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ref.ui
@@ -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>
diff --git a/testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ui b/testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ui
new file mode 100644
index 0000000000..8649153e94
--- /dev/null
+++ b/testsuite/reftests/hbox-with-ellipsizing-wrapping-label.ui
@@ -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>
diff --git a/testsuite/reftests/label-sizing.ref.ui b/testsuite/reftests/label-sizing.ref.ui
index 4235424e80..390b1bcf84 100644
--- a/testsuite/reftests/label-sizing.ref.ui
+++ b/testsuite/reftests/label-sizing.ref.ui
@@ -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>
diff --git a/testsuite/reftests/label-sizing.ui b/testsuite/reftests/label-sizing.ui
index ad3309b997..87e1c9eef4 100644
--- a/testsuite/reftests/label-sizing.ui
+++ b/testsuite/reftests/label-sizing.ui
@@ -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>
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index 5f36c6ddb4..0239f43df3 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -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',