Skip to content

Commit

Permalink
Button.SetBlurFunc() should have been named Button.SetExitFunc().
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver committed Nov 8, 2021
1 parent 0c92c2a commit 175cc7d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
15 changes: 8 additions & 7 deletions button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion form.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 0 additions & 5 deletions grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ var Styles = Theme{
SecondaryTextColor: tcell.ColorYellow,
TertiaryTextColor: tcell.ColorGreen,
InverseTextColor: tcell.ColorBlue,
ContrastSecondaryTextColor: tcell.ColorDarkCyan,
ContrastSecondaryTextColor: tcell.ColorDarkBlue,
}

0 comments on commit 175cc7d

Please sign in to comment.