combine TappableIcon and TappableImage in tappablewrappers.go

This commit is contained in:
Drew Weymouth
2023-03-14 10:40:48 -07:00
parent f6efe6c9c9
commit 78c3872f47
2 changed files with 29 additions and 34 deletions
-34
View File
@@ -1,34 +0,0 @@
package widgets
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/widget"
)
type TappableIcon struct {
widget.Icon
OnTapped func()
}
func NewTappbaleIcon(res fyne.Resource) *TappableIcon {
icon := &TappableIcon{}
icon.ExtendBaseWidget(icon)
icon.SetResource(res)
return icon
}
func (t *TappableIcon) Tapped(_ *fyne.PointEvent) {
if t.OnTapped != nil {
t.OnTapped()
}
}
func (t *TappableIcon) TappedSecondary(_ *fyne.PointEvent) {
}
func (t *TappableIcon) Cursor() desktop.Cursor {
return desktop.PointerCursor
}
@@ -7,6 +7,35 @@ import (
"fyne.io/fyne/v2/widget"
)
// TappableIcon is a tappable wrapper of widget.Icon
type TappableIcon struct {
widget.Icon
OnTapped func()
}
func NewTappbaleIcon(res fyne.Resource) *TappableIcon {
icon := &TappableIcon{}
icon.ExtendBaseWidget(icon)
icon.SetResource(res)
return icon
}
func (t *TappableIcon) Tapped(_ *fyne.PointEvent) {
if t.OnTapped != nil {
t.OnTapped()
}
}
func (t *TappableIcon) TappedSecondary(_ *fyne.PointEvent) {
}
func (t *TappableIcon) Cursor() desktop.Cursor {
return desktop.PointerCursor
}
// TappableImage is a tappable wrapper of canvas.Image
type TappableImage struct {
widget.BaseWidget
canvas.Image