2019-01-20 19:51:34 +01:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
2020-11-30 23:07:03 +01:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2019-01-20 19:51:34 +01:00
|
|
|
)
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2020-03-03 22:20:07 +01:00
|
|
|
type RootDrawable interface {
|
|
|
|
Initialize(ui *UI)
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:51:34 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-29 16:50:02 +02:00
|
|
|
type Beeper interface {
|
|
|
|
OnBeep(func() error)
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:51:34 +01:00
|
|
|
type DrawableInteractive interface {
|
|
|
|
Drawable
|
|
|
|
Interactive
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:50:02 +02:00
|
|
|
type DrawableInteractiveBeeper interface {
|
|
|
|
DrawableInteractive
|
|
|
|
Beeper
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:51:34 +01:00
|
|
|
// 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
|
|
|
|
}
|
2019-07-12 00:15:15 +02:00
|
|
|
|
2019-09-06 00:32:36 +02: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-12 00:15:15 +02:00
|
|
|
Drawable
|
2019-09-06 00:32:36 +02:00
|
|
|
MouseHandler
|
|
|
|
}
|
2019-07-12 00:15:15 +02:00
|
|
|
|
2019-09-06 00:32:36 +02:00
|
|
|
type MouseableDrawableInteractive interface {
|
|
|
|
DrawableInteractive
|
|
|
|
MouseHandler
|
2019-07-12 00:15:15 +02:00
|
|
|
}
|