-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmisc_tooltipable.go
69 lines (61 loc) · 1.5 KB
/
misc_tooltipable.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
package wx
import (
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
type ToolTipable struct {
ToolTip fyne.CanvasObject
parent fyne.Widget
timer *time.Timer
tooltip *widget.PopUp
pos fyne.Position
}
func (tt *ToolTipable) SetToolTip(title, text string, icon fyne.Resource) {
if title == "" && text == "" {
tt.ToolTip = nil
return
}
if title == "" || text == "" {
tt.ToolTip = widget.NewLabel(title + text)
} else {
if icon != nil {
tt.ToolTip = container.NewVBox(
container.NewHBox(
&widget.Label{Text: title, TextStyle: fyne.TextStyle{Bold: true}},
layout.NewSpacer(), widget.NewIcon(icon),
),
widget.NewLabel(text),
)
} else {
tt.ToolTip = container.NewVBox(
&widget.Label{Text: title, TextStyle: fyne.TextStyle{Bold: true}},
widget.NewLabel(text),
)
}
}
}
func (tt *ToolTipable) MouseIn(me *desktop.MouseEvent) {
if p, ok := tt.parent.(fyne.Disableable); ok && p.Disabled() {
return
}
if tt.ToolTip != nil && tt.timer == nil {
tt.pos = me.AbsolutePosition
tt.timer = time.AfterFunc(1500*time.Millisecond, func() {
tt.tooltip = widget.NewPopUp(tt.ToolTip, fyne.CurrentApp().Driver().CanvasForObject(tt.parent))
tt.tooltip.ShowAtPosition(tt.pos)
})
}
}
func (tt *ToolTipable) MouseMoved(me *desktop.MouseEvent) {
tt.pos = me.AbsolutePosition
}
func (tt *ToolTipable) MouseOut() {
if tt.timer != nil {
tt.timer.Stop()
tt.timer = nil
}
}