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

@ -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
} }
@ -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)
} }