2019-01-20 18:51:34 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
)
|
|
|
|
|
2019-05-19 09:49:57 +00: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 18:51:34 +00:00
|
|
|
type Drawable interface {
|
2019-05-19 09:49:57 +00:00
|
|
|
// Called when this renderable should draw itself.
|
2019-01-20 18:51:34 +00:00
|
|
|
Draw(ctx *Context)
|
2019-05-19 09:49:57 +00:00
|
|
|
// Specifies a function to call when this cell needs to be redrawn. The
|
|
|
|
// callback may be called in any goroutine.
|
2019-01-20 18:51:34 +00:00
|
|
|
OnInvalidate(callback func(d Drawable))
|
2019-05-19 09:49:57 +00:00
|
|
|
// Invalidates the drawable. This can be called from any goroutine.
|
2019-01-20 18:51:34 +00:00
|
|
|
Invalidate()
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:20:07 +00:00
|
|
|
type RootDrawable interface {
|
|
|
|
Initialize(ui *UI)
|
|
|
|
}
|
|
|
|
|
2019-01-20 18:51:34 +00:00
|
|
|
type Interactive interface {
|
|
|
|
// Returns true if the event was handled by this component
|
|
|
|
Event(event tcell.Event) bool
|
2019-03-17 18:02:33 +00:00
|
|
|
// Indicates whether or not this control will receive input events
|
|
|
|
Focus(focus bool)
|
2019-01-20 18:51:34 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 14:50:02 +00:00
|
|
|
type Beeper interface {
|
|
|
|
OnBeep(func() error)
|
|
|
|
}
|
|
|
|
|
2019-01-20 18:51:34 +00:00
|
|
|
type DrawableInteractive interface {
|
|
|
|
Drawable
|
|
|
|
Interactive
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:50:02 +00:00
|
|
|
type DrawableInteractiveBeeper interface {
|
|
|
|
DrawableInteractive
|
|
|
|
Beeper
|
|
|
|
}
|
|
|
|
|
2019-01-20 18:51:34 +00:00
|
|
|
// A drawable which contains other drawables
|
|
|
|
type Container interface {
|
|
|
|
Drawable
|
2019-01-20 20:06:44 +00:00
|
|
|
// Return all of the drawables which are children of this one (do not
|
|
|
|
// recurse into your grandchildren).
|
2019-01-20 18:51:34 +00:00
|
|
|
Children() []Drawable
|
|
|
|
}
|
2019-07-11 22:15:15 +00:00
|
|
|
|
2019-09-05 22:32:36 +00:00
|
|
|
type MouseHandler interface {
|
|
|
|
// Handle a mouse event which occurred at the local x and y positions
|
|
|
|
MouseEvent(localX int, localY int, event tcell.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A drawable that can be interacted with by the mouse
|
|
|
|
type Mouseable interface {
|
2019-07-11 22:15:15 +00:00
|
|
|
Drawable
|
2019-09-05 22:32:36 +00:00
|
|
|
MouseHandler
|
|
|
|
}
|
2019-07-11 22:15:15 +00:00
|
|
|
|
2019-09-05 22:32:36 +00:00
|
|
|
type MouseableDrawableInteractive interface {
|
|
|
|
DrawableInteractive
|
|
|
|
MouseHandler
|
2019-07-11 22:15:15 +00:00
|
|
|
}
|