Add OnEdit to TextInput

This commit is contained in:
Sasha Koshka 2024-05-07 18:24:19 -04:00
parent 4d790f7264
commit ca2f9654b3

View File

@ -13,6 +13,7 @@ type TextInput struct {
text []rune text []rune
on struct { on struct {
enter event.FuncBroadcaster enter event.FuncBroadcaster
edit event.FuncBroadcaster
} }
} }
@ -47,6 +48,11 @@ func (this *TextInput) OnEnter (callback func ()) event.Cookie {
return this.on.enter.Connect(callback) return this.on.enter.Connect(callback)
} }
// OnEdit specifies a function to be called when the user edits the input text.
func (this *TextInput) OnEdit (callback func ()) event.Cookie {
return this.on.edit.Connect(callback)
}
func (this *TextInput) handleKeyDown (key input.Key, numpad bool) { func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
dot := this.Dot() dot := this.Dot()
modifiers := this.Modifiers() modifiers := this.Modifiers()
@ -93,7 +99,10 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
} }
this.Select(dot) this.Select(dot)
if changed { this.SetText(string(this.text)) } if changed {
this.SetText(string(this.text))
this.on.edit.Broadcast()
}
} }
func (this *TextInput) handleScroll (x, y float64) { func (this *TextInput) handleScroll (x, y float64) {