From 5d339e656b66d00356960ae057969532d34245b4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 2 Jul 2014 17:13:40 -0400 Subject: Moved everything out of the way pending rewrite. --- prevlib/layout.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 prevlib/layout.go (limited to 'prevlib/layout.go') diff --git a/prevlib/layout.go b/prevlib/layout.go new file mode 100644 index 0000000..e88cae4 --- /dev/null +++ b/prevlib/layout.go @@ -0,0 +1,36 @@ +package ui + +// Recursively replaces nils with stretchy empty spaces and changes the orientation +// of inner stack so they are perpenticular to each other. +func resetControls(parent *Stack) { + for i, control := range parent.controls { + switch control.(type) { + case *Stack: + stack := control.(*Stack) + stack.orientation = !parent.orientation + resetControls(stack) + case nil: + emptySpace := newStack(horizontal) + parent.controls[i] = emptySpace + parent.stretchy[i] = true + } + } +} + +// Creates a new Stack from the given controls. The topmost Stack will have +// vertical orientation and margin borders, with each nested stack being +// oriented oppositely. Controls are displayed with a default padding +// between them. +func Layout(controls ...Control) *Stack { + stack := &Stack{ + orientation: vertical, + controls: controls, + stretchy: make([]bool, len(controls)), + width: make([]int, len(controls)), + height: make([]int, len(controls)), + } + + resetControls(stack) + + return stack +} -- cgit v1.2.3