listview: Measure children only, not self
authorBenjamin Otte <otte@redhat.com>
Sun, 19 Feb 2023 03:55:33 +0000 (04:55 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 19 Feb 2023 04:41:29 +0000 (05:41 +0100)
The previous code would include CSS padding/margin/border in the
measurement and that is wrong.

Until commit a96c75ff02 this was not actually visible, but afterwards
listitems were allocated 16px too wide.

Test included

gtk/gtklistview.c
testsuite/reftests/listview-margin.css [new file with mode: 0644]
testsuite/reftests/listview-margin.ref.ui [new file with mode: 0644]
testsuite/reftests/listview-margin.ui [new file with mode: 0644]
testsuite/reftests/meson.build

index 792c9d5a6e3692d67600d6f88988419b0ee86210..f9b7103d63a8a95e2646fcc9bb1e9dfa0c514602 100644 (file)
@@ -606,9 +606,9 @@ gtk_list_view_size_allocate (GtkWidget *widget,
     }
 
   /* step 1: determine width of the list */
-  gtk_widget_measure (widget, opposite_orientation,
-                      -1,
-                      &min, &nat, NULL, NULL);
+  gtk_list_view_measure_across (widget, opposite_orientation,
+                                -1,
+                                &min, &nat);
   self->list_width = orientation == GTK_ORIENTATION_VERTICAL ? width : height;
   if (opposite_scroll_policy == GTK_SCROLL_MINIMUM)
     self->list_width = MAX (min, self->list_width);
diff --git a/testsuite/reftests/listview-margin.css b/testsuite/reftests/listview-margin.css
new file mode 100644 (file)
index 0000000..8de8d97
--- /dev/null
@@ -0,0 +1,8 @@
+listview, box {
+  margin: 50px;
+  padding: 50px;
+}
+
+row {
+  all: unset;
+}
diff --git a/testsuite/reftests/listview-margin.ref.ui b/testsuite/reftests/listview-margin.ref.ui
new file mode 100644 (file)
index 0000000..c551b8b
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkWindow">
+    <property name="decorated">0</property>
+    <property name="child">
+      <object class="GtkBox">
+        <style>
+          <class name="view"/>
+        </style>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">1</property>
+            <property name="label">One</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">1</property>
+            <property name="label">Two</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">1</property>
+            <property name="label">Three</property>
+          </object>
+        </child>
+      </object>
+    </property>
+  </object>
+</interface>
diff --git a/testsuite/reftests/listview-margin.ui b/testsuite/reftests/listview-margin.ui
new file mode 100644 (file)
index 0000000..e72a1e5
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkWindow">
+    <property name="decorated">0</property>
+    <property name="child">
+      <object class="GtkListView">
+        <property name="model">
+          <object class="GtkNoSelection">
+            <property name="model">
+              <object class="GtkStringList">
+                <items>
+                  <item translatable="yes">One</item>
+                  <item translatable="yes">Two</item>
+                  <item translatable="yes">Three</item>
+                </items>
+              </object>
+            </property>
+          </object>
+        </property>
+        <property name="factory">
+          <object class="GtkBuilderListItemFactory">
+            <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkLabel">
+        <property name="xalign">1</property>
+        <binding name="label">
+          <lookup name="string" type="GtkStringObject">
+            <lookup name="item">GtkListItem</lookup>
+          </lookup>
+        </binding>
+      </object>
+    </property>
+  </template>
+</interface>
+            ]]></property>
+          </object>
+        </property>
+      </object>
+    </property>
+  </object>
+</interface>
index b8e0ef0e64694f9caa93efb3a05a9d28d1ea5759..1cc8a4302cbe54ec2ec7d905029ea604917f3ae9 100644 (file)
@@ -446,6 +446,9 @@ testdata = [
   'link-coloring.css',
   'link-coloring.ref.ui',
   'link-coloring.ui',
+  'listview-margin.css',
+  'listview-margin.ref.ui',
+  'listview-margin.ui',
   'listview-with-wrapped-labels.ref.ui',
   'listview-with-wrapped-labels.ui',
   'marble.xpm',