Add documentation for Slider

This commit is contained in:
Sasha Koshka 2023-09-14 17:03:19 -04:00
parent c210c07b74
commit 2251d33ac7
3 changed files with 22 additions and 6 deletions

View File

@ -52,7 +52,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
word := modifiers.Control word := modifiers.Control
sel := modifiers.Shift sel := modifiers.Shift
changed := false changed := false
switch { switch {
case key == input.KeyEnter: case key == input.KeyEnter:
this.on.enter.Broadcast() 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)) this.text, dot = text.Type(this.text, dot, rune(key))
changed = true changed = true
} }
this.Select(dot) this.Select(dot)
if changed { this.SetText(string(this.text)) } if changed { this.SetText(string(this.text)) }
} }

View File

@ -33,12 +33,12 @@ func newScrollbar (orient string) *Scrollbar {
this.Add(this.handle) this.Add(this.handle)
this.SetFocusable(true) this.SetFocusable(true)
this.CaptureDND(true) this.CaptureDND(true)
this.CaptureMouse(true) this.CaptureMouse(true)
this.CaptureScroll(true) this.CaptureScroll(true)
this.CaptureKeyboard(true) this.CaptureKeyboard(true)
this.OnKeyDown(this.handleKeyDown) this.OnKeyDown(this.handleKeyDown)
this.OnMouseDown(this.handleMouseDown) this.OnMouseDown(this.handleMouseDown)
this.OnMouseUp(this.handleMouseUp) this.OnMouseUp(this.handleMouseUp)
@ -80,6 +80,13 @@ func (this *Scrollbar) SetValue (value float64) {
// right/bottom. // right/bottom.
func (this *Scrollbar) Value () float64 { func (this *Scrollbar) Value () float64 {
// TODO // 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) { func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {

View File

@ -6,6 +6,7 @@ import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input" import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event" import "git.tebibyte.media/tomo/tomo/event"
// Slider is a control that selects a numeric value between 0 and 1.
type Slider struct { type Slider struct {
tomo.ContainerBox tomo.ContainerBox
handle *SliderHandle 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 { type SliderHandle struct {
tomo.Box tomo.Box
} }
@ -35,12 +38,12 @@ func newSlider (orient string, value float64) *Slider {
this.Add(this.handle) this.Add(this.handle)
this.SetFocusable(true) this.SetFocusable(true)
this.CaptureDND(true) this.CaptureDND(true)
this.CaptureMouse(true) this.CaptureMouse(true)
this.CaptureScroll(true) this.CaptureScroll(true)
this.CaptureKeyboard(true) this.CaptureKeyboard(true)
this.SetValue(value) this.SetValue(value)
this.OnKeyDown(this.handleKeyDown) this.OnKeyDown(this.handleKeyDown)
this.OnMouseDown(this.handleMouseDown) this.OnMouseDown(this.handleMouseDown)
@ -51,14 +54,17 @@ func newSlider (orient string, value float64) *Slider {
return this return this
} }
// NewVerticalSlider creates a new vertical slider with the specified value.
func NewVerticalSlider (value float64) *Slider { func NewVerticalSlider (value float64) *Slider {
return newSlider("vertical", value) return newSlider("vertical", value)
} }
// NewHorizontalSlider creates a new horizontal slider with the specified value.
func NewHorizontalSlider (value float64) *Slider { func NewHorizontalSlider (value float64) *Slider {
return newSlider("horizontal", value) return newSlider("horizontal", value)
} }
// SetValue sets the value of the slider between 0 and 1.
func (this *Slider) SetValue (value float64) { func (this *Slider) SetValue (value float64) {
if value < 0 { value = 0 } if value < 0 { value = 0 }
if value > 1 { value = 1 } if value > 1 { value = 1 }
@ -68,10 +74,13 @@ func (this *Slider) SetValue (value float64) {
this.on.valueChange.Broadcast() this.on.valueChange.Broadcast()
} }
// Value returns the value of the slider between 0 and 1.
func (this *Slider) Value () float64 { func (this *Slider) Value () float64 {
return this.layout.value 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 { func (this *Slider) OnValueChange (callback func ()) event.Cookie {
return this.on.valueChange.Connect(callback) return this.on.valueChange.Connect(callback)
} }