Fixed vertical slider
This commit is contained in:
parent
98bf754282
commit
05b6490095
23
slider.go
23
slider.go
@ -14,7 +14,7 @@ type Slider struct {
|
||||
layout sliderLayout
|
||||
dragging bool
|
||||
dragOffset image.Point
|
||||
|
||||
|
||||
on struct {
|
||||
valueChange event.FuncBroadcaster
|
||||
}
|
||||
@ -34,7 +34,7 @@ func newSlider (orient string, value float64) *Slider {
|
||||
vertical: orient == "vertical",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
this.Add(this.handle)
|
||||
this.SetFocusable(true)
|
||||
this.SetPropagateEvents(false)
|
||||
@ -74,18 +74,24 @@ func (this *Slider) OnValueChange (callback func ()) event.Cookie {
|
||||
}
|
||||
|
||||
func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
||||
var increment float64; if this.layout.vertical {
|
||||
increment = -0.05
|
||||
} else {
|
||||
increment = 0.05
|
||||
}
|
||||
|
||||
switch key {
|
||||
case input.KeyUp, input.KeyLeft:
|
||||
if this.Modifiers().Alt {
|
||||
this.SetValue(0)
|
||||
} else {
|
||||
this.SetValue(this.Value() - 0.05)
|
||||
this.SetValue(this.Value() - increment)
|
||||
}
|
||||
case input.KeyDown, input.KeyRight:
|
||||
if this.Modifiers().Alt {
|
||||
this.SetValue(1)
|
||||
} else {
|
||||
this.SetValue(this.Value() + 0.05)
|
||||
this.SetValue(this.Value() + increment)
|
||||
}
|
||||
case input.KeyHome:
|
||||
this.SetValue(0)
|
||||
@ -98,7 +104,7 @@ func (this *Slider) handleMouseDown (button input.Button) {
|
||||
pointer := this.MousePosition()
|
||||
handle := this.handle.Bounds()
|
||||
var above, within bool
|
||||
|
||||
|
||||
if pointer.In(handle) {
|
||||
within = true
|
||||
} else if this.layout.vertical {
|
||||
@ -106,7 +112,7 @@ func (this *Slider) handleMouseDown (button input.Button) {
|
||||
} else {
|
||||
above = pointer.X < handle.Min.X
|
||||
}
|
||||
|
||||
|
||||
switch button {
|
||||
case input.ButtonLeft:
|
||||
if within {
|
||||
@ -152,6 +158,7 @@ func (this *Slider) drag () {
|
||||
|
||||
if this.layout.vertical {
|
||||
this.SetValue (
|
||||
1 -
|
||||
float64(pointer.Y) /
|
||||
float64(gutter.Dy() - handle.Dy()))
|
||||
} else {
|
||||
@ -185,10 +192,10 @@ func (this sliderLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
if len(boxes) != 1 { return }
|
||||
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
|
||||
gutter := hints.Bounds
|
||||
|
||||
|
||||
if this.vertical {
|
||||
height := gutter.Dy() - handle.Dy()
|
||||
offset := int(float64(height) * this.value)
|
||||
offset := int(float64(height) * (1 - this.value))
|
||||
handle.Max.X = gutter.Dx()
|
||||
boxes[0].SetBounds (
|
||||
handle.
|
||||
|
Loading…
Reference in New Issue
Block a user