TextBox now has an OnEnter method.

This commit is contained in:
Sasha Koshka 2023-03-20 01:13:23 -04:00
parent 221647a265
commit d475e5e2ec

View File

@ -34,6 +34,7 @@ type TextBox struct {
onKeyDown func (key input.Key, modifiers input.Modifiers) (handled bool) onKeyDown func (key input.Key, modifiers input.Modifiers) (handled bool)
onChange func () onChange func ()
onEnter func ()
onScrollBoundsChange func () onScrollBoundsChange func ()
} }
@ -124,6 +125,11 @@ func (element *TextBox) HandleKeyDown(key input.Key, modifiers input.Modifiers)
altered := true altered := true
textChanged := false textChanged := false
switch { switch {
case key == input.KeyEnter:
if element.onEnter != nil {
element.onEnter()
}
case key == input.KeyBackspace: case key == input.KeyBackspace:
if len(element.text) < 1 { break } if len(element.text) < 1 { break }
element.text, element.dot = textmanip.Backspace ( element.text, element.dot = textmanip.Backspace (
@ -236,6 +242,10 @@ func (element *TextBox) OnKeyDown (
element.onKeyDown = callback element.onKeyDown = callback
} }
func (element *TextBox) OnEnter (callback func ()) {
element.onEnter = callback
}
func (element *TextBox) OnChange (callback func ()) { func (element *TextBox) OnChange (callback func ()) {
element.onChange = callback element.onChange = callback
} }