summaryrefslogtreecommitdiff
path: root/layout.go
diff options
context:
space:
mode:
authorBoppreH <[email protected]>2014-06-26 15:11:57 -0300
committerBoppreH <[email protected]>2014-06-26 15:11:57 -0300
commit52bccbc8da143e56e8b158d91d8aa93f1990d4c8 (patch)
tree0ccd59bc2a46ca9bec26cfe8ca4b687a62feff12 /layout.go
parent3bedaf483a8b26d3db218d57296dfe4dc1d5d5b1 (diff)
Add old layout.go
Diffstat (limited to 'layout.go')
-rw-r--r--layout.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/layout.go b/layout.go
new file mode 100644
index 0000000..e4fda38
--- /dev/null
+++ b/layout.go
@@ -0,0 +1,40 @@
+package ui
+
+// Recursively removes border margins and padding from controls, replaces
+// nil values with stretchy spaces and reorients nested stack to have
+// opposing orientations.
+func resetControls(parent *Stack) {
+ for i, control := range parent.controls {
+ switch control.(type) {
+ case *Stack:
+ stack := control.(*Stack)
+ stack.borderMargin = 0
+ 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)),
+ padding: 10,
+ borderMargin: 15,
+ }
+
+ resetControls(stack)
+
+ return stack
+}