From 20f274797f1202529dfc367620b6b77a36198f48 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Tue, 14 Mar 2023 10:23:44 -0700 Subject: [PATCH] move SearchEntry into searcher.go file --- ui/widgets/searchentry.go | 60 --------------------------------------- ui/widgets/searcher.go | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 60 deletions(-) delete mode 100644 ui/widgets/searchentry.go diff --git a/ui/widgets/searchentry.go b/ui/widgets/searchentry.go deleted file mode 100644 index 81ac28b..0000000 --- a/ui/widgets/searchentry.go +++ /dev/null @@ -1,60 +0,0 @@ -package widgets - -import ( - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/theme" - "fyne.io/fyne/v2/widget" -) - -type SearchEntry struct { - widget.Entry - height float32 -} - -func NewSearchEntry() *SearchEntry { - sf := &SearchEntry{} - sf.ExtendBaseWidget(sf) - // this is a bit hacky - sf.height = widget.NewEntry().MinSize().Height - sf.PlaceHolder = "Search" - c := NewClearTextButton() - c.OnTapped = func() { - sf.SetText("") - } - sf.ActionItem = c - return sf -} - -func (s *SearchEntry) Refresh() { - if s.Text == "" { - s.ActionItem.(*clearTextButton).Resource = theme.SearchIcon() - } else { - s.ActionItem.(*clearTextButton).Resource = theme.ContentClearIcon() - } - s.Entry.Refresh() -} - -func (s *SearchEntry) MinSize() fyne.Size { - return fyne.NewSize(200, s.height) -} - -var _ fyne.Tappable = (*clearTextButton)(nil) - -type clearTextButton struct { - widget.Icon - - OnTapped func() -} - -func NewClearTextButton() *clearTextButton { - c := &clearTextButton{} - c.ExtendBaseWidget(c) - c.Resource = theme.SearchIcon() - return c -} - -func (c *clearTextButton) Tapped(*fyne.PointEvent) { - if c.OnTapped != nil { - c.OnTapped() - } -} diff --git a/ui/widgets/searcher.go b/ui/widgets/searcher.go index 49aa1b0..f9f64b8 100644 --- a/ui/widgets/searcher.go +++ b/ui/widgets/searcher.go @@ -3,6 +3,10 @@ package widgets import ( "sync" "time" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/theme" + "fyne.io/fyne/v2/widget" ) type Searcher struct { @@ -61,3 +65,56 @@ func (s *Searcher) sendSearch(text string) { s.OnSearched(text) } } + +type SearchEntry struct { + widget.Entry + height float32 +} + +func NewSearchEntry() *SearchEntry { + sf := &SearchEntry{} + sf.ExtendBaseWidget(sf) + // this is a bit hacky + sf.height = widget.NewEntry().MinSize().Height + sf.PlaceHolder = "Search" + c := NewClearTextButton() + c.OnTapped = func() { + sf.SetText("") + } + sf.ActionItem = c + return sf +} + +func (s *SearchEntry) Refresh() { + if s.Text == "" { + s.ActionItem.(*clearTextButton).Resource = theme.SearchIcon() + } else { + s.ActionItem.(*clearTextButton).Resource = theme.ContentClearIcon() + } + s.Entry.Refresh() +} + +func (s *SearchEntry) MinSize() fyne.Size { + return fyne.NewSize(200, s.height) +} + +var _ fyne.Tappable = (*clearTextButton)(nil) + +type clearTextButton struct { + widget.Icon + + OnTapped func() +} + +func NewClearTextButton() *clearTextButton { + c := &clearTextButton{} + c.ExtendBaseWidget(c) + c.Resource = theme.SearchIcon() + return c +} + +func (c *clearTextButton) Tapped(*fyne.PointEvent) { + if c.OnTapped != nil { + c.OnTapped() + } +}