forked from tslocum/cview
feat(checkbox): Add `SetCheckedRune`
This commit is contained in:
parent
7678d84c66
commit
a6bb544c20
16
checkbox.go
16
checkbox.go
|
@ -46,6 +46,9 @@ type CheckBox struct {
|
|||
// this form item.
|
||||
finished func(tcell.Key)
|
||||
|
||||
// The rune to show when the checkbox is checked
|
||||
checkedRune rune
|
||||
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
|
@ -56,6 +59,7 @@ func NewCheckBox() *CheckBox {
|
|||
labelColor: Styles.SecondaryTextColor,
|
||||
fieldBackgroundColor: Styles.ContrastBackgroundColor,
|
||||
fieldTextColor: Styles.PrimaryTextColor,
|
||||
checkedRune: Styles.CheckBoxCheckedRune,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,6 +72,15 @@ func (c *CheckBox) SetChecked(checked bool) *CheckBox {
|
|||
return c
|
||||
}
|
||||
|
||||
// SetCheckedRune sets the rune to show when the checkbox is checked.
|
||||
func (c *CheckBox) SetCheckedRune(rune rune) *CheckBox {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
c.checkedRune = rune
|
||||
return c
|
||||
}
|
||||
|
||||
// IsChecked returns whether or not the box is checked.
|
||||
func (c *CheckBox) IsChecked() bool {
|
||||
c.RLock()
|
||||
|
@ -239,7 +252,8 @@ func (c *CheckBox) Draw(screen tcell.Screen) {
|
|||
if c.focus.HasFocus() {
|
||||
fieldStyle = fieldStyle.Background(c.fieldTextColor).Foreground(c.fieldBackgroundColor)
|
||||
}
|
||||
checkedRune := 'X'
|
||||
|
||||
checkedRune := c.checkedRune
|
||||
if !c.checked {
|
||||
checkedRune = ' '
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ type Theme struct {
|
|||
ContextMenuPaddingBottom int // Bottom padding.
|
||||
ContextMenuPaddingLeft int // Left padding.
|
||||
ContextMenuPaddingRight int // Right padding.
|
||||
|
||||
// Check box
|
||||
CheckBoxCheckedRune rune
|
||||
}
|
||||
|
||||
// Styles defines the appearance of an application. The default is for a black
|
||||
|
@ -55,4 +58,6 @@ var Styles = Theme{
|
|||
ContextMenuPaddingBottom: 0,
|
||||
ContextMenuPaddingLeft: 1,
|
||||
ContextMenuPaddingRight: 1,
|
||||
|
||||
CheckBoxCheckedRune: 'X',
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue