Fix #95: temporarily add tappable behavior to seekbar slider until Fyne 2.4
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user