-
-
Notifications
You must be signed in to change notification settings - Fork 669
Expand file tree
/
Copy pathprimitive.go
More file actions
93 lines (80 loc) · 4.07 KB
/
primitive.go
File metadata and controls
93 lines (80 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package tview
import "github.com/gdamore/tcell/v2"
// 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)
// 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.
//
// 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.
//
// The Application's Draw() function will be called automatically after the
// handler returns.
//
// The Box class provides functionality to intercept keyboard input. If you
// subclass from Box, it is recommended that you wrap your handler using
// Box.WrapInputHandler() so you inherit that functionality.
InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
// Focus is called by the application when the primitive receives focus.
// Implementers may call delegate() to pass the focus on to another
// primitive which is usually a child primitive. This is not called on
// parents of the primitive that receives focus.
Focus(delegate func(p Primitive))
// HasFocus determines if the primitive (or any of its child primitives) has
// focus.
HasFocus() bool
// Blur is called by the application when the primitive loses focus. This is
// not called on parents of the primitive that loses focus.
Blur()
// MouseHandler returns a handler which receives mouse events.
// It is called by the Application class.
//
// A value of nil may also be returned to stop the downward propagation of
// mouse events.
//
// 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.
MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive)
// PasteHandler returns a handler which receives pasted text.
// It is called by the Application class.
//
// A value of nil may also be returned to stop the downward propagation of
// paste events.
//
// The Box class may provide functionality to intercept paste events in the
// future. If you subclass from [Box], it is recommended that you wrap your
// handler using Box.WrapPasteHandler() so you inherit that functionality.
PasteHandler() func(text string, setFocus func(p Primitive))
// focusChain adds the chain of primitives that have focus to the given
// slice, starting with the bottom-most primitive that has focus and ending
// with this box. If this box or none of its descendents has focus, the
// slice is not modified. If chain is nil, no chain is added. Returns
// whether or not this box or one of its descendents has focus.
focusChain(chain *[]Primitive) bool
// focused is called when the current input focus changes. It is called on
// the primitive which newly received focus as well as on all of its
// ancestors (in no defined order). The default implementation in [Box]
// invokes the callback set with [Box.SetFocusFunc]. This can also happen
// when the focus is set to the primitive that already has focus.
focused()
// blurred is called when the current input focus changes. It is called on
// the primitive which lost focus as well as on all of its ancestors (in no
// defined order). The default implementation in [Box] invokes the callback
// set with [Box.SetBlurFunc]. This can also happen when the focus is set to
// the primitive that already has focus.
blurred()
}