Slider can now be controlled by scrolling

If ya nasty
This commit is contained in:
Sasha Koshka 2024-05-17 01:22:47 -04:00
parent 6fad52b335
commit f025ec3d8a

View File

@ -13,6 +13,7 @@ type Slider struct {
layout sliderLayout
dragging bool
dragOffset image.Point
step float64
on struct {
slide event.FuncBroadcaster
@ -34,6 +35,7 @@ func newSlider (orient string, value float64) *Slider {
layout: sliderLayout {
vertical: orient == "vertical",
},
step: 0.05,
}
this.Add(this.handle)
@ -49,6 +51,7 @@ func newSlider (orient string, value float64) *Slider {
this.OnMouseDown(this.handleMouseDown)
this.OnMouseUp(this.handleMouseUp)
this.OnMouseMove(this.handleMouseMove)
this.OnScroll(this.handleScroll)
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
theme.Apply(this, theme.R("objects", "Slider", orient))
return this
@ -149,10 +152,10 @@ func (this *Slider) handleMouseDown (button input.Button) {
}
case input.ButtonRight:
if above {
this.SetValue(this.Value() - 0.05)
this.SetValue(this.Value() - this.step)
this.on.slide.Broadcast()
} else {
this.SetValue(this.Value() + 0.05)
this.SetValue(this.Value() + this.step)
this.on.slide.Broadcast()
}
}
@ -168,6 +171,12 @@ func (this *Slider) handleMouseMove () {
this.drag()
}
func (this *Slider) handleScroll (x, y float64) {
delta := (x + y) * 0.005
this.SetValue(this.Value() + delta)
this.on.slide.Broadcast()
}
func (this *Slider) drag () {
pointer := this.MousePosition().Sub(this.dragOffset)
gutter := this.InnerBounds()