[gtk/wip/otte/for-master: 24/30] label: max-width-chars has no effect on smaller text




commit cce6a603a6aa054d2d5aaaf9b3b0671cb6a9970c
Author: Benjamin Otte <otte redhat com>
Date:   Sat Nov 6 16:17:59 2021 +0100

    label: max-width-chars has no effect on smaller text
    
    Having a short text and a large max-width-chars should request the
    natural width of the text, not the limit from max-width-chars.
    
    This caused huge message dialogs.
    
    Reftests added.

 gtk/gtklabel.c                                              | 11 ++++-------
 testsuite/reftests/label-huge-max-width-chars.ref.ui        | 11 +++++++++++
 testsuite/reftests/label-huge-max-width-chars.ui            | 12 ++++++++++++
 .../reftests/label-wrapped-huge-max-width-chars.ref.ui      | 12 ++++++++++++
 testsuite/reftests/label-wrapped-huge-max-width-chars.ui    | 13 +++++++++++++
 testsuite/reftests/meson.build                              |  4 ++++
 6 files changed, 56 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 3c3be85406..46af2fb174 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -1077,14 +1077,15 @@ get_static_size (GtkLabel       *self,
                  int            *minimum_baseline,
                  int            *natural_baseline)
 {
+  int minimum_default, natural_default;
   PangoLayout *layout;
 
-  layout = gtk_label_get_measuring_layout (self, NULL, -1);
+  get_default_widths (self, &minimum_default, &natural_default);
+
+  layout = gtk_label_get_measuring_layout (self, NULL, natural_default);
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      int minimum_default, natural_default;
-
       pango_layout_get_size (layout, natural, NULL);
       if (self->ellipsize)
         {
@@ -1096,11 +1097,8 @@ get_static_size (GtkLabel       *self,
       else
         *minimum = *natural;
 
-      get_default_widths (self, &minimum_default, &natural_default);
       if (minimum_default > *minimum)
         *minimum = minimum_default;
-      if (natural_default > -1)
-        *natural = natural_default;
       *natural = MAX (*minimum, *natural);
     }
   else
@@ -1180,7 +1178,6 @@ get_width_for_height (GtkLabel *self,
       /* Natural width is natural width - or as wide as possible */
       layout = gtk_label_get_measuring_layout (self, layout, natural_default);
       pango_layout_get_size (layout, natural_width, NULL);
-      *natural_width = MAX (*natural_width, natural_default);
       *natural_width = MAX (*natural_width, *minimum_width);
     }
   else
diff --git a/testsuite/reftests/label-huge-max-width-chars.ref.ui 
b/testsuite/reftests/label-huge-max-width-chars.ref.ui
new file mode 100644
index 0000000000..ec722f56ce
--- /dev/null
+++ b/testsuite/reftests/label-huge-max-width-chars.ref.ui
@@ -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-huge-max-width-chars.ui 
b/testsuite/reftests/label-huge-max-width-chars.ui
new file mode 100644
index 0000000000..bf1237c1de
--- /dev/null
+++ b/testsuite/reftests/label-huge-max-width-chars.ui
@@ -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">1000</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/label-wrapped-huge-max-width-chars.ref.ui 
b/testsuite/reftests/label-wrapped-huge-max-width-chars.ref.ui
new file mode 100644
index 0000000000..5ec6dea124
--- /dev/null
+++ b/testsuite/reftests/label-wrapped-huge-max-width-chars.ref.ui
@@ -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="wrap">1</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/label-wrapped-huge-max-width-chars.ui 
b/testsuite/reftests/label-wrapped-huge-max-width-chars.ui
new file mode 100644
index 0000000000..cc21161d61
--- /dev/null
+++ b/testsuite/reftests/label-wrapped-huge-max-width-chars.ui
@@ -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">Hello World</property>
+        <property name="max-width-chars">1000</property>
+        <property name="wrap">1</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index 7917c1d388..d6857190cf 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -347,6 +347,8 @@ testdata = [
   'label-fonts.css',
   'label-fonts.ref.ui',
   'label-fonts.ui',
+  'label-huge-max-width-chars.ref.ui',
+  'label-huge-max-width-chars.ui',
   'label-max-width-chars-and-halign-and-infinite-width.ui',
   'label-max-width-chars-and-halign-and-infinite-width.ref.ui',
   'label-shadows.css',
@@ -365,6 +367,8 @@ testdata = [
   'label-text-shadow-changes-modify-clip.ui',
   'label-width-chars-dont-shrink.ref.ui',
   'label-width-chars-dont-shrink.ui',
+  'label-wrapped-huge-max-width-chars.ref.ui',
+  'label-wrapped-huge-max-width-chars.ui',
   # this seems to make assumptions on text positioning
   # that are not valid with subpixel positioning
   #'label-wrap-justify.ref.ui',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]