|
|
|
@ -127,6 +127,9 @@ type DropDown struct {
|
|
|
|
|
// The chars to show when the option's text gets shortened.
|
|
|
|
|
abbreviationChars string |
|
|
|
|
|
|
|
|
|
// The symbol to draw at the end of the field.
|
|
|
|
|
dropDownSymbol rune |
|
|
|
|
|
|
|
|
|
sync.RWMutex |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -151,6 +154,7 @@ func NewDropDown() *DropDown {
|
|
|
|
|
fieldTextColor: Styles.PrimaryTextColor, |
|
|
|
|
fieldTextColorFocused: Styles.PrimaryTextColor, |
|
|
|
|
prefixTextColor: Styles.ContrastSecondaryTextColor, |
|
|
|
|
dropDownSymbol: Styles.DropDownSymbol, |
|
|
|
|
abbreviationChars: Styles.DropDownAbbreviationChars, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -159,6 +163,15 @@ func NewDropDown() *DropDown {
|
|
|
|
|
return d |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SetDropDownSymbolRune sets the rune to be drawn at the end of the dropdown field
|
|
|
|
|
// to indicate that this field is a dropdown.
|
|
|
|
|
func (d *DropDown) SetDropDownSymbolRune(symbol rune) *DropDown { |
|
|
|
|
d.Lock() |
|
|
|
|
defer d.Unlock() |
|
|
|
|
d.dropDownSymbol = symbol |
|
|
|
|
return d |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SetCurrentOption sets the index of the currently selected option. This may
|
|
|
|
|
// be a negative value to indicate that no option is currently selected. Calling
|
|
|
|
|
// this function will also trigger the "selected" callback (if there is one).
|
|
|
|
@ -398,6 +411,7 @@ func (d *DropDown) getFieldWidth() int {
|
|
|
|
|
} |
|
|
|
|
fieldWidth += len(d.optionPrefix) + len(d.optionSuffix) |
|
|
|
|
fieldWidth += len(d.currentOptionPrefix) + len(d.currentOptionSuffix) |
|
|
|
|
fieldWidth += 3 // space + dropDownSymbol + space
|
|
|
|
|
return fieldWidth |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -589,6 +603,9 @@ func (d *DropDown) Draw(screen tcell.Screen) {
|
|
|
|
|
Print(screen, text, x, y, fieldWidth, AlignLeft, color) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Draw drop down symbol
|
|
|
|
|
screen.SetContent(x+fieldWidth-2, y, d.dropDownSymbol, nil, new(tcell.Style).Foreground(fieldTextColor).Background(fieldBackgroundColor)) |
|
|
|
|
|
|
|
|
|
// Draw options list.
|
|
|
|
|
if hasFocus && d.open { |
|
|
|
|
// We prefer to drop down but if there is no space, maybe drop up?
|
|
|
|
|