Some Updates
This commit is contained in:
@@ -64,15 +64,11 @@ func (w *Checkbox) Init(id string, style tcell.Style) {
|
||||
w.stateRunes = []rune{'X', ' ', '-'}
|
||||
w.focusable = true
|
||||
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
|
||||
tcell.KeyEnter: func(_ *tcell.EventKey) bool {
|
||||
if w.state == CHECKBOX_ON {
|
||||
w.state = CHECKBOX_OFF
|
||||
} else {
|
||||
w.state = CHECKBOX_ON
|
||||
}
|
||||
return true
|
||||
},
|
||||
tcell.KeyEnter: w.ToggleState,
|
||||
})
|
||||
w.AddToKeyMap(NewRuneMap(map[rune]func(ev *tcell.EventKey) bool{
|
||||
' ': w.ToggleState,
|
||||
}))
|
||||
}
|
||||
func (w *Checkbox) Id() string { return w.id }
|
||||
func (w *Checkbox) HandleResize(ev *tcell.EventResize) {
|
||||
@@ -105,7 +101,7 @@ func (w *Checkbox) Draw(screen tcell.Screen) {
|
||||
if w.active {
|
||||
dStyle = w.style.Bold(true)
|
||||
}
|
||||
wh.DrawText(w.x, w.y, fmt.Sprintf("[%s] %s", string(w.state), w.label), dStyle, screen)
|
||||
wh.DrawText(w.x, w.y, fmt.Sprintf("[%s] %s", string(w.stateRunes[w.state]), w.label), dStyle, screen)
|
||||
}
|
||||
|
||||
func (w *Checkbox) Active() bool { return w.active }
|
||||
@@ -152,3 +148,12 @@ func (w *Checkbox) SetStateRunes(runes []rune) {
|
||||
w.stateRunes[i] = runes[i]
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Checkbox) ToggleState(_ *tcell.EventKey) bool {
|
||||
if w.state == CHECKBOX_ON {
|
||||
w.state = CHECKBOX_OFF
|
||||
} else {
|
||||
w.state = CHECKBOX_ON
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user