~sircmpwn/aerc

a0c2b1caf03d0ed8b89de8402fcc14b003969e2c — Drew DeVault 2 years ago 87fa305
Implement the Container interface in lib/ui/
5 files changed, 26 insertions(+), 7 deletions(-)

M lib/ui/borders.go
M lib/ui/grid.go
M lib/ui/interfaces.go
M lib/ui/stack.go
M lib/ui/tab.go
M lib/ui/borders.go => lib/ui/borders.go +4 -0
@@ 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)

M lib/ui/grid.go => lib/ui/grid.go +8 -0
@@ 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 {

M lib/ui/interfaces.go => lib/ui/interfaces.go +2 -7
@@ 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
}

M lib/ui/stack.go => lib/ui/stack.go +4 -0
@@ 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)
}

M lib/ui/tab.go => lib/ui/tab.go +8 -0
@@ 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()