From 78c3872f47c73376c6e53a628709745abc5a85df Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Tue, 14 Mar 2023 10:40:48 -0700 Subject: [PATCH] combine TappableIcon and TappableImage in tappablewrappers.go --- ui/widgets/tappableicon.go | 34 ------------------- .../{tappableimage.go => tappablewrappers.go} | 29 ++++++++++++++++ 2 files changed, 29 insertions(+), 34 deletions(-) delete mode 100644 ui/widgets/tappableicon.go rename ui/widgets/{tappableimage.go => tappablewrappers.go} (59%) diff --git a/ui/widgets/tappableicon.go b/ui/widgets/tappableicon.go deleted file mode 100644 index 4ca70f3..0000000 --- a/ui/widgets/tappableicon.go +++ /dev/null @@ -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 -} diff --git a/ui/widgets/tappableimage.go b/ui/widgets/tappablewrappers.go similarity index 59% rename from ui/widgets/tappableimage.go rename to ui/widgets/tappablewrappers.go index d17d173..218449a 100644 --- a/ui/widgets/tappableimage.go +++ b/ui/widgets/tappablewrappers.go @@ -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