Skip to content

Commit f4c171f

Browse files
committed
feat(ui): add right click to timer for play-pause, stop, next (with icons)
1 parent ba5e723 commit f4c171f

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

ui/pomodoro_widget.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ func NewPomodoroWidget(thePomodoro *pomodoro.Pomodoro) *PomodoroWidget {
4141
l.timer.OnTapped = func() {
4242
l.PlayPause()
4343
}
44+
l.timer.OnTappedSecondary = func(e *fyne.PointEvent) {
45+
playPauseItem := fyne.NewMenuItem("Play/Pause", l.PlayPause)
46+
playPauseItem.Icon = theme.MediaPlayIcon()
47+
stopItem := fyne.NewMenuItem("Stop", l.Stop)
48+
stopItem.Icon = theme.MediaStopIcon()
49+
nextItem := fyne.NewMenuItem("Next", l.Next)
50+
nextItem.Icon = theme.MediaSkipNextIcon()
51+
menu := fyne.NewMenu("", playPauseItem, stopItem, nextItem)
52+
widget.ShowPopUpMenuAtPosition(menu, fyne.CurrentApp().Driver().CanvasForObject(l.timer), e.AbsolutePosition)
53+
}
4454
l.playButton.OnTapped = func() {
4555
l.PlayPause()
4656
}

ui/tappable_text.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111

1212
type TappableText struct {
1313
widget.BaseWidget
14-
Label *canvas.Text
15-
OnTapped func()
14+
Label *canvas.Text
15+
OnTapped func()
16+
OnTappedSecondary func(*fyne.PointEvent)
1617
}
1718

1819
func NewTappableText(title string, color color.Color, tapped func()) *TappableText {
@@ -34,6 +35,12 @@ func (t *TappableText) Tapped(*fyne.PointEvent) {
3435
}
3536
}
3637

38+
func (t *TappableText) TappedSecondary(e *fyne.PointEvent) {
39+
if onTappedSecondary := t.OnTappedSecondary; onTappedSecondary != nil {
40+
onTappedSecondary(e)
41+
}
42+
}
43+
3744
func (t *TappableText) SetText(text string) {
3845
t.Label.Text = text
3946
t.Refresh()

0 commit comments

Comments
 (0)