Slider can now be controlled by scrolling
If ya nasty
This commit is contained in:
parent
6fad52b335
commit
f025ec3d8a
13
slider.go
13
slider.go
@ -13,6 +13,7 @@ type Slider struct {
|
|||||||
layout sliderLayout
|
layout sliderLayout
|
||||||
dragging bool
|
dragging bool
|
||||||
dragOffset image.Point
|
dragOffset image.Point
|
||||||
|
step float64
|
||||||
|
|
||||||
on struct {
|
on struct {
|
||||||
slide event.FuncBroadcaster
|
slide event.FuncBroadcaster
|
||||||
@ -34,6 +35,7 @@ func newSlider (orient string, value float64) *Slider {
|
|||||||
layout: sliderLayout {
|
layout: sliderLayout {
|
||||||
vertical: orient == "vertical",
|
vertical: orient == "vertical",
|
||||||
},
|
},
|
||||||
|
step: 0.05,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Add(this.handle)
|
this.Add(this.handle)
|
||||||
@ -49,6 +51,7 @@ func newSlider (orient string, value float64) *Slider {
|
|||||||
this.OnMouseDown(this.handleMouseDown)
|
this.OnMouseDown(this.handleMouseDown)
|
||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnMouseUp(this.handleMouseUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
|
this.OnScroll(this.handleScroll)
|
||||||
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
|
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
|
||||||
theme.Apply(this, theme.R("objects", "Slider", orient))
|
theme.Apply(this, theme.R("objects", "Slider", orient))
|
||||||
return this
|
return this
|
||||||
@ -149,10 +152,10 @@ func (this *Slider) handleMouseDown (button input.Button) {
|
|||||||
}
|
}
|
||||||
case input.ButtonRight:
|
case input.ButtonRight:
|
||||||
if above {
|
if above {
|
||||||
this.SetValue(this.Value() - 0.05)
|
this.SetValue(this.Value() - this.step)
|
||||||
this.on.slide.Broadcast()
|
this.on.slide.Broadcast()
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() + 0.05)
|
this.SetValue(this.Value() + this.step)
|
||||||
this.on.slide.Broadcast()
|
this.on.slide.Broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,6 +171,12 @@ func (this *Slider) handleMouseMove () {
|
|||||||
this.drag()
|
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 () {
|
func (this *Slider) drag () {
|
||||||
pointer := this.MousePosition().Sub(this.dragOffset)
|
pointer := this.MousePosition().Sub(this.dragOffset)
|
||||||
gutter := this.InnerBounds()
|
gutter := this.InnerBounds()
|
||||||
|
Loading…
Reference in New Issue
Block a user