Browse Source

feat(checkbox): Add `SetCheckedRune`

tablepad
Andreas Bieber 2 years ago
parent
commit
a6bb544c20
  1. 16
      checkbox.go
  2. 5
      styles.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 = ' '
}

5
styles.go

@ -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…
Cancel
Save