andlabs / ui

Platform-native GUI library for Go.
Other
8.33k stars 651 forks source link

ui.Entry event OnChanged doesn't fire for its SetText function #307

Open philiplb opened 6 years ago

philiplb commented 6 years ago

Hi, for me, the ui.Entry event OnChanged doesn't fire for its SetText function. My setup is like this:

myInput = ui.NewEntry()
myOpenButton.OnClicked(func(_ *ui.Button) {
    file := ui.OpenFile(window)
    myInput.SetText(file)
})
myInput.OnChanged(func(_ *ui.Entry) {
    fmt.Println(myInput.Text())
})

When I enter something manually in the entry field, the event gets fired just fine. But it doesn't fire for myInput.SetText(file). Of course, I can easily work around that, just noticing. :) Currently, it looks like this:

myInputOnChanged := func(_ *ui.Entry) {
    fmt.Println(myInput.Text())
}
myOpenButton.OnClicked(func(_ *ui.Button) {
    file := ui.OpenFile(window)
    myInput.SetText(file)
    myInputOnChanged(nil)
})
myInput.OnChanged(myInputOnChanged)
andlabs commented 6 years ago

Yes, that's intentional. Enough people are interested in having this behavior that I could probably provide some method...