-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck.go
93 lines (80 loc) · 2.2 KB
/
check.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
87
88
89
90
91
92
93
package wx
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/widget"
)
type CheckEx struct {
widget.Check
ToolTipable
// custom callbacks
OnFocusGained func()
OnFocusLost func()
OnTypedRune func(rune) (block bool)
OnTypedKey func(*fyne.KeyEvent) (block bool)
OnTypedShortcut func(fyne.Shortcut) (block bool)
}
func NewCheckEx(text string, changed func(bool)) *CheckEx {
c := &CheckEx{}
c.Check = widget.Check{
DisableableWidget: widget.DisableableWidget{},
Text: text,
OnChanged: changed,
}
c.ToolTipable.parent = c
c.ExtendBaseWidget(c)
return c
}
// FocusGained is a hook called by the focus handling logic after this object gained the focus.
func (c *CheckEx) FocusGained() {
c.Check.FocusGained()
if c.OnFocusGained != nil {
c.OnFocusGained()
}
}
// FocusLost is a hook called by the focus handling logic after this object lost the focus.
func (c *CheckEx) FocusLost() {
c.Check.FocusLost()
if c.OnFocusLost != nil {
c.OnFocusLost()
}
}
// TypedRune is a hook called by the input handling logic on text input events if this object is focused.
func (c *CheckEx) TypedRune(r rune) {
if c.OnTypedRune != nil && c.OnTypedRune(r) {
return
}
c.Check.TypedRune(r)
}
// TypedKey is a hook called by the input handling logic on key events if this object is focused.
func (c *CheckEx) TypedKey(k *fyne.KeyEvent) {
/*if k.Name == fyne.KeyEnter {
c.TypedKey(&fyne.KeyEvent{
Name: fyne.KeySpace,
})
}*/
if c.OnTypedKey != nil && c.OnTypedKey(k) {
return
}
c.Check.TypedKey(k)
}
func (c *CheckEx) TypedShortcut(s fyne.Shortcut) {
if c.OnTypedShortcut != nil && c.OnTypedShortcut(s) {
return
}
}
// MouseIn is a hook that is called if the mouse pointer enters the element.
func (c *CheckEx) MouseIn(me *desktop.MouseEvent) {
c.ToolTipable.MouseIn(me)
c.Check.MouseIn(me)
}
// MouseMoved is a hook that is called if the mouse pointer moved over the element.
func (c *CheckEx) MouseMoved(me *desktop.MouseEvent) {
c.ToolTipable.MouseMoved(me)
c.Check.MouseMoved(me)
}
// MouseOut is a hook that is called if the mouse pointer leaves the element.
func (c *CheckEx) MouseOut() {
c.ToolTipable.MouseOut()
c.Check.MouseOut()
}