1package tview
2
3import "github.com/gdamore/tcell"
4
5// Primitive is the top-most interface for all graphical primitives.
6type Primitive interface {
7	// Draw draws this primitive onto the screen. Implementers can call the
8	// screen's ShowCursor() function but should only do so when they have focus.
9	// (They will need to keep track of this themselves.)
10	Draw(screen tcell.Screen)
11
12	// GetRect returns the current position of the primitive, x, y, width, and
13	// height.
14	GetRect() (int, int, int, int)
15
16	// SetRect sets a new position of the primitive.
17	SetRect(x, y, width, height int)
18
19	// InputHandler returns a handler which receives key events when it has focus.
20	// It is called by the Application class.
21	//
22	// A value of nil may also be returned, in which case this primitive cannot
23	// receive focus and will not process any key events.
24	//
25	// The handler will receive the key event and a function that allows it to
26	// set the focus to a different primitive, so that future key events are sent
27	// to that primitive.
28	//
29	// The Application's Draw() function will be called automatically after the
30	// handler returns.
31	//
32	// The Box class provides functionality to intercept keyboard input. If you
33	// subclass from Box, it is recommended that you wrap your handler using
34	// Box.WrapInputHandler() so you inherit that functionality.
35	InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
36
37	// Focus is called by the application when the primitive receives focus.
38	// Implementers may call delegate() to pass the focus on to another primitive.
39	Focus(delegate func(p Primitive))
40
41	// Blur is called by the application when the primitive loses focus.
42	Blur()
43
44	// GetFocusable returns the item's Focusable.
45	GetFocusable() Focusable
46
47	// MouseHandler returns a handler which receives mouse events.
48	// It is called by the Application class.
49	//
50	// A value of nil may also be returned to stop the downward propagation of
51	// mouse events.
52	//
53	// The Box class provides functionality to intercept mouse events. If you
54	// subclass from Box, it is recommended that you wrap your handler using
55	// Box.WrapMouseHandler() so you inherit that functionality.
56	MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive)
57}
58