move SearchEntry into searcher.go file
This commit is contained in:
@@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,10 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Searcher struct {
|
type Searcher struct {
|
||||||
@@ -61,3 +65,56 @@ func (s *Searcher) sendSearch(text string) {
|
|||||||
s.OnSearched(text)
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user