fix search field action button not updating sometimes
This commit is contained in:
@@ -28,16 +28,17 @@ func NewSearchEntry() *SearchEntry {
|
|||||||
debounceFunc := util.NewDebouncer(200*time.Millisecond, func() {
|
debounceFunc := util.NewDebouncer(200*time.Millisecond, func() {
|
||||||
sf.sendSearch(sf.Entry.Text)
|
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
|
return sf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SearchEntry) Refresh() {
|
func (s *SearchEntry) Refresh() {
|
||||||
if s.Text == "" {
|
s.updateActionButton()
|
||||||
s.ActionItem.(*clearTextButton).Resource = theme.SearchIcon()
|
|
||||||
} else {
|
|
||||||
s.ActionItem.(*clearTextButton).Resource = theme.ContentClearIcon()
|
|
||||||
}
|
|
||||||
s.Entry.Refresh()
|
s.Entry.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +46,17 @@ func (s *SearchEntry) MinSize() fyne.Size {
|
|||||||
return fyne.NewSize(200, s.Entry.MinSize().Height)
|
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)
|
var _ fyne.Tappable = (*clearTextButton)(nil)
|
||||||
|
|
||||||
type clearTextButton struct {
|
type clearTextButton struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user