2019-12-30 23:12:17 +00:00
|
|
|
package cview
|
2017-12-15 14:29:21 +00:00
|
|
|
|
2020-08-30 15:36:03 +00:00
|
|
|
import "github.com/gdamore/tcell/v2"
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
// Primitive is the top-most interface for all graphical primitives.
|
|
|
|
type Primitive interface {
|
|
|
|
// Draw draws this primitive onto the screen. Implementers can call the
|
|
|
|
// screen's ShowCursor() function but should only do so when they have focus.
|
|
|
|
// (They will need to keep track of this themselves.)
|
|
|
|
Draw(screen tcell.Screen)
|
|
|
|
|
|
|
|
// GetRect returns the current position of the primitive, x, y, width, and
|
|
|
|
// height.
|
|
|
|
GetRect() (int, int, int, int)
|
|
|
|
|
|
|
|
// SetRect sets a new position of the primitive.
|
|
|
|
SetRect(x, y, width, height int)
|
|
|
|
|
2020-10-20 02:05:03 +00:00
|
|
|
// GetVisible returns whether or not the primitive is visible.
|
|
|
|
GetVisible() bool
|
|
|
|
|
2020-10-20 04:05:10 +00:00
|
|
|
// SetVisible sets whether or not the primitive is visible.
|
|
|
|
SetVisible(v bool)
|
2020-10-20 02:05:03 +00:00
|
|
|
|
2017-12-15 14:29:21 +00:00
|
|
|
// InputHandler returns a handler which receives key events when it has focus.
|
|
|
|
// It is called by the Application class.
|
|
|
|
//
|
|
|
|
// A value of nil may also be returned, in which case this primitive cannot
|
|
|
|
// receive focus and will not process any key events.
|
|
|
|
//
|
2017-12-18 19:04:52 +00:00
|
|
|
// The handler will receive the key event and a function that allows it to
|
|
|
|
// set the focus to a different primitive, so that future key events are sent
|
|
|
|
// to that primitive.
|
|
|
|
//
|
2017-12-15 14:29:21 +00:00
|
|
|
// The Application's Draw() function will be called automatically after the
|
|
|
|
// handler returns.
|
2018-01-14 20:29:34 +00:00
|
|
|
//
|
|
|
|
// The Box class provides functionality to intercept keyboard input. If you
|
|
|
|
// subclass from Box, it is recommended that you wrap your handler using
|
2018-03-19 20:25:30 +00:00
|
|
|
// Box.WrapInputHandler() so you inherit that functionality.
|
2017-12-18 19:04:52 +00:00
|
|
|
InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
// Focus is called by the application when the primitive receives focus.
|
2017-12-18 19:04:52 +00:00
|
|
|
// Implementers may call delegate() to pass the focus on to another primitive.
|
|
|
|
Focus(delegate func(p Primitive))
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
// Blur is called by the application when the primitive loses focus.
|
|
|
|
Blur()
|
2017-12-20 19:54:49 +00:00
|
|
|
|
|
|
|
// GetFocusable returns the item's Focusable.
|
|
|
|
GetFocusable() Focusable
|
2019-11-04 05:34:46 +00:00
|
|
|
|
|
|
|
// MouseHandler returns a handler which receives mouse events.
|
|
|
|
// It is called by the Application class.
|
|
|
|
//
|
2020-03-29 19:43:46 +00:00
|
|
|
// A value of nil may also be returned to stop the downward propagation of
|
|
|
|
// mouse events.
|
2019-11-04 05:34:46 +00:00
|
|
|
//
|
|
|
|
// The Box class provides functionality to intercept mouse events. If you
|
|
|
|
// subclass from Box, it is recommended that you wrap your handler using
|
|
|
|
// Box.WrapMouseHandler() so you inherit that functionality.
|
2020-03-29 19:43:46 +00:00
|
|
|
MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive)
|
2017-12-15 14:29:21 +00:00
|
|
|
}
|