combine TappableIcon and TappableImage in tappablewrappers.go
This commit is contained in:
@@ -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"
|
"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 {
|
type TappableImage struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
canvas.Image
|
canvas.Image
|
||||||
Reference in New Issue
Block a user