-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkbox.go
41 lines (34 loc) · 1.4 KB
/
checkbox.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
package goey
import (
"bitbucket.org/rj/goey/base"
)
var (
checkboxKind = base.NewKind("bitbucket.org/rj/goey.Checkbox")
)
// Checkbox describes a widget that users input or update a flag.
// The model for the value is a boolean value.
type Checkbox struct {
Text string // Text is a caption for the checkbox.
Value bool // Is the checkbox checked?
Disabled bool // Disabled is a flag indicating that the user cannot interact with this checkbox.
OnChange func(value bool) // OnChange will be called whenever the value (checked or unchecked) changes.
OnFocus func() // OnFocus will be called whenever the checkbox receives the keyboard focus.
OnBlur func() // OnBlur will be called whenever the checkbox loses the keyboard focus.
}
// Kind returns the concrete type for use in the Widget interface.
// Users should not need to use this method directly.
func (*Checkbox) Kind() *base.Kind {
return &checkboxKind
}
// Mount creates a checkbox control in the GUI.
// The newly created widget will be a child of the widget specified by parent.
func (w *Checkbox) Mount(parent base.Control) (base.Element, error) {
// Forward to the platform-dependant code
return w.mount(parent)
}
func (*checkboxElement) Kind() *base.Kind {
return &checkboxKind
}
func (w *checkboxElement) UpdateProps(data base.Widget) error {
return w.updateProps(data.(*Checkbox))
}