Documentation
¶
Overview ¶
Package radio implements an interactive radio button group widget.
Index ¶
- Constants
- Variables
- type ChangeFn
- type IndicatorSet
- type Item
- type Option
- type Radio
- func (r *Radio) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error
- func (r *Radio) ItemText(index int) string
- func (r *Radio) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error
- func (r *Radio) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error
- func (r *Radio) Options() widgetapi.Options
- func (r *Radio) SelectedIndex() int
- func (r *Radio) SelectedText() string
- func (r *Radio) SetSelected(index int) error
- func (r *Radio) Text() string
Constants ¶
const ( // DefaultSelectedRune is the default indicator rune for the selected item. DefaultSelectedRune = '◉' // DefaultUnselectedRune is the default indicator rune for an unselected item. DefaultUnselectedRune = '○' // DefaultGap is the default number of cells between radio items. DefaultGap = 3 // DefaultIndicatorGap is the default number of cells between indicator and label. DefaultIndicatorGap = 1 )
Variables ¶
var ( DefaultCellOpts = []cell.Option{cell.FgColor(cell.ColorWhite)} DefaultSelectedCellOpts = []cell.Option{cell.FgColor(cell.ColorCyan)} IndicatorSets = struct { Circle IndicatorSet Square IndicatorSet Diamond IndicatorSet Target IndicatorSet }{ Circle: IndicatorSet{Selected: "◉", Unselected: "○"}, Square: IndicatorSet{Selected: "■", Unselected: "□"}, Diamond: IndicatorSet{Selected: "◆", Unselected: "◇"}, Target: IndicatorSet{Selected: "◎", Unselected: "·"}, } )
Default styling used by radio items when the caller doesn't provide item specific values.
Functions ¶
This section is empty.
Types ¶
type ChangeFn ¶
ChangeFn is called when the user selects a radio option.
The callback must be thread-safe because it is triggered from the keyboard and mouse event handling paths, which run in separate goroutines.
type IndicatorSet ¶
IndicatorSet defines the UTF-8 strings used to render selected and unselected radio indicators.
type Item ¶
type Item struct {
Label string
SelectedText string
UnselectedText string
SelectedRune rune
UnselectedRune rune
CellOpts []cell.Option
SelectedCellOpts []cell.Option
}
Item represents one selectable radio option.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options.
func IndicatorGap ¶
IndicatorGap sets the number of blank cells between the indicator and label.
func Indicators ¶
Indicators sets the default UTF-8 strings used for radio indicators.
func OnChange ¶
OnChange sets the radio widget's selection 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 UseIndicatorSet ¶
func UseIndicatorSet(set IndicatorSet) Option
UseIndicatorSet sets the default indicators from a reusable group.
type Radio ¶
type Radio struct {
// contains filtered or unexported fields
}
Radio lets the user choose exactly one item from a fixed list of options.
Implements widgetapi.Widget. This object is thread-safe.
func (*Radio) Keyboard ¶
Keyboard processes keyboard events for the radio group. Implements widgetapi.Widget.Keyboard.
func (*Radio) Mouse ¶
Mouse processes mouse events for the radio group. Implements widgetapi.Widget.Mouse.
func (*Radio) SelectedIndex ¶
SelectedIndex returns the current selected item index.
func (*Radio) SelectedText ¶
SelectedText returns the current selected item label.
func (*Radio) SetSelected ¶
SetSelected replaces the current selected item.