summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-26 14:24:16 -0400
committerPietro Gagliardi <[email protected]>2014-06-26 14:24:16 -0400
commit999e669aa4b92d4df8e6a3209fb793d09b49519d (patch)
treecbaa3486f4ee63bf7a227b10365648b67edc323b
parent2a0dbfc74a5def29d6902dcb6dc0de9e6884d032 (diff)
parentb398150c09016d1765cde9213ecb2f51dc883868 (diff)
Merge branch 'master' of github.com:andlabs/ui
-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
+}