diff --git a/checkbox.go b/checkbox.go index 980e65b..19170e1 100644 --- a/checkbox.go +++ b/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 = ' ' } diff --git a/styles.go b/styles.go index 4dbe436..e9c0ef2 100644 --- a/styles.go +++ b/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', }