From d475e5e2ec6a1cc03a1c99236dce15db477ed28c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 20 Mar 2023 01:13:23 -0400 Subject: [PATCH] TextBox now has an OnEnter method. --- elements/basic/textbox.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/elements/basic/textbox.go b/elements/basic/textbox.go index 393a0c7..4f8abf2 100644 --- a/elements/basic/textbox.go +++ b/elements/basic/textbox.go @@ -34,6 +34,7 @@ type TextBox struct { onKeyDown func (key input.Key, modifiers input.Modifiers) (handled bool) onChange func () + onEnter func () onScrollBoundsChange func () } @@ -124,6 +125,11 @@ func (element *TextBox) HandleKeyDown(key input.Key, modifiers input.Modifiers) altered := true textChanged := false switch { + case key == input.KeyEnter: + if element.onEnter != nil { + element.onEnter() + } + case key == input.KeyBackspace: if len(element.text) < 1 { break } element.text, element.dot = textmanip.Backspace ( @@ -236,6 +242,10 @@ func (element *TextBox) OnKeyDown ( element.onKeyDown = callback } +func (element *TextBox) OnEnter (callback func ()) { + element.onEnter = callback +} + func (element *TextBox) OnChange (callback func ()) { element.onChange = callback }