forked from jojomi/gonsole
-
Notifications
You must be signed in to change notification settings - Fork 4
/
interface.go
86 lines (60 loc) · 1.53 KB
/
interface.go
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
package gonsole
import "github.com/nsf/termbox-go"
// An UI element. It has a position, margin, padding, colors and other style properties.
type Element interface {
GetWindow() AppWindow
Parent() Container
ID() string
Dirty() bool
SetDirty(dirty bool)
Enabled() bool
SetEnabled(enabled bool)
Focused() bool
Focus()
Position() Position
SetPosition(pos Position)
Margin() Sides
SetMargin(margins Sides)
Padding() Sides
SetPadding(margins Sides)
Colors() (fg Attribute, bg Attribute)
SetColors(fg Attribute, bg Attribute)
FocusColors() (fg Attribute, bg Attribute)
SetFocusColors(fg Attribute, bg Attribute)
BorderType() LineType
SetBorderType(border LineType)
BorderColors() (fg Attribute, bg Attribute)
SetBorderColors(fg Attribute, bg Attribute)
AbsolutePosition() Box
BorderBox() Box
ContentBox() Box
ParseEvent(ev *termbox.Event) (handled, repaint bool)
Repaint()
Theme() *Theme
}
// An element that is a container for controls
type Container interface {
Element
Title() string
SetTitle(title string)
AddControl(control Control)
Children() []Control
ChildrenDeep() []Control
}
// A control which is an element that can optional be focused
type Control interface {
Element
Focusable() bool
SetFocusable(active bool)
Cursorable() bool
SetCursorable(cursorable bool)
}
// A window which is a top level container for controls.
// TODO: a better name for this interface. ideally "window"
type AppWindow interface {
Container
App() *App
Close()
FocusedControl() Control
FocusControl(control Control)
}