diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-11 12:12:26 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-11 17:07:49 +1000 |
commit | e3a14d546aa31851e6ab26dcdb21336ad94365c7 (patch) | |
tree | e272d6f596ae2f6e989f4a9c05d35d8594022c16 | |
parent | f2007f4d95b7d8b9c454bb00ea087f09a52a4fb4 (diff) |
support static boxes that go outside the available size
-rw-r--r-- | pkg/gui/boxlayout/boxlayout.go | 5 | ||||
-rw-r--r-- | pkg/gui/boxlayout/boxlayout_test.go | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/pkg/gui/boxlayout/boxlayout.go b/pkg/gui/boxlayout/boxlayout.go index ac077becd..36af2b2ab 100644 --- a/pkg/gui/boxlayout/boxlayout.go +++ b/pkg/gui/boxlayout/boxlayout.go @@ -96,6 +96,11 @@ func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions var boxSize int if child.isStatic() { boxSize = child.Size + // assuming that only one static child can have a size greater than the + // available space. In that case we just crop the size to what's available + if boxSize > availableSize { + boxSize = availableSize + } } else { // TODO: consider more evenly distributing the remainder boxSize = unitSize * child.Weight diff --git a/pkg/gui/boxlayout/boxlayout_test.go b/pkg/gui/boxlayout/boxlayout_test.go index 6f06379a3..65e6101f7 100644 --- a/pkg/gui/boxlayout/boxlayout_test.go +++ b/pkg/gui/boxlayout/boxlayout_test.go @@ -179,6 +179,27 @@ func TestArrangeWindows(t *testing.T) { ) }, }, + { + "Box with static child with size too large", + &Box{Direction: COLUMN, Children: []*Box{{Size: 11, Window: "static"}, {Weight: 1, Window: "dynamic1"}, {Weight: 2, Window: "dynamic2"}}}, + 0, + 0, + 10, + 10, + func(result map[string]Dimensions) { + assert.EqualValues( + t, + result, + map[string]Dimensions{ + "static": {X0: 0, X1: 9, Y0: 0, Y1: 9}, + // not sure if X0: 10, X1: 9 makes any sense, but testing this in the + // actual GUI it seems harmless + "dynamic1": {X0: 10, X1: 9, Y0: 0, Y1: 9}, + "dynamic2": {X0: 10, X1: 9, Y0: 0, Y1: 9}, + }, + ) + }, + }, } for _, s := range scenarios { |