From 7f1c3ae87076ae213b5f3d2416d094df81411709 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 11 Feb 2023 17:04:50 -0500 Subject: [PATCH] Added documentation for the sliders --- elements/basic/lerpslider.go | 7 +++++++ elements/basic/slider.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/elements/basic/lerpslider.go b/elements/basic/lerpslider.go index 51d66a9..bc619c2 100644 --- a/elements/basic/lerpslider.go +++ b/elements/basic/lerpslider.go @@ -7,12 +7,16 @@ type Numeric interface { ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr } +// LerpSlider is a slider that has a minimum and maximum value, and who's value +// can be any numeric type. type LerpSlider[T Numeric] struct { *Slider min T max T } +// NewLerpSlider creates a new LerpSlider with a minimum and maximum value. If +// vertical is set to true, the slider will be vertical instead of horizontal. func NewLerpSlider[T Numeric] (min, max T, value T, vertical bool) (element *LerpSlider[T]) { if min > max { temp := max @@ -28,17 +32,20 @@ func NewLerpSlider[T Numeric] (min, max T, value T, vertical bool) (element *Ler return } +// SetValue sets the slider's value. func (element *LerpSlider[T]) SetValue (value T) { value -= element.min element.Slider.SetValue(float64(value) / float64(element.Range())) } +// Value returns the slider's value. func (element *LerpSlider[T]) Value () (value T) { return T ( float64(element.Slider.Value()) * float64(element.Range())) + element.min } +// Range returns the difference between the slider's maximum and minimum values. func (element *LerpSlider[T]) Range () T { return element.max - element.min } diff --git a/elements/basic/slider.go b/elements/basic/slider.go index 094d64a..322cd51 100644 --- a/elements/basic/slider.go +++ b/elements/basic/slider.go @@ -7,6 +7,7 @@ import "git.tebibyte.media/sashakoshka/tomo/config" import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/elements/core" +// Slider is a slider control with a floating point value between zero and one. type Slider struct { *core.Core *core.FocusableCore @@ -27,6 +28,8 @@ type Slider struct { onRelease func () } +// NewSlider creates a new slider with the specified value. If vertical is set +// to true, func NewSlider (value float64, vertical bool) (element *Slider) { element = &Slider { value: value, @@ -85,14 +88,17 @@ func (element *Slider) HandleKeyDown (key input.Key, modifiers input.Modifiers) func (element *Slider) HandleKeyUp (key input.Key, modifiers input.Modifiers) { } +// Value returns the slider's value. func (element *Slider) Value () (value float64) { return element.value } +// SetEnabled sets whether or not the slider can be interacted with. func (element *Slider) SetEnabled (enabled bool) { element.focusableControl.SetEnabled(enabled) } +// SetValue sets the slider's value. func (element *Slider) SetValue (value float64) { if value < 0 { value = 0 } if value > 1 { value = 1 } @@ -103,10 +109,13 @@ func (element *Slider) SetValue (value float64) { element.redo() } +// OnSlide sets a function to be called every time the slider handle changes +// position while being dragged. func (element *Slider) OnSlide (callback func ()) { element.onSlide = callback } +// OnRelease sets a function to be called when the handle stops being dragged. func (element *Slider) OnRelease (callback func ()) { element.onRelease = callback }