diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-21 19:53:45 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:29:18 +1000 |
commit | 2d90e1e8ee5ccb3d2acd8678e68137645c9e65bd (patch) | |
tree | cb623a51873bd086967ea794b21210861ce5031e /pkg/gui/boxlayout | |
parent | ddf25e14afe5ddfc2527149c54ea55ea2e83610a (diff) |
commit files kind of generalised
Diffstat (limited to 'pkg/gui/boxlayout')
-rw-r--r-- | pkg/gui/boxlayout/boxlayout.go | 20 | ||||
-rw-r--r-- | pkg/gui/boxlayout/boxlayout_test.go | 22 |
2 files changed, 21 insertions, 21 deletions
diff --git a/pkg/gui/boxlayout/boxlayout.go b/pkg/gui/boxlayout/boxlayout.go index f4bd8310e..b5d78faea 100644 --- a/pkg/gui/boxlayout/boxlayout.go +++ b/pkg/gui/boxlayout/boxlayout.go @@ -14,9 +14,9 @@ const ( COLUMN ) -// to give a high-level explanation of what's going on here. We layout our views by arranging a bunch of boxes in the window. +// to give a high-level explanation of what's going on here. We layout our windows by arranging a bunch of boxes in the available space. // If a box has children, it needs to specify how it wants to arrange those children: ROW or COLUMN. -// If a box represents a view, you can put the view name in the viewName field. +// If a box represents a window, you can put the window name in the Window field. // When determining how to divvy-up the available height (for row children) or width (for column children), we first // give the boxes with a static `size` the space that they want. Then we apportion // the remaining space based on the weights of the dynamic boxes (you can't define @@ -36,8 +36,8 @@ type Box struct { // function which takes the width and height assigned to the box and decides the layout of the children. ConditionalChildren func(width int, height int) []*Box - // ViewName refers to the name of the view this box represents, if there is one - ViewName string + // Window refers to the name of the window this box represents, if there is one + Window string // static Size. If parent box's direction is ROW this refers to height, otherwise width Size int @@ -47,13 +47,13 @@ type Box struct { Weight int } -func ArrangeViews(root *Box, x0, y0, width, height int) map[string]Dimensions { +func ArrangeWindows(root *Box, x0, y0, width, height int) map[string]Dimensions { children := root.getChildren(width, height) if len(children) == 0 { // leaf node - if root.ViewName != "" { - dimensionsForView := Dimensions{X0: x0, Y0: y0, X1: x0 + width - 1, Y1: y0 + height - 1} - return map[string]Dimensions{root.ViewName: dimensionsForView} + if root.Window != "" { + dimensionsForWindow := Dimensions{X0: x0, Y0: y0, X1: x0 + width - 1, Y1: y0 + height - 1} + return map[string]Dimensions{root.Window: dimensionsForWindow} } return map[string]Dimensions{} } @@ -104,9 +104,9 @@ func ArrangeViews(root *Box, x0, y0, width, height int) map[string]Dimensions { var resultForChild map[string]Dimensions if direction == COLUMN { - resultForChild = ArrangeViews(child, x0+offset, y0, boxSize, height) + resultForChild = ArrangeWindows(child, x0+offset, y0, boxSize, height) } else { - resultForChild = ArrangeViews(child, x0, y0+offset, width, boxSize) + resultForChild = ArrangeWindows(child, x0, y0+offset, width, boxSize) } result = mergeDimensionMaps(result, resultForChild) diff --git a/pkg/gui/boxlayout/boxlayout_test.go b/pkg/gui/boxlayout/boxlayout_test.go index 05d97ca9d..d339f828f 100644 --- a/pkg/gui/boxlayout/boxlayout_test.go +++ b/pkg/gui/boxlayout/boxlayout_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestArrangeViews(t *testing.T) { +func TestArrangeWindows(t *testing.T) { type scenario struct { testName string root *Box @@ -31,7 +31,7 @@ func TestArrangeViews(t *testing.T) { }, { "Box with static and dynamic panel", - &Box{Children: []*Box{{Size: 1, ViewName: "static"}, {Weight: 1, ViewName: "dynamic"}}}, + &Box{Children: []*Box{{Size: 1, Window: "static"}, {Weight: 1, Window: "dynamic"}}}, 0, 0, 10, @@ -49,7 +49,7 @@ func TestArrangeViews(t *testing.T) { }, { "Box with static and two dynamic panels", - &Box{Children: []*Box{{Size: 1, ViewName: "static"}, {Weight: 1, ViewName: "dynamic1"}, {Weight: 2, ViewName: "dynamic2"}}}, + &Box{Children: []*Box{{Size: 1, Window: "static"}, {Weight: 1, Window: "dynamic1"}, {Weight: 2, Window: "dynamic2"}}}, 0, 0, 10, @@ -68,7 +68,7 @@ func TestArrangeViews(t *testing.T) { }, { "Box with COLUMN direction", - &Box{Direction: COLUMN, Children: []*Box{{Size: 1, ViewName: "static"}, {Weight: 1, ViewName: "dynamic1"}, {Weight: 2, ViewName: "dynamic2"}}}, + &Box{Direction: COLUMN, Children: []*Box{{Size: 1, Window: "static"}, {Weight: 1, Window: "dynamic1"}, {Weight: 2, Window: "dynamic2"}}}, 0, 0, 10, @@ -93,7 +93,7 @@ func TestArrangeViews(t *testing.T) { } else { return ROW } - }, Children: []*Box{{Weight: 1, ViewName: "dynamic1"}, {Weight: 1, ViewName: "dynamic2"}}}, + }, Children: []*Box{{Weight: 1, Window: "dynamic1"}, {Weight: 1, Window: "dynamic2"}}}, 0, 0, 4, @@ -117,7 +117,7 @@ func TestArrangeViews(t *testing.T) { } else { return ROW } - }, Children: []*Box{{Weight: 1, ViewName: "dynamic1"}, {Weight: 1, ViewName: "dynamic2"}}}, + }, Children: []*Box{{Weight: 1, Window: "dynamic1"}, {Weight: 1, Window: "dynamic2"}}}, 0, 0, 5, @@ -137,9 +137,9 @@ func TestArrangeViews(t *testing.T) { "Box with conditional children where box is wide", &Box{ConditionalChildren: func(width int, height int) []*Box { if width > 4 { - return []*Box{{ViewName: "wide", Weight: 1}} + return []*Box{{Window: "wide", Weight: 1}} } else { - return []*Box{{ViewName: "narrow", Weight: 1}} + return []*Box{{Window: "narrow", Weight: 1}} } }}, 0, @@ -160,9 +160,9 @@ func TestArrangeViews(t *testing.T) { "Box with conditional children where box is narrow", &Box{ConditionalChildren: func(width int, height int) []*Box { if width > 4 { - return []*Box{{ViewName: "wide", Weight: 1}} + return []*Box{{Window: "wide", Weight: 1}} } else { - return []*Box{{ViewName: "narrow", Weight: 1}} + return []*Box{{Window: "narrow", Weight: 1}} } }}, 0, @@ -183,7 +183,7 @@ func TestArrangeViews(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - s.test(ArrangeViews(s.root, s.x0, s.y0, s.width, s.height)) + s.test(ArrangeWindows(s.root, s.x0, s.y0, s.width, s.height)) }) } } |