Implement the Container interface in lib/ui/

This commit is contained in:
Drew DeVault 2019-01-20 15:06:44 -05:00
parent 87fa305848
commit a0c2b1caf0
5 changed files with 26 additions and 7 deletions

View File

@ -30,6 +30,10 @@ func (bordered *Bordered) contentInvalidated(d Drawable) {
bordered.Invalidate() bordered.Invalidate()
} }
func (bordered *Bordered) Children() []Drawable {
return []Drawable{bordered.content}
}
func (bordered *Bordered) Invalidate() { func (bordered *Bordered) Invalidate() {
if bordered.onInvalidate != nil { if bordered.onInvalidate != nil {
bordered.onInvalidate(bordered) bordered.onInvalidate(bordered)

View File

@ -71,6 +71,14 @@ func (grid *Grid) Columns(spec []GridSpec) *Grid {
return 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) { func (grid *Grid) Draw(ctx *Context) {
invalid := grid.invalid invalid := grid.invalid
if invalid { if invalid {

View File

@ -31,12 +31,7 @@ type DrawableInteractive interface {
// A drawable which contains other drawables // A drawable which contains other drawables
type Container interface { type Container interface {
Drawable Drawable
// A list of all drawables which are children of this one (do not recurse // Return all of the drawables which are children of this one (do not
// into your grandchildren). // recurse into your grandchildren).
Children() []Drawable 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
} }

View File

@ -15,6 +15,10 @@ func NewStack() *Stack {
return &Stack{} return &Stack{}
} }
func (stack *Stack) Children() []Drawable {
return stack.children
}
func (stack *Stack) OnInvalidate(onInvalidate func(d Drawable)) { func (stack *Stack) OnInvalidate(onInvalidate func(d Drawable)) {
stack.onInvalidate = append(stack.onInvalidate, onInvalidate) stack.onInvalidate = append(stack.onInvalidate, onInvalidate)
} }

View File

@ -107,6 +107,14 @@ func (strip *TabStrip) OnInvalidate(onInvalidate func(d Drawable)) {
strip.onInvalidateStrip = onInvalidate 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) { func (content *TabContent) Draw(ctx *Context) {
if content.Selected >= len(content.Tabs) { if content.Selected >= len(content.Tabs) {
width := ctx.Width() width := ctx.Width()