Documentation
¶
Overview ¶
Package dropdown implements an interactive dropdown selection widget.
Index ¶
- Variables
- func IntRange(start, end, step int, format string) []string
- type BorderRunes
- type Dropdown
- func (d *Dropdown) CanvasSize(maxHeight int) image.Point
- func (d *Dropdown) Close()
- func (d *Dropdown) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error
- func (d *Dropdown) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error
- func (d *Dropdown) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error
- func (d *Dropdown) Open()
- func (d *Dropdown) Options() widgetapi.Options
- func (d *Dropdown) SelectedIndex() int
- func (d *Dropdown) SelectedText() string
- func (d *Dropdown) SetItems(items []string) error
- func (d *Dropdown) SetSelected(index int) error
- func (d *Dropdown) TriggerText() string
- func (d *Dropdown) TriggerTextFor(label string) string
- type GlyphProfile
- type Option
- func Arrows(closed, open rune) Option
- func BorderCellOpts(cellOpts ...cell.Option) Option
- func BorderGlyphs(runes BorderRunes) Option
- func CellOpts(cellOpts ...cell.Option) Option
- func FocusedCellOpts(cellOpts ...cell.Option) Option
- func GlyphSet(set GlyphProfile) Option
- func OnSelect(fn SelectFn) Option
- func RowPrefixes(selected, unselected string) Option
- func Selected(index int) Option
- func SelectedCellOpts(cellOpts ...cell.Option) Option
- func Width(cells int) Option
- type SelectFn
Constants ¶
This section is empty.
Variables ¶
var ( DefaultTextColor = cell.ColorWhite DefaultFocusedTextColor = cell.ColorCyan DefaultSelectedTextColor = cell.ColorWhite DefaultSelectedFillColor = cell.ColorNumber(60) DefaultBorderColor = cell.ColorCyan GlyphProfiles = struct { Classic GlyphProfile Minimal GlyphProfile }{ Classic: GlyphProfile{ ClosedArrow: '▼', OpenArrow: '▲', SelectedPrefix: ">", UnselectedPrefix: " ", Border: BorderRunes{ TopLeft: '┌', TopRight: '┐', BottomLeft: '└', BottomRight: '┘', Horizontal: '─', Vertical: '│', }, }, Minimal: GlyphProfile{ ClosedArrow: '▾', OpenArrow: '▴', SelectedPrefix: "›", UnselectedPrefix: " ", Border: BorderRunes{ TopLeft: '╭', TopRight: '╮', BottomLeft: '╰', BottomRight: '╯', Horizontal: '─', Vertical: '│', }, }, } )
Default colors used by the dropdown widget.
Functions ¶
Types ¶
type BorderRunes ¶
type BorderRunes struct {
TopLeft rune
TopRight rune
BottomLeft rune
BottomRight rune
Horizontal rune
Vertical rune
}
BorderRunes defines the UTF-8 runes used to draw the open dropdown box.
type Dropdown ¶
type Dropdown struct {
// contains filtered or unexported fields
}
Dropdown allows users to select one value from a fixed list of items.
When focused, the widget can be opened with Enter, Space, or the arrow keys. Once open, Up and Down move the active row, Enter commits the selection, and Esc closes the list.
Implements widgetapi.Widget. This object is thread-safe.
func (*Dropdown) CanvasSize ¶
CanvasSize returns the size needed to draw the dropdown in its current state within the provided height budget.
When closed, the dropdown only needs a single row for the trigger. When open, the returned height includes the trigger, visible rows, and border.
func (*Dropdown) Keyboard ¶
Keyboard processes keyboard events for the dropdown. Implements widgetapi.Widget.Keyboard.
func (*Dropdown) Mouse ¶
Mouse processes mouse events for the dropdown. Implements widgetapi.Widget.Mouse.
func (*Dropdown) SelectedIndex ¶
SelectedIndex returns the currently selected item index.
func (*Dropdown) SelectedText ¶
SelectedText returns the currently selected item label.
func (*Dropdown) SetItems ¶
SetItems replaces the dropdown item list.
If the current selection no longer fits into the updated item set, the selection resets to the first item.
func (*Dropdown) SetSelected ¶
SetSelected replaces the current selection programmatically.
func (*Dropdown) TriggerText ¶
TriggerText returns the dropdown's current trigger line text.
func (*Dropdown) TriggerTextFor ¶
TriggerTextFor returns the trigger text for the provided label using the dropdown's configured closed-arrow glyphs.
type GlyphProfile ¶
type GlyphProfile struct {
ClosedArrow rune
OpenArrow rune
SelectedPrefix string
UnselectedPrefix string
Border BorderRunes
}
GlyphProfile groups reusable dropdown glyph choices.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options.
func BorderCellOpts ¶
BorderCellOpts sets the styling used for the open dropdown box border.
func BorderGlyphs ¶
func BorderGlyphs(runes BorderRunes) Option
BorderGlyphs sets the runes used for the open dropdown box border.
func CellOpts ¶
CellOpts sets the default cell styling used for the trigger and unselected list rows.
func FocusedCellOpts ¶
FocusedCellOpts sets the styling used for the closed trigger while the widget's container is focused.
func GlyphSet ¶
func GlyphSet(set GlyphProfile) Option
GlyphSet sets the dropdown glyphs from a reusable group.
func OnSelect ¶
OnSelect sets the dropdown'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 RowPrefixes ¶
RowPrefixes sets the leading text used for selected and unselected rows.
func SelectedCellOpts ¶
SelectedCellOpts sets the styling used for the active row while the list is open.
Directories
¶
| Path | Synopsis |
|---|---|
|
Binary dropdowndemo shows the functionality of a dropdown widget.
|
Binary dropdowndemo shows the functionality of a dropdown widget. |