From a9cec173ddcd0999cfbe7f61ca15c01bd3c1cbce Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Thu, 27 Apr 2023 09:21:07 -0700 Subject: [PATCH] Fix #95: temporarily add tappable behavior to seekbar slider until Fyne 2.4 --- CHANGELOG.md | 1 + ui/widgets/playercontrols.go | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e690fff..aac7c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - [#145](https://github.com/dweymouth/supersonic/issues/145) Add rating column to tracklist with 5-star rating widget - [b017995](https://github.com/dweymouth/supersonic/commit/b01799550ded0c6a8f33913827df23818f9a7353) Add Ctrl+W (Cmd+W on Mac) shortcut to close to tray if enabled +- [#95](https://github.com/dweymouth/supersonic/issues/95) Enable click-to-seek behavior in seek bar ### Fixed - [#148](https://github.com/dweymouth/supersonic/issues/148) Fix potential crash when searching for albums diff --git a/ui/widgets/playercontrols.go b/ui/widgets/playercontrols.go index ed9a90b..70970a4 100644 --- a/ui/widgets/playercontrols.go +++ b/ui/widgets/playercontrols.go @@ -168,3 +168,49 @@ func (pc *PlayerControls) UpdatePlayTime(curTime, totalTime float64) { func (p *PlayerControls) CreateRenderer() fyne.WidgetRenderer { return widget.NewSimpleRenderer(p.container) } + +// This code will be OBSOLETE in Fyne 2.4 +// which will natively add Tappable behavior to slider +// Tapped is called when a pointer tapped event is captured. +// +// Since: 2.4 +func (t *TrackPosSlider) Tapped(e *fyne.PointEvent) { + ratio := t.getRatio(e) + val := t.Min + ratio*(t.Max-t.Min) + t.isDragging = true + t.SetValue(val) + t.lastDraggedValue = val + t.isDragging = false + t.DragEnd() +} + +func (t *TrackPosSlider) endOffset() float32 { + return (theme.IconInlineSize()-4)/2 + theme.InnerPadding() - 1.5 // align with radio icons +} + +func (t *TrackPosSlider) getRatio(e *fyne.PointEvent) float64 { + pad := t.endOffset() + + x := e.Position.X + y := e.Position.Y + + switch t.Orientation { + case widget.Vertical: + if y > t.Size().Height-pad { + return 0.0 + } else if y < pad { + return 1.0 + } else { + return 1 - float64(y-pad)/float64(t.Size().Height-pad*2) + } + case widget.Horizontal: + if x > t.Size().Width-pad { + return 1.0 + } else if x < pad { + return 0.0 + } else { + return float64(x-pad) / float64(t.Size().Width-pad*2) + } + } + return 0.0 +}