-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicon.go
47 lines (38 loc) · 882 Bytes
/
icon.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
package wx
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
type Icon struct {
widget.Icon
OnTapped func(e *fyne.PointEvent)
OnTappedSecondary func(e *fyne.PointEvent)
PointerCursor bool
}
func NewIcon(res fyne.Resource) *Icon {
w := &Icon{}
w.ExtendBaseWidget(w)
w.Resource = res
return w
}
func (w *Icon) SetColor(clr fyne.ThemeColorName) {
w.SetResource(theme.NewColoredResource(w.Resource, clr))
}
func (w *Icon) Tapped(e *fyne.PointEvent) {
if w.OnTapped != nil {
w.OnTapped(e)
}
}
func (w *Icon) TappedSecondary(e *fyne.PointEvent) {
if w.OnTappedSecondary != nil {
w.OnTappedSecondary(e)
}
}
func (w *Icon) Cursor() desktop.Cursor {
if w.PointerCursor && (w.OnTapped != nil || w.OnTappedSecondary != nil) {
return desktop.PointerCursor
}
return desktop.DefaultCursor
}