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