diff --git a/slider.go b/slider.go index 347f5fa..9b2cac9 100644 --- a/slider.go +++ b/slider.go @@ -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()