slider

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package slider implements an interactive value slider widget.

Index

Constants

View Source
const (
	// DefaultWidth is the default slider length in terminal cells.
	DefaultWidth = 18
	// DefaultStep is the default increment used for keyboard changes.
	DefaultStep = 1
)

Variables

View Source
var (
	DefaultFillColor        = cell.ColorNumber(221)
	DefaultTrackColor       = cell.ColorNumber(239)
	DefaultKnobColor        = cell.ColorWhite
	DefaultFocusedKnobColor = cell.ColorCyan
)

Default colors used by the slider widget.

Functions

This section is empty.

Types

type ChangeFn

type ChangeFn func(value int) error

ChangeFn is called when the user changes the slider value.

The callback must be thread-safe because it is triggered from the keyboard and mouse event handling paths, which run in separate goroutines.

type Direction

type Direction int

Direction indicates the axis the slider is drawn on.

const (
	// OrientationHorizontal draws the slider left-to-right.
	OrientationHorizontal Direction = iota
	// OrientationVertical draws the slider bottom-to-top.
	OrientationVertical
)

func (Direction) String

func (o Direction) String() string

String implements fmt.Stringer.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options.

func AlignHorizontal

func AlignHorizontal(h align.Horizontal) Option

AlignHorizontal positions the slider horizontally inside a larger canvas.

func AlignVertical

func AlignVertical(v align.Vertical) Option

AlignVertical positions the slider vertically inside a larger canvas.

func BarStyle

func BarStyle() Option

BarStyle applies the default solid bar style.

func DotsStyle

func DotsStyle() Option

DotsStyle applies the filled and empty circular dot style.

func FillCellOpts

func FillCellOpts(cellOpts ...cell.Option) Option

FillCellOpts sets the styling used for the filled portion of the slider.

func FillRune

func FillRune(r rune) Option

FillRune sets the rune used for the filled portion of the slider.

func FocusedKnobCellOpts

func FocusedKnobCellOpts(cellOpts ...cell.Option) Option

FocusedKnobCellOpts sets the styling used for the slider knob while the widget is focused.

func Height

func Height(cells int) Option

Height sets the slider length in terminal cells.

This is an alias for Length intended for vertical sliders.

func KnobCellOpts

func KnobCellOpts(cellOpts ...cell.Option) Option

KnobCellOpts sets the styling used for the slider knob.

func KnobRune

func KnobRune(r rune) Option

KnobRune sets the rune used for the slider knob.

func Length

func Length(cells int) Option

Length sets the number of terminal cells used along the slider axis.

func Max

func Max(v int) Option

Max sets the maximum slider value.

func Min

func Min(v int) Option

Min sets the minimum slider value.

func OnChange

func OnChange(fn ChangeFn) Option

OnChange sets the slider's value-change hook.

This is the widget's canonical callback surface. Callers that need delayed or asynchronous work should build that from this hook so the widget keeps a single stable event path.

func Orientation

func Orientation(o Direction) Option

Orientation sets whether the slider is drawn horizontally or vertically.

func SegmentedBlocksStyle

func SegmentedBlocksStyle() Option

SegmentedBlocksStyle applies the dense rectangular block style.

func SegmentedDotsStyle

func SegmentedDotsStyle() Option

SegmentedDotsStyle applies the smaller dot segment style.

func SegmentedSquaresStyle

func SegmentedSquaresStyle() Option

SegmentedSquaresStyle applies the smaller square segment style.

func SegmentedStyle

func SegmentedStyle() Option

SegmentedStyle applies the thin segmented-line style.

func SquaresStyle

func SquaresStyle() Option

SquaresStyle applies the filled and empty square style.

func StarsStyle

func StarsStyle() Option

StarsStyle applies the filled and empty star style.

func Step

func Step(v int) Option

Step sets the increment used for keyboard changes.

func Style

func Style(s Preset) Option

Style applies one of the built-in visual slider styles.

func TrackCellOpts

func TrackCellOpts(cellOpts ...cell.Option) Option

TrackCellOpts sets the styling used for the unfilled portion of the slider.

func TrackRune

func TrackRune(r rune) Option

TrackRune sets the rune used for the unfilled portion of the slider.

func Value

func Value(v int) Option

Value sets the initial slider value.

func Width

func Width(cells int) Option

Width sets the slider length in terminal cells.

Width is kept for compatibility with existing horizontal sliders. For vertical sliders, Height or Length is usually clearer.

type Preset

type Preset int

Preset is a named visual preset for the slider track.

const (
	// StyleBar is the default solid filled bar with a knob.
	StyleBar Preset = iota
	// StyleSegmented draws a thin segmented line.
	StyleSegmented
	// StyleSegmentedBlocks draws dense rectangular block segments.
	StyleSegmentedBlocks
	// StyleDots draws filled and empty circular dots.
	StyleDots
	// StyleSegmentedDots draws smaller dot segments.
	StyleSegmentedDots
	// StyleSquares draws filled and empty square blocks.
	StyleSquares
	// StyleSegmentedSquares draws smaller square segments.
	StyleSegmentedSquares
	// StyleStars draws filled and empty star segments.
	StyleStars
)

func (Preset) String

func (s Preset) String() string

String implements fmt.Stringer.

type Slider

type Slider struct {
	// contains filtered or unexported fields
}

Slider lets the user select a numeric value within a fixed range.

Implements widgetapi.Widget. This object is thread-safe.

func New

func New(opts ...Option) (*Slider, error)

New returns a new Slider.

func (*Slider) Draw

func (s *Slider) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws the Slider onto the canvas. Implements widgetapi.Widget.Draw.

func (*Slider) Keyboard

func (s *Slider) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard processes keyboard events for the slider. Implements widgetapi.Widget.Keyboard.

func (*Slider) Mouse

func (s *Slider) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse processes mouse events for the slider. Implements widgetapi.Widget.Mouse.

func (*Slider) Options

func (s *Slider) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*Slider) SetValue

func (s *Slider) SetValue(v int)

SetValue replaces the current value, clamping it to the configured range.

func (*Slider) Value

func (s *Slider) Value() int

Value returns the current slider value.

Directories

Path Synopsis
Binary sliderdemo shows the functionality of a slider widget.
Binary sliderdemo shows the functionality of a slider widget.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL