fix search field action button not updating sometimes

This commit is contained in:
Drew Weymouth
2023-11-03 17:24:37 -07:00
parent 0420465af5
commit 6033d5f6bc
+18 -6
View File
@@ -28,16 +28,17 @@ func NewSearchEntry() *SearchEntry {
debounceFunc := util.NewDebouncer(200*time.Millisecond, func() {
sf.sendSearch(sf.Entry.Text)
})
sf.Entry.OnChanged = func(_ string) { debounceFunc() }
sf.Entry.OnChanged = func(_ string) {
if sf.updateActionButton() {
sf.ActionItem.Refresh()
}
debounceFunc()
}
return sf
}
func (s *SearchEntry) Refresh() {
if s.Text == "" {
s.ActionItem.(*clearTextButton).Resource = theme.SearchIcon()
} else {
s.ActionItem.(*clearTextButton).Resource = theme.ContentClearIcon()
}
s.updateActionButton()
s.Entry.Refresh()
}
@@ -45,6 +46,17 @@ func (s *SearchEntry) MinSize() fyne.Size {
return fyne.NewSize(200, s.Entry.MinSize().Height)
}
func (s *SearchEntry) updateActionButton() bool {
btn := s.ActionItem.(*clearTextButton)
oldResouce := btn.Resource
if s.Text == "" {
btn.Resource = theme.SearchIcon()
} else {
btn.Resource = theme.ContentClearIcon()
}
return oldResouce != btn.Resource
}
var _ fyne.Tappable = (*clearTextButton)(nil)
type clearTextButton struct {