From 2ac51ad8278a120b9aa2e0c49a18fd4c8e45f2ca Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 23 Aug 2020 23:15:57 -0400 Subject: centerlayout: Some spacing-related fixes Try to arrange for border-spacing to actually be respected in the final layout. Fixes: #3081 --- gtk/gtkcenterlayout.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 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++) -- cgit v1.2.1 From 17dcb1070733d41f483b82f2813e8961c4a81835 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 24 Aug 2020 10:58:18 -0400 Subject: Add a reftest for box layouts This tests that invisible children don't influence the layout. --- .../reftests/boxlayout-invisible-child.ref.ui | 20 ++++++++++++++++ testsuite/reftests/boxlayout-invisible-child.ui | 27 ++++++++++++++++++++++ testsuite/reftests/meson.build | 2 ++ 3 files changed, 49 insertions(+) create mode 100644 testsuite/reftests/boxlayout-invisible-child.ref.ui create mode 100644 testsuite/reftests/boxlayout-invisible-child.ui 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 @@ + + + + 0 + + + + + Hello + + + + + World + + + + + + 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 @@ + + + + + 0 + + + + + Hello + + + + + 0 + cruel + + + + + World + + + + + + diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build index 816e370992..001baa6fb6 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', -- cgit v1.2.1 From 08f58122d1ebeab7bc1be2e0c7f4a612f05d250d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 24 Aug 2020 11:38:00 -0400 Subject: Add a reftest for grid layouts This tests that invisible children don't influence the layout. --- .../reftests/gridlayout-invisible-child.ref.ui | 28 ++++++++++++++++ testsuite/reftests/gridlayout-invisible-child.ui | 39 ++++++++++++++++++++++ testsuite/reftests/meson.build | 2 ++ 3 files changed, 69 insertions(+) create mode 100644 testsuite/reftests/gridlayout-invisible-child.ref.ui create mode 100644 testsuite/reftests/gridlayout-invisible-child.ui 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 @@ + + + + 0 + + + + + Hello + + 0 + 0 + + + + + + World + + 0 + 2 + + + + + + + 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 @@ + + + + + 0 + + + + + Hello + + 0 + 0 + + + + + + 0 + cruel + + 0 + 1 + + + + + + World + + 0 + 2 + + + + + + + diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build index 001baa6fb6..a6a5210a77 100644 --- a/testsuite/reftests/meson.build +++ b/testsuite/reftests/meson.build @@ -229,6 +229,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', -- cgit v1.2.1 From c890d5991c7ab24c019ae12ad04a59869495554f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 24 Aug 2020 12:02:34 -0400 Subject: Add reftests for center layout Add a test that checks behavior with invisible children, and another one that ensures we go back to box-like layout if min-size is forced. --- .../reftests/centerlayout-invisible-child.css | 3 +++ .../reftests/centerlayout-invisible-child.ref.ui | 21 +++++++++++++++++ testsuite/reftests/centerlayout-invisible-child.ui | 27 ++++++++++++++++++++++ testsuite/reftests/centerlayout-minsize.css | 3 +++ testsuite/reftests/centerlayout-minsize.ref.ui | 26 +++++++++++++++++++++ testsuite/reftests/centerlayout-minsize.ui | 27 ++++++++++++++++++++++ testsuite/reftests/meson.build | 6 +++++ 7 files changed, 113 insertions(+) create mode 100644 testsuite/reftests/centerlayout-invisible-child.css create mode 100644 testsuite/reftests/centerlayout-invisible-child.ref.ui create mode 100644 testsuite/reftests/centerlayout-invisible-child.ui create mode 100644 testsuite/reftests/centerlayout-minsize.css create mode 100644 testsuite/reftests/centerlayout-minsize.ref.ui create mode 100644 testsuite/reftests/centerlayout-minsize.ui 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 @@ + + + + + 0 + + + + + Hello, Hello + + + + + World + + + + + + 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 @@ + + + + + 0 + + + + + Hello, Hello + + + + + 0 + cruel + + + + + World + + + + + + 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 @@ + + + + + 0 + + + + + Hello, Hello + + + + + cruel + + + + + World + + + + + + 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 @@ + + + + + 0 + 20 + + + + + Hello, Hello + + + + + cruel + + + + + World + + + + + + diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build index a6a5210a77..0e8bdbc16e 100644 --- a/testsuite/reftests/meson.build +++ b/testsuite/reftests/meson.build @@ -163,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', -- cgit v1.2.1