change sort selector to button on Albums page
This commit is contained in:
+11
-28
@@ -51,7 +51,7 @@ type ArtistPage struct {
|
|||||||
|
|
||||||
albumGrid *widgets.GridView
|
albumGrid *widgets.GridView
|
||||||
tracklistCtr *fyne.Container
|
tracklistCtr *fyne.Container
|
||||||
sortButton *widgets.IconButton
|
sortButton *widgets.SortChooserButton
|
||||||
nowPlayingID string
|
nowPlayingID string
|
||||||
header *ArtistPageHeader
|
header *ArtistPageHeader
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
@@ -96,8 +96,16 @@ func newArtistPage(artistID string, cfg *backend.ArtistPageConfig, pool *util.Wi
|
|||||||
viewToggle := widgets.NewToggleText(0, []string{lang.L("Discography"), lang.L("Top Tracks")})
|
viewToggle := widgets.NewToggleText(0, []string{lang.L("Discography"), lang.L("Top Tracks")})
|
||||||
viewToggle.SetActivatedLabel(a.activeView)
|
viewToggle.SetActivatedLabel(a.activeView)
|
||||||
viewToggle.OnChanged = a.onViewChange
|
viewToggle.OnChanged = a.onViewChange
|
||||||
a.sortButton = widgets.NewIconButton(myTheme.SortIcon, a.showAlbumSortMenu)
|
a.sortButton = widgets.NewSortChooserButton(util.LocalizeSlice(discographySorts), func(selIdx int) {
|
||||||
a.sortButton.SetToolTip(lang.L("Sort"))
|
a.cfg.DiscographySort = discographySorts[selIdx]
|
||||||
|
a.showAlbumGrid(true /*reSort*/)
|
||||||
|
})
|
||||||
|
a.sortButton.AlignLeft = true
|
||||||
|
for i, sort := range discographySorts {
|
||||||
|
if sort == a.cfg.DiscographySort {
|
||||||
|
a.sortButton.SetSelectedIndex(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
viewToggleRow := container.NewBorder(nil, nil,
|
viewToggleRow := container.NewBorder(nil, nil,
|
||||||
container.NewHBox(util.NewHSpace(5), viewToggle),
|
container.NewHBox(util.NewHSpace(5), viewToggle),
|
||||||
container.NewHBox(a.sortButton, util.NewHSpace(10)),
|
container.NewHBox(a.sortButton, util.NewHSpace(10)),
|
||||||
@@ -182,31 +190,6 @@ func (a *ArtistPage) playArtistRadio() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistPage) showAlbumSortMenu() {
|
|
||||||
m := fyne.NewMenu("")
|
|
||||||
oneChecked := false
|
|
||||||
for i, s := range util.LocalizeSlice(discographySorts) {
|
|
||||||
_i := i
|
|
||||||
item := fyne.NewMenuItem(s, func() {
|
|
||||||
a.cfg.DiscographySort = discographySorts[_i]
|
|
||||||
a.showAlbumGrid(true /*reSort*/)
|
|
||||||
})
|
|
||||||
if discographySorts[i] == a.cfg.DiscographySort {
|
|
||||||
item.Checked = true
|
|
||||||
oneChecked = true
|
|
||||||
}
|
|
||||||
m.Items = append(m.Items, item)
|
|
||||||
}
|
|
||||||
if !oneChecked {
|
|
||||||
m.Items[0].Checked = true
|
|
||||||
}
|
|
||||||
btnPos := fyne.CurrentApp().Driver().AbsolutePositionForObject(a.sortButton)
|
|
||||||
btnSize := a.sortButton.Size()
|
|
||||||
pop := widget.NewPopUpMenu(m, fyne.CurrentApp().Driver().CanvasForObject(a))
|
|
||||||
menuW := pop.MinSize().Width
|
|
||||||
pop.ShowAtPosition(fyne.NewPos(btnPos.X+btnSize.Width-menuW, btnPos.Y+btnSize.Height))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel {
|
func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel {
|
||||||
if a.artistInfo == nil {
|
if a.artistInfo == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type GridViewPage[M, F any] struct {
|
|||||||
searchGridState *widgets.GridViewState
|
searchGridState *widgets.GridViewState
|
||||||
|
|
||||||
title *widget.RichText
|
title *widget.RichText
|
||||||
sortOrder *widget.Select
|
sortOrder *widgets.SortChooserButton
|
||||||
filterBtn widgets.FilterButton[M, F]
|
filterBtn widgets.FilterButton[M, F]
|
||||||
filter mediaprovider.MediaFilter[M, F]
|
filter mediaprovider.MediaFilter[M, F]
|
||||||
searcher *widgets.SearchEntry
|
searcher *widgets.SearchEntry
|
||||||
@@ -125,15 +125,7 @@ func (g *GridViewPage[M, F]) createTitleAndSort() {
|
|||||||
})
|
})
|
||||||
if s, ok := g.adapter.(SortableGridViewPageAdapter); ok {
|
if s, ok := g.adapter.(SortableGridViewPageAdapter); ok {
|
||||||
sorts, selected := s.SortOrders()
|
sorts, selected := s.SortOrders()
|
||||||
g.sortOrder = widget.NewSelect(sorts, g.onSortOrderChanged)
|
g.sortOrder = widgets.NewSortChooserButton(sorts, g.onSortOrderChanged)
|
||||||
// find longest string
|
|
||||||
l := ""
|
|
||||||
for _, s := range sorts {
|
|
||||||
if len(s) > len(l) {
|
|
||||||
l = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g.sortOrder.PlaceHolder = l // props up MinSize.Width
|
|
||||||
g.sortOrder.SetSelectedIndex(selected)
|
g.sortOrder.SetSelectedIndex(selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,13 +205,13 @@ func (g *GridViewPage[M, F]) doSearch(query string) {
|
|||||||
g.grid.Reset(g.adapter.SearchIter(query, g.getFilter()))
|
g.grid.Reset(g.adapter.SearchIter(query, g.getFilter()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewPage[M, F]) onSortOrderChanged(_ string) {
|
func (g *GridViewPage[M, F]) onSortOrderChanged(idx int) {
|
||||||
if g.grid == nil {
|
if g.grid == nil {
|
||||||
return // callback from initializing
|
return // callback from initializing
|
||||||
}
|
}
|
||||||
|
|
||||||
g.adapter.(SortableGridViewPageAdapter).SaveSortOrder(g.getSortOrderIdx())
|
g.adapter.(SortableGridViewPageAdapter).SaveSortOrder(g.getSortOrderIdx())
|
||||||
g.grid.Reset(g.adapter.Iter(g.getSortOrderIdx(), g.getFilter()))
|
g.grid.Reset(g.adapter.Iter(idx, g.getFilter()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewPage[M, F]) getFilter() mediaprovider.MediaFilter[M, F] {
|
func (g *GridViewPage[M, F]) getFilter() mediaprovider.MediaFilter[M, F] {
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ type IconButton struct {
|
|||||||
IconSize IconButtonSize
|
IconSize IconButtonSize
|
||||||
OnTapped func()
|
OnTapped func()
|
||||||
|
|
||||||
icon fyne.Resource
|
icon fyne.Resource
|
||||||
focused bool
|
focused bool
|
||||||
hovered bool
|
hovered bool
|
||||||
|
disabled bool
|
||||||
|
|
||||||
themed *theme.ThemedResource
|
themed *theme.ThemedResource
|
||||||
img *canvas.Image
|
img *canvas.Image
|
||||||
@@ -38,6 +39,7 @@ type IconButton struct {
|
|||||||
var (
|
var (
|
||||||
_ fyne.Tappable = (*IconButton)(nil)
|
_ fyne.Tappable = (*IconButton)(nil)
|
||||||
_ fyne.Focusable = (*IconButton)(nil)
|
_ fyne.Focusable = (*IconButton)(nil)
|
||||||
|
_ fyne.Disableable = (*IconButton)(nil)
|
||||||
_ desktop.Hoverable = (*IconButton)(nil)
|
_ desktop.Hoverable = (*IconButton)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,8 +58,26 @@ func (i *IconButton) SetIcon(icon fyne.Resource) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *IconButton) Disable() {
|
||||||
|
if !i.disabled {
|
||||||
|
i.disabled = true
|
||||||
|
i.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IconButton) Enable() {
|
||||||
|
if i.disabled {
|
||||||
|
i.disabled = false
|
||||||
|
i.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IconButton) Disabled() bool {
|
||||||
|
return i.disabled
|
||||||
|
}
|
||||||
|
|
||||||
func (i *IconButton) Tapped(*fyne.PointEvent) {
|
func (i *IconButton) Tapped(*fyne.PointEvent) {
|
||||||
if i.OnTapped != nil {
|
if !i.disabled && i.OnTapped != nil {
|
||||||
i.OnTapped()
|
i.OnTapped()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +97,7 @@ func (i *IconButton) FocusLost() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *IconButton) TypedKey(e *fyne.KeyEvent) {
|
func (i *IconButton) TypedKey(e *fyne.KeyEvent) {
|
||||||
if e.Name == fyne.KeySpace {
|
if !i.disabled && e.Name == fyne.KeySpace {
|
||||||
i.Tapped(nil)
|
i.Tapped(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,6 +107,10 @@ func (i *IconButton) TypedRune(r rune) {
|
|||||||
|
|
||||||
func (i *IconButton) MouseIn(e *desktop.MouseEvent) {
|
func (i *IconButton) MouseIn(e *desktop.MouseEvent) {
|
||||||
i.ToolTipWidget.MouseIn(e)
|
i.ToolTipWidget.MouseIn(e)
|
||||||
|
if i.disabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !i.hovered {
|
if !i.hovered {
|
||||||
defer i.Refresh()
|
defer i.Refresh()
|
||||||
}
|
}
|
||||||
@@ -95,6 +119,10 @@ func (i *IconButton) MouseIn(e *desktop.MouseEvent) {
|
|||||||
|
|
||||||
func (i *IconButton) MouseOut() {
|
func (i *IconButton) MouseOut() {
|
||||||
i.ToolTipWidget.MouseOut()
|
i.ToolTipWidget.MouseOut()
|
||||||
|
if i.disabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if i.hovered {
|
if i.hovered {
|
||||||
defer i.Refresh()
|
defer i.Refresh()
|
||||||
}
|
}
|
||||||
@@ -121,7 +149,9 @@ func (i *IconButton) iconSize() fyne.Size {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *IconButton) updateColor() {
|
func (i *IconButton) updateColor() {
|
||||||
if i.Highlighted || i.focused {
|
if i.disabled {
|
||||||
|
i.themed.ColorName = theme.ColorNameDisabled
|
||||||
|
} else if i.Highlighted || i.focused {
|
||||||
i.themed.ColorName = theme.ColorNamePrimary
|
i.themed.ColorName = theme.ColorNamePrimary
|
||||||
} else if i.hovered {
|
} else if i.hovered {
|
||||||
i.themed.ColorName = myTheme.ColorNameHoveredIconButton
|
i.themed.ColorName = myTheme.ColorNameHoveredIconButton
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package widgets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/lang"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/dweymouth/supersonic/ui/theme"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SortChooserButton struct {
|
||||||
|
widget.BaseWidget
|
||||||
|
|
||||||
|
Sorts []string
|
||||||
|
AlignLeft bool
|
||||||
|
|
||||||
|
OnChanged func(selIndex int)
|
||||||
|
|
||||||
|
disabled bool
|
||||||
|
selectedIndex int
|
||||||
|
btn *IconButton
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSortChooserButton(sorts []string, onChanged func(selIdx int)) *SortChooserButton {
|
||||||
|
s := &SortChooserButton{Sorts: sorts, OnChanged: onChanged}
|
||||||
|
s.ExtendBaseWidget(s)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) SelectedIndex() int {
|
||||||
|
return s.selectedIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) SetSelectedIndex(idx int) {
|
||||||
|
if idx < 0 || idx > len(s.Sorts)-1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.selectedIndex = idx
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) Disable() {
|
||||||
|
if !s.disabled {
|
||||||
|
s.disabled = true
|
||||||
|
s.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) Enable() {
|
||||||
|
if s.disabled {
|
||||||
|
s.disabled = false
|
||||||
|
s.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) Disabled() bool {
|
||||||
|
return s.disabled
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) Refresh() {
|
||||||
|
if s.btn != nil {
|
||||||
|
if s.disabled {
|
||||||
|
s.btn.Disable()
|
||||||
|
} else {
|
||||||
|
s.btn.Enable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.BaseWidget.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
s.btn = NewIconButton(theme.SortIcon, s.showMenu)
|
||||||
|
s.btn.SetToolTip(lang.L("Sort"))
|
||||||
|
return widget.NewSimpleRenderer(s.btn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SortChooserButton) showMenu() {
|
||||||
|
m := fyne.NewMenu("")
|
||||||
|
for i, lbl := range s.Sorts {
|
||||||
|
_i := i
|
||||||
|
item := fyne.NewMenuItem(lbl, func() {
|
||||||
|
s.selectedIndex = _i
|
||||||
|
if s.OnChanged != nil {
|
||||||
|
s.OnChanged(_i)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if i == s.selectedIndex {
|
||||||
|
item.Checked = true
|
||||||
|
}
|
||||||
|
m.Items = append(m.Items, item)
|
||||||
|
}
|
||||||
|
btnPos := fyne.CurrentApp().Driver().AbsolutePositionForObject(s)
|
||||||
|
btnSize := s.Size()
|
||||||
|
pop := widget.NewPopUpMenu(m, fyne.CurrentApp().Driver().CanvasForObject(s))
|
||||||
|
menuW := pop.MinSize().Width
|
||||||
|
if s.AlignLeft {
|
||||||
|
pop.ShowAtPosition(fyne.NewPos(btnPos.X+btnSize.Width-menuW, btnPos.Y+btnSize.Height))
|
||||||
|
} else {
|
||||||
|
pop.ShowAtPosition(fyne.NewPos(btnPos.X, btnPos.Y+btnSize.Height))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user