Select Slider
SelectSlider create a slider over a list of discrete items and return the index of the one it sits on.
API
Interface
func SelectSlider(c *tgframe.Container, label string, items []string,
conf ...*SelectSliderConf) int
Parameters
cis Parent container.labelis the label of the slider.itemsis the list of options, drawn as marks along the track.confis an optional configuration, at most one.- Return the index of the item the slider sits on, 0-indexed as Select's is.
The handle is always on an item, so unlike Select there is no "nothing
selected" state and nothing to check: the index is the one the app user left it
at, else Default.
// SelectSliderConf is the configuration for the SelectSlider component.
type SelectSliderConf struct {
tgframe.Base // ID
// Default is the index of the item the slider starts on. Defaults to 0.
Default int
}
An empty items, or a Default outside it, is a mistake in the call rather
than a value to correct, and panics.
Like Slider, the index is sent to Go when the handle is released rather than while it is being dragged.
Example
sizes := []string{"S", "M", "L"}
selIdx := tgcomp.SelectSlider(p.Main, "SelectSlider", sizes)
tgcomp.Text(p.Main, "Value: "+sizes[selIdx],
&tgcomp.TextConf{ID: "select_slider_result"})
Use this over Select when the options are ordered — sizes, tiers, buckets — so that their order is part of what the control shows. For an unordered list, a dropdown reads better.
