label: max-width-chars should be ignored sometimes
authorBenjamin Otte <otte@redhat.com>
Sat, 6 Nov 2021 15:25:11 +0000 (16:25 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 9 Nov 2021 02:41:43 +0000 (03:41 +0100)
When a widget is neither wrappable nor ellipsizable, we cannot modify
the label to fit into any size. So we cannot respect max-width-chars.

gtk/gtklabel.c
testsuite/reftests/label-small-max-width-chars.ref.ui [new file with mode: 0644]
testsuite/reftests/label-small-max-width-chars.ui [new file with mode: 0644]
testsuite/reftests/meson.build

index 46af2fb17442fd870c3bba6177d8f0f491cafb92..a82ec7bb779ab5851785919d15c9a5c9e9146f83 100644 (file)
@@ -1082,7 +1082,7 @@ get_static_size (GtkLabel       *self,
 
   get_default_widths (self, &minimum_default, &natural_default);
 
-  layout = gtk_label_get_measuring_layout (self, NULL, natural_default);
+  layout = gtk_label_get_measuring_layout (self, NULL, self->ellipsize ? natural_default : -1);
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
diff --git a/testsuite/reftests/label-small-max-width-chars.ref.ui b/testsuite/reftests/label-small-max-width-chars.ref.ui
new file mode 100644 (file)
index 0000000..ec722f5
--- /dev/null
@@ -0,0 +1,11 @@
+<?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">Hello World</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/label-small-max-width-chars.ui b/testsuite/reftests/label-small-max-width-chars.ui
new file mode 100644 (file)
index 0000000..d3236e8
--- /dev/null
@@ -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">Hello World</property>
+        <property name="max-width-chars">2</property>
+      </object>
+    </child>
+  </object>
+</interface>
index d6857190cf843e0c00e7e2415a7aaec280b93dd7..9f40c0f3a0ed875172d0d5b815077c3aaf5c1276 100644 (file)
@@ -359,6 +359,8 @@ testdata = [
   'label-sizing.ui',
   'label-small-ellipsized.ref.ui',
   'label-small-ellipsized.ui',
+  'label-small-max-width-chars.ref.ui',
+  'label-small-max-width-chars.ui',
   'label-text-shadow-clipping.css',
   'label-text-shadow-clipping.ref.ui',
   'label-text-shadow-clipping.ui',