-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckbox.go
More file actions
38 lines (32 loc) · 746 Bytes
/
checkbox.go
File metadata and controls
38 lines (32 loc) · 746 Bytes
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
package gui
type Checkbox struct {
Button
}
func NewCheckbox(text string, changeCallback ...ButtonChangeCallback) *Checkbox {
b := &Checkbox{}
widgetInit(b)
b.style = CurrentGui().Theme().Checkbox
b.text = text
if len(changeCallback) == 1 {
b.onChangeCallback = changeCallback[0]
}
return b
}
func (b *Checkbox) Checked() bool { return b.pressed }
func (b *Checkbox) SetChecked(checked bool) {
b.pressed = checked
b.fireChangeEvent(checked)
}
func (b *Checkbox) OnMouseEvent(event MouseEvent) IWidget {
if event.Type == MouseEventButton {
if event.Button != MouseButtonLeft {
return nil
}
if event.Action == EventActionPress {
b.pressed = !b.pressed
b.fireChangeEvent(b.pressed)
return b
}
}
return nil
}