aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-20 15:06:44 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-20 15:06:44 -0500
commita0c2b1caf03d0ed8b89de8402fcc14b003969e2c (patch)
treeef20eb601dcf9238b6d57aad7ae69e0f5c5d4d51 /lib
parent87fa305848a893b1c85472ea394f24486bd478b6 (diff)
Implement the Container interface in lib/ui/
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/borders.go4
-rw-r--r--lib/ui/grid.go8
-rw-r--r--lib/ui/interfaces.go9
-rw-r--r--lib/ui/stack.go4
-rw-r--r--lib/ui/tab.go8
5 files changed, 26 insertions, 7 deletions
diff --git a/lib/ui/borders.go b/lib/ui/borders.go
index 38b35fd..97df5df 100644
--- a/lib/ui/borders.go
+++ b/lib/ui/borders.go
@@ -30,6 +30,10 @@ func (bordered *Bordered) contentInvalidated(d Drawable) {
bordered.Invalidate()
}
+func (bordered *Bordered) Children() []Drawable {
+ return []Drawable{bordered.content}
+}
+
func (bordered *Bordered) Invalidate() {
if bordered.onInvalidate != nil {
bordered.onInvalidate(bordered)
diff --git a/lib/ui/grid.go b/lib/ui/grid.go
index 3c375ee..87b94bd 100644
--- a/lib/ui/grid.go
+++ b/lib/ui/grid.go
@@ -71,6 +71,14 @@ func (grid *Grid) Columns(spec []GridSpec) *Grid {
return grid
}
+func (grid *Grid) Children() []Drawable {
+ children := make([]Drawable, len(grid.cells))
+ for i, cell := range grid.cells {
+ children[i] = cell.Content
+ }
+ return children
+}
+
func (grid *Grid) Draw(ctx *Context) {
invalid := grid.invalid
if invalid {
diff --git a/lib/ui/interfaces.go b/lib/ui/interfaces.go
index 320183f..c38fcff 100644
--- a/lib/ui/interfaces.go
+++ b/lib/ui/interfaces.go
@@ -31,12 +31,7 @@ type DrawableInteractive interface {
// A drawable which contains other drawables
type Container interface {
Drawable
- // A list of all drawables which are children of this one (do not recurse
- // into your grandchildren).
+ // Return all of the drawables which are children of this one (do not
+ // recurse into your grandchildren).
Children() []Drawable
- // Return the "focused" child, or none of no preference. Does not actually
- // have to be Interactive. If there is a preferred child, input events will
- // be directed to it. If there's no preference, events will be delivered to
- // all children.
- InteractiveChild() Drawable
}
diff --git a/lib/ui/stack.go b/lib/ui/stack.go
index 2e3f0b9..75cc780 100644
--- a/lib/ui/stack.go
+++ b/lib/ui/stack.go
@@ -15,6 +15,10 @@ func NewStack() *Stack {
return &Stack{}
}
+func (stack *Stack) Children() []Drawable {
+ return stack.children
+}
+
func (stack *Stack) OnInvalidate(onInvalidate func(d Drawable)) {
stack.onInvalidate = append(stack.onInvalidate, onInvalidate)
}
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 8f08978..ecd48eb 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -107,6 +107,14 @@ func (strip *TabStrip) OnInvalidate(onInvalidate func(d Drawable)) {
strip.onInvalidateStrip = onInvalidate
}
+func (content *TabContent) Children() []Drawable {
+ children := make([]Drawable, len(content.Tabs))
+ for i, tab := range content.Tabs {
+ children[i] = tab.Content
+ }
+ return children
+}
+
func (content *TabContent) Draw(ctx *Context) {
if content.Selected >= len(content.Tabs) {
width := ctx.Width()