remove obsolete slider tap handling and customize some behavior

This commit is contained in:
Drew Weymouth
2023-11-02 18:46:06 -07:00
parent afcb47f61d
commit d99563571a
2 changed files with 45 additions and 99 deletions
+5 -43
View File
@@ -104,6 +104,11 @@ func NewVolumeSlider(width float32) *volumeSlider {
return v
}
func (v *volumeSlider) Tapped(e *fyne.PointEvent) {
v.Slider.Tapped(e)
fyne.CurrentApp().Driver().CanvasForObject(v).Unfocus()
}
func (v *volumeSlider) MinSize() fyne.Size {
h := v.Slider.MinSize().Height
return fyne.NewSize(v.Width, h)
@@ -113,49 +118,6 @@ func (v *volumeSlider) Scrolled(e *fyne.ScrollEvent) {
v.SetValue(v.Value + float64(0.5*e.Scrolled.DY))
}
// 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 (v *volumeSlider) Tapped(e *fyne.PointEvent) {
ratio := v.getRatio(e)
val := v.Min + ratio*(v.Max-v.Min)
v.SetValue(val)
v.DragEnd()
}
func (v *volumeSlider) endOffset() float32 {
return (theme.IconInlineSize()-4)/2 + theme.InnerPadding() - 1.5 // align with radio icons
}
func (v *volumeSlider) getRatio(e *fyne.PointEvent) float64 {
pad := v.endOffset()
x := e.Position.X
y := e.Position.Y
switch v.Orientation {
case widget.Vertical:
if y > v.Size().Height-pad {
return 0.0
} else if y < pad {
return 1.0
} else {
return 1 - float64(y-pad)/float64(v.Size().Height-pad*2)
}
case widget.Horizontal:
if x > v.Size().Width-pad {
return 1.0
} else if x < pad {
return 0.0
} else {
return float64(x-pad) / float64(v.Size().Width-pad*2)
}
}
return 0.0
}
type VolumeControl struct {
widget.BaseWidget