summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-26 14:21:44 -0400
committerPietro Gagliardi <[email protected]>2014-06-26 14:21:44 -0400
commitb398150c09016d1765cde9213ecb2f51dc883868 (patch)
tree0ccd59bc2a46ca9bec26cfe8ca4b687a62feff12
parent3bedaf483a8b26d3db218d57296dfe4dc1d5d5b1 (diff)
parent52bccbc8da143e56e8b158d91d8aa93f1990d4c8 (diff)
Merge pull request #19 from boppreh/master
Add a Layout function for higher-level layouts. I might put this in a subrepository. Thanks @boppreh
-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
+}