summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-08-24 16:43:39 +0000
committerMatthias Clasen <mclasen@redhat.com>2020-08-24 16:43:39 +0000
commit7ff326e700a30183b71832a75b0f00adbd756564 (patch)
tree8e27af5246d907a13772e7194bbf0239cf22c366
parentd27f9abbcaa2f17c77472b8d6bec79c1de2c40f4 (diff)
parentc890d5991c7ab24c019ae12ad04a59869495554f (diff)
downloadgtk+-7ff326e700a30183b71832a75b0f00adbd756564.tar.gz
Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master Closes #3081 See merge request GNOME/gtk!2472
-rw-r--r--gtk/gtkcenterlayout.c38
-rw-r--r--testsuite/reftests/boxlayout-invisible-child.ref.ui20
-rw-r--r--testsuite/reftests/boxlayout-invisible-child.ui27
-rw-r--r--testsuite/reftests/centerlayout-invisible-child.css3
-rw-r--r--testsuite/reftests/centerlayout-invisible-child.ref.ui21
-rw-r--r--testsuite/reftests/centerlayout-invisible-child.ui27
-rw-r--r--testsuite/reftests/centerlayout-minsize.css3
-rw-r--r--testsuite/reftests/centerlayout-minsize.ref.ui26
-rw-r--r--testsuite/reftests/centerlayout-minsize.ui27
-rw-r--r--testsuite/reftests/gridlayout-invisible-child.ref.ui28
-rw-r--r--testsuite/reftests/gridlayout-invisible-child.ui39
-rw-r--r--testsuite/reftests/meson.build10
12 files changed, 253 insertions, 16 deletions
diff --git a/gtk/gtkcenterlayout.c b/gtk/gtkcenterlayout.c
index c9519f15b2..ebf0817235 100644
--- a/gtk/gtkcenterlayout.c
+++ b/gtk/gtkcenterlayout.c
@@ -122,9 +122,15 @@ gtk_center_layout_distribute (GtkCenterLayout *self,
gboolean end_expand = FALSE;
int avail;
int i;
+ int needed_spacing = 0;
/* Usable space is really less... */
- size -= spacing * 2;
+ for (i = 0; i < 3; i++)
+ {
+ if (self->children[i])
+ needed_spacing += spacing;
+ }
+ needed_spacing -= spacing;
sizes[0].minimum_size = sizes[0].natural_size = 0;
sizes[1].minimum_size = sizes[1].natural_size = 0;
@@ -140,20 +146,20 @@ gtk_center_layout_distribute (GtkCenterLayout *self,
if (self->center_widget)
{
- center_size = CLAMP (size - (sizes[0].minimum_size + sizes[2].minimum_size), sizes[1].minimum_size, sizes[1].natural_size);
+ center_size = CLAMP (size - needed_spacing - (sizes[0].minimum_size + sizes[2].minimum_size), sizes[1].minimum_size, sizes[1].natural_size);
center_expand = get_expand (self->center_widget, self->orientation);
}
if (self->start_widget)
{
- avail = MIN ((size - center_size) / 2, size - (center_size + sizes[2].minimum_size));
+ avail = MIN ((size - needed_spacing - center_size) / 2, size - needed_spacing - (center_size + sizes[2].minimum_size));
start_size = CLAMP (avail, sizes[0].minimum_size, sizes[0].natural_size);
start_expand = get_expand (self->start_widget, self->orientation);
}
if (self->end_widget)
{
- avail = MIN ((size - center_size) / 2, size - (center_size + sizes[0].minimum_size));
+ avail = MIN ((size - needed_spacing - center_size) / 2, size - needed_spacing - (center_size + sizes[0].minimum_size));
end_size = CLAMP (avail, sizes[2].minimum_size, sizes[2].natural_size);
end_expand = get_expand (self->end_widget, self->orientation);
}
@@ -165,25 +171,25 @@ gtk_center_layout_distribute (GtkCenterLayout *self,
center_pos = (size / 2) - (center_size / 2);
/* Push in from start/end */
- if (start_size > center_pos)
- center_pos = start_size;
- else if (size - end_size < center_pos + center_size)
- center_pos = size - center_size - end_size;
+ if (start_size > 0 && start_size + spacing > center_pos)
+ center_pos = start_size + spacing;
+ else if (end_size > 0 && size - end_size - spacing < center_pos + center_size)
+ center_pos = size - center_size - end_size - spacing;
else if (center_expand)
{
center_size = size - 2 * MAX (start_size, end_size);
- center_pos = (size / 2) - (center_size / 2);
+ center_pos = (size / 2) - (center_size / 2) + spacing;
}
if (start_expand)
- start_size = center_pos;
+ start_size = center_pos - spacing;
if (end_expand)
- end_size = size - (center_pos + center_size);
+ end_size = size - (center_pos + center_size) - spacing;
}
else
{
- avail = size - (start_size + end_size);
+ avail = size - needed_spacing - (start_size + end_size);
if (start_expand && end_expand)
{
start_size += avail / 2;
@@ -484,10 +490,10 @@ gtk_center_layout_allocate (GtkLayoutManager *layout_manager,
if (child[1])
{
/* Push in from start/end */
- if (child_size[0] > child_pos[1])
- child_pos[1] = child_size[0];
- else if (size - child_size[2] < child_pos[1] + child_size[1])
- child_pos[1] = size - child_size[1] - child_size[2];
+ if (child_size[0] > 0 && child_size[0] + spacing > child_pos[1])
+ child_pos[1] = child_size[0] + spacing;
+ else if (child_size[2] > 0 && size - child_size[2] - spacing < child_pos[1] + child_size[1])
+ child_pos[1] = size - child_size[1] - child_size[2] - spacing;
}
for (i = 0; i < 3; i++)
diff --git a/testsuite/reftests/boxlayout-invisible-child.ref.ui b/testsuite/reftests/boxlayout-invisible-child.ref.ui
new file mode 100644
index 0000000000..04eb01fd37
--- /dev/null
+++ b/testsuite/reftests/boxlayout-invisible-child.ref.ui
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/boxlayout-invisible-child.ui b/testsuite/reftests/boxlayout-invisible-child.ui
new file mode 100644
index 0000000000..d3f37c0b6f
--- /dev/null
+++ b/testsuite/reftests/boxlayout-invisible-child.ui
@@ -0,0 +1,27 @@
+<!-- check that an invisible child does not influence the layout -->
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">0</property>
+ <property name="label" translatable="yes">cruel</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/centerlayout-invisible-child.css b/testsuite/reftests/centerlayout-invisible-child.css
new file mode 100644
index 0000000000..9e5d48a484
--- /dev/null
+++ b/testsuite/reftests/centerlayout-invisible-child.css
@@ -0,0 +1,3 @@
+box {
+ border-spacing: 10px;
+}
diff --git a/testsuite/reftests/centerlayout-invisible-child.ref.ui b/testsuite/reftests/centerlayout-invisible-child.ref.ui
new file mode 100644
index 0000000000..fc1055a55a
--- /dev/null
+++ b/testsuite/reftests/centerlayout-invisible-child.ref.ui
@@ -0,0 +1,21 @@
+<!-- check that an invisible child does not influence the layout -->
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkCenterBox" id="box1">
+ <child type="start">
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello, Hello</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/centerlayout-invisible-child.ui b/testsuite/reftests/centerlayout-invisible-child.ui
new file mode 100644
index 0000000000..30888471b0
--- /dev/null
+++ b/testsuite/reftests/centerlayout-invisible-child.ui
@@ -0,0 +1,27 @@
+<!-- check that an invisible child does not influence the layout -->
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkCenterBox" id="box1">
+ <child type="start">
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello, Hello</property>
+ </object>
+ </child>
+ <child type="center">
+ <object class="GtkLabel" id="label2">
+ <property name="visible">0</property>
+ <property name="label" translatable="yes">cruel</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/centerlayout-minsize.css b/testsuite/reftests/centerlayout-minsize.css
new file mode 100644
index 0000000000..9e5d48a484
--- /dev/null
+++ b/testsuite/reftests/centerlayout-minsize.css
@@ -0,0 +1,3 @@
+box {
+ border-spacing: 10px;
+}
diff --git a/testsuite/reftests/centerlayout-minsize.ref.ui b/testsuite/reftests/centerlayout-minsize.ref.ui
new file mode 100644
index 0000000000..8791443f2b
--- /dev/null
+++ b/testsuite/reftests/centerlayout-minsize.ref.ui
@@ -0,0 +1,26 @@
+<!-- check that an invisible child does not influence the layout -->
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello, Hello</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="label" translatable="yes">cruel</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/centerlayout-minsize.ui b/testsuite/reftests/centerlayout-minsize.ui
new file mode 100644
index 0000000000..7f11882cf4
--- /dev/null
+++ b/testsuite/reftests/centerlayout-minsize.ui
@@ -0,0 +1,27 @@
+<!-- check that an invisible child does not influence the layout -->
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <property name="default-width">20</property>
+ <child>
+ <object class="GtkCenterBox" id="box1">
+ <child type="start">
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello, Hello</property>
+ </object>
+ </child>
+ <child type="center">
+ <object class="GtkLabel" id="label2">
+ <property name="label" translatable="yes">cruel</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/gridlayout-invisible-child.ref.ui b/testsuite/reftests/gridlayout-invisible-child.ref.ui
new file mode 100644
index 0000000000..ad64be95bc
--- /dev/null
+++ b/testsuite/reftests/gridlayout-invisible-child.ref.ui
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkGrid" id="grid1">
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello</property>
+ <layout>
+ <property name="row">0</property>
+ <property name="column">0</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ <layout>
+ <property name="row">0</property>
+ <property name="column">2</property>
+ </layout>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/gridlayout-invisible-child.ui b/testsuite/reftests/gridlayout-invisible-child.ui
new file mode 100644
index 0000000000..eeebd7abb2
--- /dev/null
+++ b/testsuite/reftests/gridlayout-invisible-child.ui
@@ -0,0 +1,39 @@
+<!-- check that an invisible child does not influence the layout -->
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window_information_collection">
+ <property name="decorated">0</property>
+ <child>
+ <object class="GtkGrid" id="grid1">
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="label" translatable="yes">Hello</property>
+ <layout>
+ <property name="row">0</property>
+ <property name="column">0</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">0</property>
+ <property name="label" translatable="yes">cruel</property>
+ <layout>
+ <property name="row">0</property>
+ <property name="column">1</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="label" translatable="yes">World</property>
+ <layout>
+ <property name="row">0</property>
+ <property name="column">2</property>
+ </layout>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index 816e370992..0e8bdbc16e 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -141,6 +141,8 @@ testdata = [
'border-style.css',
'border-style.ref.ui',
'border-style.ui',
+ 'boxlayout-invisible-child.ref.ui',
+ 'boxlayout-invisible-child.ui',
'box-order.css',
'box-order.ref.ui',
'box-order.ui',
@@ -161,6 +163,12 @@ testdata = [
'box-shadow-with-blend-mode.ui',
'button-wrapping.ui',
'button-wrapping.ref.ui',
+ 'centerlayout-invisible-child.css',
+ 'centerlayout-invisible-child.ref.ui',
+ 'centerlayout-invisible-child.ui',
+ 'centerlayout-minsize.css',
+ 'centerlayout-minsize.ref.ui',
+ 'centerlayout-minsize.ui',
'color-transition.css',
'color-transition.ref.ui',
'color-transition.ui',
@@ -227,6 +235,8 @@ testdata = [
'gradient-hard-stop.ref.ui',
'gradient-hard-stop.ui',
'green-20x20.png',
+ 'gridlayout-invisible-child.ref.ui',
+ 'gridlayout-invisible-child.ui',
'grid-empty-with-spacing.ref.ui',
'grid-empty-with-spacing.ui',
'grid-expand.css',