-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcontext_menu.go
52 lines (43 loc) · 1.2 KB
/
context_menu.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
package main
import (
"fyne.io/fyne"
"fyne.io/fyne/widget"
)
type contextMenuButton struct {
widget.Button
menu *fyne.Menu
}
func (b *contextMenuButton) Tapped(e *fyne.PointEvent) {
widget.ShowPopUpMenuAtPosition(b.menu, fyne.CurrentApp().Driver().CanvasForObject(b), e.AbsolutePosition)
}
func newContextMenuButton(label string, icon fyne.Resource, menu *fyne.Menu) *contextMenuButton {
b := &contextMenuButton{menu: menu}
b.Text = label
b.Icon = icon
b.ExtendBaseWidget(b)
return b
}
type contextMenuLabel struct {
widget.Label
menu *fyne.Menu
tapped func()
}
func (l *contextMenuLabel) Tapped(e *fyne.PointEvent) {
if l.tapped != nil {
l.tapped()
}
}
func (l *contextMenuLabel) TappedSecondary(e *fyne.PointEvent) {
widget.ShowPopUpMenuAtPosition(l.menu, fyne.CurrentApp().Driver().CanvasForObject(l), e.AbsolutePosition)
}
func newContextMenuLabel(label string, menu *fyne.Menu) *contextMenuLabel {
l := &contextMenuLabel{menu: menu}
l.Text = label
l.ExtendBaseWidget(l)
return l
}
func newCopyableLabel(win fyne.Window, label string) (l *contextMenuLabel) {
return newContextMenuLabel(label, fyne.NewMenu("",
fyne.NewMenuItem("Copy", func() { win.Clipboard().SetContent(l.Text) }),
))
}