Added documentation for the sliders
This commit is contained in:
parent
d7a6193c04
commit
7f1c3ae870
@ -7,12 +7,16 @@ type Numeric interface {
|
|||||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
~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 {
|
type LerpSlider[T Numeric] struct {
|
||||||
*Slider
|
*Slider
|
||||||
min T
|
min T
|
||||||
max 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]) {
|
func NewLerpSlider[T Numeric] (min, max T, value T, vertical bool) (element *LerpSlider[T]) {
|
||||||
if min > max {
|
if min > max {
|
||||||
temp := max
|
temp := max
|
||||||
@ -28,17 +32,20 @@ func NewLerpSlider[T Numeric] (min, max T, value T, vertical bool) (element *Ler
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetValue sets the slider's value.
|
||||||
func (element *LerpSlider[T]) SetValue (value T) {
|
func (element *LerpSlider[T]) SetValue (value T) {
|
||||||
value -= element.min
|
value -= element.min
|
||||||
element.Slider.SetValue(float64(value) / float64(element.Range()))
|
element.Slider.SetValue(float64(value) / float64(element.Range()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Value returns the slider's value.
|
||||||
func (element *LerpSlider[T]) Value () (value T) {
|
func (element *LerpSlider[T]) Value () (value T) {
|
||||||
return T (
|
return T (
|
||||||
float64(element.Slider.Value()) * float64(element.Range())) +
|
float64(element.Slider.Value()) * float64(element.Range())) +
|
||||||
element.min
|
element.min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Range returns the difference between the slider's maximum and minimum values.
|
||||||
func (element *LerpSlider[T]) Range () T {
|
func (element *LerpSlider[T]) Range () T {
|
||||||
return element.max - element.min
|
return element.max - element.min
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import "git.tebibyte.media/sashakoshka/tomo/config"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
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 {
|
type Slider struct {
|
||||||
*core.Core
|
*core.Core
|
||||||
*core.FocusableCore
|
*core.FocusableCore
|
||||||
@ -27,6 +28,8 @@ type Slider struct {
|
|||||||
onRelease func ()
|
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) {
|
func NewSlider (value float64, vertical bool) (element *Slider) {
|
||||||
element = &Slider {
|
element = &Slider {
|
||||||
value: value,
|
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) { }
|
func (element *Slider) HandleKeyUp (key input.Key, modifiers input.Modifiers) { }
|
||||||
|
|
||||||
|
// Value returns the slider's value.
|
||||||
func (element *Slider) Value () (value float64) {
|
func (element *Slider) Value () (value float64) {
|
||||||
return element.value
|
return element.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetEnabled sets whether or not the slider can be interacted with.
|
||||||
func (element *Slider) SetEnabled (enabled bool) {
|
func (element *Slider) SetEnabled (enabled bool) {
|
||||||
element.focusableControl.SetEnabled(enabled)
|
element.focusableControl.SetEnabled(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetValue sets the slider's value.
|
||||||
func (element *Slider) SetValue (value float64) {
|
func (element *Slider) SetValue (value float64) {
|
||||||
if value < 0 { value = 0 }
|
if value < 0 { value = 0 }
|
||||||
if value > 1 { value = 1 }
|
if value > 1 { value = 1 }
|
||||||
@ -103,10 +109,13 @@ func (element *Slider) SetValue (value float64) {
|
|||||||
element.redo()
|
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 ()) {
|
func (element *Slider) OnSlide (callback func ()) {
|
||||||
element.onSlide = callback
|
element.onSlide = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnRelease sets a function to be called when the handle stops being dragged.
|
||||||
func (element *Slider) OnRelease (callback func ()) {
|
func (element *Slider) OnRelease (callback func ()) {
|
||||||
element.onRelease = callback
|
element.onRelease = callback
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user