Button.SetBlurFunc() should have been named Button.SetExitFunc().

pull/669/head
Oliver 3 years ago
parent 0c92c2a810
commit 175cc7d7ce

@ -26,8 +26,9 @@ type Button struct {
selected func()
// An optional function which is called when the user leaves the button. A
// key is provided indicating which key was pressed to leave (tab or backtab).
blur func(tcell.Key)
// key is provided indicating which key was pressed to leave (tab or
// backtab).
exit func(tcell.Key)
}
// NewButton returns a new input field.
@ -80,15 +81,15 @@ func (b *Button) SetSelectedFunc(handler func()) *Button {
return b
}
// SetBlurFunc sets a handler which is called when the user leaves the button.
// SetExitFunc sets a handler which is called when the user leaves the button.
// The callback function is provided with the key that was pressed, which is one
// of the following:
//
// - KeyEscape: Leaving the button with no specific direction.
// - KeyTab: Move to the next field.
// - KeyBacktab: Move to the previous field.
func (b *Button) SetBlurFunc(handler func(key tcell.Key)) *Button {
b.blur = handler
func (b *Button) SetExitFunc(handler func(key tcell.Key)) *Button {
b.exit = handler
return b
}
@ -129,8 +130,8 @@ func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Prim
b.selected()
}
case tcell.KeyBacktab, tcell.KeyTab, tcell.KeyEscape: // Leave. No action.
if b.blur != nil {
b.blur(key)
if b.exit != nil {
b.exit(key)
}
}
})

@ -588,7 +588,7 @@ func (f *Form) Focus(delegate func(p Primitive)) {
} else {
// We're selecting a button.
button := f.buttons[f.focusedElement-len(f.items)]
button.SetBlurFunc(handler)
button.SetExitFunc(handler)
delegate(button)
}
}

@ -253,11 +253,6 @@ func (g *Grid) Focus(delegate func(p Primitive)) {
g.hasFocus = true
}
// Blur is called when this primitive loses focus.
func (g *Grid) Blur() {
g.hasFocus = false
}
// HasFocus returns whether or not this primitive has focus.
func (g *Grid) HasFocus() bool {
for _, item := range g.items {

@ -31,5 +31,5 @@ var Styles = Theme{
SecondaryTextColor: tcell.ColorYellow,
TertiaryTextColor: tcell.ColorGreen,
InverseTextColor: tcell.ColorBlue,
ContrastSecondaryTextColor: tcell.ColorDarkCyan,
ContrastSecondaryTextColor: tcell.ColorDarkBlue,
}

Loading…
Cancel
Save