Add documentation for Slider
This commit is contained in:
parent
c210c07b74
commit
2251d33ac7
4
input.go
4
input.go
@ -52,7 +52,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
|
||||
word := modifiers.Control
|
||||
sel := modifiers.Shift
|
||||
changed := false
|
||||
|
||||
|
||||
switch {
|
||||
case key == input.KeyEnter:
|
||||
this.on.enter.Broadcast()
|
||||
@ -87,7 +87,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
|
||||
this.text, dot = text.Type(this.text, dot, rune(key))
|
||||
changed = true
|
||||
}
|
||||
|
||||
|
||||
this.Select(dot)
|
||||
if changed { this.SetText(string(this.text)) }
|
||||
}
|
||||
|
11
scrollbar.go
11
scrollbar.go
@ -33,12 +33,12 @@ func newScrollbar (orient string) *Scrollbar {
|
||||
|
||||
this.Add(this.handle)
|
||||
this.SetFocusable(true)
|
||||
|
||||
|
||||
this.CaptureDND(true)
|
||||
this.CaptureMouse(true)
|
||||
this.CaptureScroll(true)
|
||||
this.CaptureKeyboard(true)
|
||||
|
||||
|
||||
this.OnKeyDown(this.handleKeyDown)
|
||||
this.OnMouseDown(this.handleMouseDown)
|
||||
this.OnMouseUp(this.handleMouseUp)
|
||||
@ -80,6 +80,13 @@ func (this *Scrollbar) SetValue (value float64) {
|
||||
// right/bottom.
|
||||
func (this *Scrollbar) Value () float64 {
|
||||
// TODO
|
||||
return 0
|
||||
}
|
||||
|
||||
// OnValueChange specifies a function to be called when the position of the
|
||||
// scrollbar changes.
|
||||
func (this *Slider) OnValueChange (callback func ()) event.Cookie {
|
||||
return this.on.valueChange.Connect(callback)
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {
|
||||
|
13
slider.go
13
slider.go
@ -6,6 +6,7 @@ import "git.tebibyte.media/tomo/tomo/theme"
|
||||
import "git.tebibyte.media/tomo/tomo/input"
|
||||
import "git.tebibyte.media/tomo/tomo/event"
|
||||
|
||||
// Slider is a control that selects a numeric value between 0 and 1.
|
||||
type Slider struct {
|
||||
tomo.ContainerBox
|
||||
handle *SliderHandle
|
||||
@ -18,6 +19,8 @@ type Slider struct {
|
||||
}
|
||||
}
|
||||
|
||||
// SliderHandle is a simple object that serves as a handle for sliders and
|
||||
// scrollbars. It is completely inert.
|
||||
type SliderHandle struct {
|
||||
tomo.Box
|
||||
}
|
||||
@ -35,12 +38,12 @@ func newSlider (orient string, value float64) *Slider {
|
||||
|
||||
this.Add(this.handle)
|
||||
this.SetFocusable(true)
|
||||
|
||||
|
||||
this.CaptureDND(true)
|
||||
this.CaptureMouse(true)
|
||||
this.CaptureScroll(true)
|
||||
this.CaptureKeyboard(true)
|
||||
|
||||
|
||||
this.SetValue(value)
|
||||
this.OnKeyDown(this.handleKeyDown)
|
||||
this.OnMouseDown(this.handleMouseDown)
|
||||
@ -51,14 +54,17 @@ func newSlider (orient string, value float64) *Slider {
|
||||
return this
|
||||
}
|
||||
|
||||
// NewVerticalSlider creates a new vertical slider with the specified value.
|
||||
func NewVerticalSlider (value float64) *Slider {
|
||||
return newSlider("vertical", value)
|
||||
}
|
||||
|
||||
// NewHorizontalSlider creates a new horizontal slider with the specified value.
|
||||
func NewHorizontalSlider (value float64) *Slider {
|
||||
return newSlider("horizontal", value)
|
||||
}
|
||||
|
||||
// SetValue sets the value of the slider between 0 and 1.
|
||||
func (this *Slider) SetValue (value float64) {
|
||||
if value < 0 { value = 0 }
|
||||
if value > 1 { value = 1 }
|
||||
@ -68,10 +74,13 @@ func (this *Slider) SetValue (value float64) {
|
||||
this.on.valueChange.Broadcast()
|
||||
}
|
||||
|
||||
// Value returns the value of the slider between 0 and 1.
|
||||
func (this *Slider) Value () float64 {
|
||||
return this.layout.value
|
||||
}
|
||||
|
||||
// OnValueChange specifies a function to be called when the slider's value
|
||||
// changes.
|
||||
func (this *Slider) OnValueChange (callback func ()) event.Cookie {
|
||||
return this.on.valueChange.Connect(callback)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user