2019-01-20 19:51:34 +01:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
)
|
|
|
|
|
2019-05-19 11:49:57 +02:00
|
|
|
// Drawable is a UI component that can draw. Unless specified, all methods must
|
|
|
|
// only be called from a single goroutine, the UI goroutine.
|
2019-01-20 19:51:34 +01:00
|
|
|
type Drawable interface {
|
2019-05-19 11:49:57 +02:00
|
|
|
// Called when this renderable should draw itself.
|
2019-01-20 19:51:34 +01:00
|
|
|
Draw(ctx *Context)
|
2019-05-19 11:49:57 +02:00
|
|
|
// Specifies a function to call when this cell needs to be redrawn. The
|
|
|
|
// callback may be called in any goroutine.
|
2019-01-20 19:51:34 +01:00
|
|
|
OnInvalidate(callback func(d Drawable))
|
2019-05-19 11:49:57 +02:00
|
|
|
// Invalidates the drawable. This can be called from any goroutine.
|
2019-01-20 19:51:34 +01:00
|
|
|
Invalidate()
|
|
|
|
}
|
|
|
|
|
|
|
|
type Interactive interface {
|
|
|
|
// Returns true if the event was handled by this component
|
|
|
|
Event(event tcell.Event) bool
|
2019-03-17 19:02:33 +01:00
|
|
|
// Indicates whether or not this control will receive input events
|
|
|
|
Focus(focus bool)
|
2019-01-20 19:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Simulator interface {
|
|
|
|
// Queues up the given input events for simulation
|
|
|
|
Simulate(events []tcell.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
type DrawableInteractive interface {
|
|
|
|
Drawable
|
|
|
|
Interactive
|
|
|
|
}
|
|
|
|
|
|
|
|
// A drawable which contains other drawables
|
|
|
|
type Container interface {
|
|
|
|
Drawable
|
2019-01-20 21:06:44 +01:00
|
|
|
// Return all of the drawables which are children of this one (do not
|
|
|
|
// recurse into your grandchildren).
|
2019-01-20 19:51:34 +01:00
|
|
|
Children() []Drawable
|
|
|
|
}
|