[gtk/wip/otte/for-master: 44/46] widget: Don't forget margins when adjusting




commit 7459d430eb5a8cd94462b0a1ad068e89384294f9
Author: Benjamin Otte <otte redhat com>
Date:   Fri Nov 19 23:19:14 2021 +0100

    widget: Don't forget margins when adjusting
    
    This could lead to the wrong values being passed and computing invalid
    sizes which would then lead to very unhappy code.
    
    Test included.

 gtk/gtkwidget.c                                     |  4 ++--
 testsuite/reftests/meson.build                      |  2 ++
 .../reftests/wrap-margin-align-critical.ref.ui      | 20 ++++++++++++++++++++
 testsuite/reftests/wrap-margin-align-critical.ui    | 21 +++++++++++++++++++++
 4 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 788cfb6650..73dc6b20be 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3846,7 +3846,7 @@ gtk_widget_adjust_size_allocation (GtkWidget     *widget,
                         &allocation->x,
                         &allocation->width);
       gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
-                          allocation->width,
+                          allocation->width + priv->margin.left + priv->margin.right,
                           &min_height, &natural_height, NULL, NULL);
       adjust_for_align (priv->valign,
                         natural_height - priv->margin.top - priv->margin.bottom,
@@ -3867,7 +3867,7 @@ gtk_widget_adjust_size_allocation (GtkWidget     *widget,
                         &allocation->y,
                         &allocation->height);
       gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
-                          allocation->height,
+                          allocation->height + priv->margin.top + priv->margin.bottom,
                           &min_width, &natural_width, NULL, NULL);
       adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
                         natural_width - priv->margin.left - priv->margin.right,
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index eb277d8bf7..01f813bee5 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -527,6 +527,8 @@ testdata = [
   # it is not in xfail since it succeeds on some platforms
   #'window-show-contents-on-map.ref.ui',
   #'window-show-contents-on-map.ui',
+  'wrap-margin-align-critical.ref.ui',
+  'wrap-margin-align-critical.ui',
 ]
 
 # These need to be fixed but the issue hasn't been tracked down.
diff --git a/testsuite/reftests/wrap-margin-align-critical.ref.ui 
b/testsuite/reftests/wrap-margin-align-critical.ref.ui
new file mode 100644
index 0000000000..04d550c82d
--- /dev/null
+++ b/testsuite/reftests/wrap-margin-align-critical.ref.ui
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <object class="GtkWindow">
+    <property name="default-width">300</property>
+    <property name="default-height">300</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkBox">
+        <property name="halign">center</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="halign">center</property>
+            <property name="label">Hello World</property>
+            <property name="wrap">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/wrap-margin-align-critical.ui 
b/testsuite/reftests/wrap-margin-align-critical.ui
new file mode 100644
index 0000000000..b69c770f09
--- /dev/null
+++ b/testsuite/reftests/wrap-margin-align-critical.ui
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <object class="GtkWindow">
+    <property name="default-width">300</property>
+    <property name="default-height">300</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkBox">
+        <property name="halign">center</property>
+        <property name="margin-start">50</property>
+        <property name="margin-end">50</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="label">Hello World</property>
+            <property name="wrap">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


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