-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.go
More file actions
56 lines (47 loc) · 1.08 KB
/
button.go
File metadata and controls
56 lines (47 loc) · 1.08 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
package gui
type ButtonChangeCallback func(state bool)
type Button struct {
Label
pressed bool
onChangeCallback ButtonChangeCallback
}
func NewButton(text string, changeCallback ...ButtonChangeCallback) *Button {
b := &Button{}
widgetInit(b)
b.style = CurrentGui().Theme().Button
b.text = text
if len(changeCallback) == 1 {
b.onChangeCallback = changeCallback[0]
}
return b
}
func (b *Button) Pressed() bool { return b.pressed }
func (b *Button) SetOnChangeCallback(f ButtonChangeCallback) {
b.onChangeCallback = f
}
func (b *Button) setPressed(pressed bool) {
b.pressed = pressed
if pressed {
b.fireChangeEvent(true)
}
}
func (b *Button) fireChangeEvent(state bool) {
if b.onChangeCallback != nil {
b.onChangeCallback(state)
}
}
func (b *Button) OnMouseEvent(event MouseEvent) IWidget {
if event.Type == MouseEventButton {
if event.Button != MouseButtonLeft {
return nil
}
if event.Action == EventActionPress {
b.setPressed(true)
return b
} else if event.Action == EventActionRelease {
b.setPressed(false)
return b
}
}
return nil
}