switch GridView to icon placeholder
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 7.6 KiB |
File diff suppressed because one or more lines are too long
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
fyne bundle -package res -prefix Res appicon-256.png > bundled.go
|
fyne bundle -package res -prefix Res appicon-256.png > bundled.go
|
||||||
fyne bundle -append -prefix Res albumplaceholder.png >> bundled.go
|
|
||||||
fyne bundle -append -prefix Res icons/freepik/disc.png >> bundled.go
|
fyne bundle -append -prefix Res icons/freepik/disc.png >> bundled.go
|
||||||
fyne bundle -append -prefix Res icons/freepik/disc-invert.png >> bundled.go
|
fyne bundle -append -prefix Res icons/freepik/disc-invert.png >> bundled.go
|
||||||
fyne bundle -append -prefix Res icons/freepik/headphones.png >> bundled.go
|
fyne bundle -append -prefix Res icons/freepik/headphones.png >> bundled.go
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
"github.com/dweymouth/supersonic/ui/util"
|
"github.com/dweymouth/supersonic/ui/util"
|
||||||
"github.com/dweymouth/supersonic/ui/widgets"
|
"github.com/dweymouth/supersonic/ui/widgets"
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ func NewAlbumsPage(cfg *backend.AlbumsPageConfig, contr *controller.Controller,
|
|||||||
}
|
}
|
||||||
a.sortOrder.Selected = cfg.SortOrder
|
a.sortOrder.Selected = cfg.SortOrder
|
||||||
iter := mp.IterateAlbums(a.sortOrder.Selected, a.filter)
|
iter := mp.IterateAlbums(a.sortOrder.Selected, a.filter)
|
||||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), im)
|
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), im, myTheme.AlbumIcon)
|
||||||
contr.ConnectAlbumGridActions(a.grid)
|
contr.ConnectAlbumGridActions(a.grid)
|
||||||
a.createSearchAndFilter()
|
a.createSearchAndFilter()
|
||||||
a.createContainer(false)
|
a.createContainer(false)
|
||||||
@@ -190,7 +191,7 @@ func (a *AlbumsPage) Save() SavedPage {
|
|||||||
func (a *AlbumsPage) doSearch(query string) {
|
func (a *AlbumsPage) doSearch(query string) {
|
||||||
iter := widgets.NewGridViewAlbumIterator(a.mp.SearchAlbums(query, a.filter))
|
iter := widgets.NewGridViewAlbumIterator(a.mp.SearchAlbums(query, a.filter))
|
||||||
if a.searchGrid == nil {
|
if a.searchGrid == nil {
|
||||||
a.searchGrid = widgets.NewGridView(iter, a.im)
|
a.searchGrid = widgets.NewGridView(iter, a.im, myTheme.AlbumIcon)
|
||||||
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
||||||
} else {
|
} else {
|
||||||
a.searchGrid.Reset(iter)
|
a.searchGrid.Reset(iter)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
"github.com/dweymouth/supersonic/res"
|
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
"github.com/dweymouth/supersonic/ui/layouts"
|
"github.com/dweymouth/supersonic/ui/layouts"
|
||||||
@@ -166,7 +165,7 @@ func (a *ArtistPage) showAlbumGrid() {
|
|||||||
Secondary: strconv.Itoa(al.Year),
|
Secondary: strconv.Itoa(al.Year),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
a.albumGrid = widgets.NewFixedGridView(model, a.im)
|
a.albumGrid = widgets.NewFixedGridView(model, a.im, myTheme.AlbumIcon)
|
||||||
a.contr.ConnectAlbumGridActions(a.albumGrid)
|
a.contr.ConnectAlbumGridActions(a.albumGrid)
|
||||||
}
|
}
|
||||||
a.container.Objects[0].(*fyne.Container).Objects[0] = a.albumGrid
|
a.container.Objects[0].(*fyne.Container).Objects[0] = a.albumGrid
|
||||||
@@ -251,7 +250,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
|||||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
a.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||||
SizeName: theme.SizeNameHeadingText,
|
SizeName: theme.SizeNameHeadingText,
|
||||||
}
|
}
|
||||||
a.artistImage = widgets.NewImagePlaceholder(res.ResPeopleInvertPng, 225)
|
a.artistImage = widgets.NewImagePlaceholder(myTheme.ArtistIcon, 225)
|
||||||
a.artistImage.OnTapped = func() {
|
a.artistImage.OnTapped = func() {
|
||||||
if im := a.artistImage.Image(); im != nil {
|
if im := a.artistImage.Image(); im != nil {
|
||||||
a.artistPage.contr.ShowPopUpImage(im)
|
a.artistPage.contr.ShowPopUpImage(im)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
"github.com/dweymouth/supersonic/ui/util"
|
"github.com/dweymouth/supersonic/ui/util"
|
||||||
"github.com/dweymouth/supersonic/ui/widgets"
|
"github.com/dweymouth/supersonic/ui/widgets"
|
||||||
)
|
)
|
||||||
@@ -74,7 +75,7 @@ func newArtistsPage(
|
|||||||
a.searcher = widgets.NewSearchEntry()
|
a.searcher = widgets.NewSearchEntry()
|
||||||
a.searcher.OnSearched = func(query string) { a.onSearched(query, false /*firstLoad*/) }
|
a.searcher.OnSearched = func(query string) { a.onSearched(query, false /*firstLoad*/) }
|
||||||
a.searcher.Entry.Text = searchText
|
a.searcher.Entry.Text = searchText
|
||||||
a.grid = widgets.NewFixedGridView(nil, a.im)
|
a.grid = widgets.NewFixedGridView(nil, a.im, myTheme.ArtistIcon)
|
||||||
a.grid.OnShowItemPage = a.showArtistPage
|
a.grid.OnShowItemPage = a.showArtistPage
|
||||||
a.grid.OnPlay = func(artistID string, shuffle bool) { go a.contr.PlayArtistDiscography(artistID, shuffle) }
|
a.grid.OnPlay = func(artistID string, shuffle bool) { go a.contr.PlayArtistDiscography(artistID, shuffle) }
|
||||||
a.grid.OnAddToQueue = func(artistID string) {
|
a.grid.OnAddToQueue = func(artistID string) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func NewFavoritesPage(cfg *backend.FavoritesPageConfig, contr *controller.Contro
|
|||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.createHeader(0)
|
a.createHeader(0)
|
||||||
iter := mp.IterateAlbums("", a.filter)
|
iter := mp.IterateAlbums("", a.filter)
|
||||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im)
|
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im, myTheme.AlbumIcon)
|
||||||
a.contr.ConnectAlbumGridActions(a.grid)
|
a.contr.ConnectAlbumGridActions(a.grid)
|
||||||
if cfg.InitialView == "Artists" {
|
if cfg.InitialView == "Artists" {
|
||||||
a.toggleBtns.SetActivatedButton(1)
|
a.toggleBtns.SetActivatedButton(1)
|
||||||
@@ -233,7 +233,7 @@ func (a *FavoritesPage) SelectAll() {
|
|||||||
func (a *FavoritesPage) doSearchAlbums(query string) {
|
func (a *FavoritesPage) doSearchAlbums(query string) {
|
||||||
iter := a.mp.SearchAlbums(query, a.filter)
|
iter := a.mp.SearchAlbums(query, a.filter)
|
||||||
if a.searchGrid == nil {
|
if a.searchGrid == nil {
|
||||||
a.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im)
|
a.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im, myTheme.AlbumIcon)
|
||||||
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
||||||
} else {
|
} else {
|
||||||
a.searchGrid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
a.searchGrid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func NewGenrePage(genre string, contr *controller.Controller, pm *backend.Playba
|
|||||||
}
|
}
|
||||||
g.playRandom = widget.NewButtonWithIcon(" Play random", myTheme.ShuffleIcon, g.playRandomSongs)
|
g.playRandom = widget.NewButtonWithIcon(" Play random", myTheme.ShuffleIcon, g.playRandomSongs)
|
||||||
iter := g.mp.IterateAlbums("", g.filter)
|
iter := g.mp.IterateAlbums("", g.filter)
|
||||||
g.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im)
|
g.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im, myTheme.AlbumIcon)
|
||||||
g.contr.ConnectAlbumGridActions(g.grid)
|
g.contr.ConnectAlbumGridActions(g.grid)
|
||||||
g.createSearchAndFilter()
|
g.createSearchAndFilter()
|
||||||
g.createContainer(false)
|
g.createContainer(false)
|
||||||
@@ -169,7 +169,7 @@ func (g *GenrePage) OnSearched(query string) {
|
|||||||
func (g *GenrePage) doSearch(query string) {
|
func (g *GenrePage) doSearch(query string) {
|
||||||
iter := g.mp.SearchAlbums(query, g.filter)
|
iter := g.mp.SearchAlbums(query, g.filter)
|
||||||
if g.searchGrid == nil {
|
if g.searchGrid == nil {
|
||||||
g.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im)
|
g.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im, myTheme.AlbumIcon)
|
||||||
g.contr.ConnectAlbumGridActions(g.searchGrid)
|
g.contr.ConnectAlbumGridActions(g.searchGrid)
|
||||||
} else {
|
} else {
|
||||||
g.searchGrid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
g.searchGrid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
"github.com/dweymouth/supersonic/res"
|
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
"github.com/dweymouth/supersonic/ui/layouts"
|
"github.com/dweymouth/supersonic/ui/layouts"
|
||||||
@@ -183,7 +182,7 @@ func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
|||||||
a := &PlaylistPageHeader{page: page}
|
a := &PlaylistPageHeader{page: page}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
|
|
||||||
a.image = widgets.NewImagePlaceholder(res.ResPlaylistInvertPng, 225)
|
a.image = widgets.NewImagePlaceholder(myTheme.PlaylistIcon, 225)
|
||||||
a.titleLabel = widget.NewRichTextWithText("")
|
a.titleLabel = widget.NewRichTextWithText("")
|
||||||
a.titleLabel.Wrapping = fyne.TextTruncate
|
a.titleLabel.Wrapping = fyne.TextTruncate
|
||||||
a.titleLabel.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
a.titleLabel.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
"github.com/dweymouth/supersonic/ui/layouts"
|
"github.com/dweymouth/supersonic/ui/layouts"
|
||||||
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
"github.com/dweymouth/supersonic/ui/widgets"
|
"github.com/dweymouth/supersonic/ui/widgets"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
@@ -94,7 +95,7 @@ func (a *PlaylistsPage) createListView() {
|
|||||||
|
|
||||||
func (a *PlaylistsPage) createGridView(playlists []*mediaprovider.Playlist) {
|
func (a *PlaylistsPage) createGridView(playlists []*mediaprovider.Playlist) {
|
||||||
model := createPlaylistGridViewModel(playlists)
|
model := createPlaylistGridViewModel(playlists)
|
||||||
a.gridView = widgets.NewFixedGridView(model, a.contr.App.ImageManager)
|
a.gridView = widgets.NewFixedGridView(model, a.contr.App.ImageManager, myTheme.PlaylistIcon)
|
||||||
a.gridView.OnPlay = func(id string, shuffle bool) {
|
a.gridView.OnPlay = func(id string, shuffle bool) {
|
||||||
go a.contr.App.PlaybackManager.PlayPlaylist(id, 0, shuffle)
|
go a.contr.App.PlaybackManager.PlayPlaylist(id, 0, shuffle)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,14 +94,12 @@ func (a *AboutDialog) buildCreditsContainer() fyne.CanvasObject {
|
|||||||
freepikURL, _ := url.Parse("https://www.flaticon.com/authors/freepik")
|
freepikURL, _ := url.Parse("https://www.flaticon.com/authors/freepik")
|
||||||
appIconCredit := widget.NewLabel("The Supersonic app icon is a derivative of a work created by Piotr Siedlecki and placed in the public domain.")
|
appIconCredit := widget.NewLabel("The Supersonic app icon is a derivative of a work created by Piotr Siedlecki and placed in the public domain.")
|
||||||
appIconCredit.Wrapping = fyne.TextWrapWord
|
appIconCredit.Wrapping = fyne.TextWrapWord
|
||||||
albumPlaceholderCredit := widget.NewLabel("The album cover placeholder image was created by @LaurenBacall originally for the MP3Tag project.")
|
|
||||||
albumPlaceholderCredit.Wrapping = fyne.TextWrapWord
|
|
||||||
return container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
|
return container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
|
||||||
widget.NewLabel("Major frameworks and modules used in this application include:"),
|
widget.NewLabel("Major frameworks and modules used in this application include:"),
|
||||||
container.NewHBox(widget.NewHyperlink("Fyne toolkit", fyneURL), widget.NewLabel("BSD 3-Clause License")),
|
container.NewHBox(widget.NewHyperlink("Fyne toolkit", fyneURL), widget.NewLabel("BSD 3-Clause License")),
|
||||||
container.NewHBox(widget.NewHyperlink("go-subsonic", goSubsonicURL), widget.NewLabel("GPL v3 License")),
|
container.NewHBox(widget.NewHyperlink("go-subsonic", goSubsonicURL), widget.NewLabel("GPL v3 License")),
|
||||||
container.NewHBox(widget.NewHyperlink("go-toml", goTomlURL), widget.NewLabel("MIT License")),
|
container.NewHBox(widget.NewHyperlink("go-toml", goTomlURL), widget.NewLabel("MIT License")),
|
||||||
appIconCredit, albumPlaceholderCredit,
|
appIconCredit,
|
||||||
container.NewHBox(widget.NewLabel("Additional icons by:"), widget.NewHyperlink("Freepik on flaticon.com", freepikURL)),
|
container.NewHBox(widget.NewLabel("Additional icons by:"), widget.NewHyperlink("Freepik on flaticon.com", freepikURL)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ type ThemedRectangle struct {
|
|||||||
|
|
||||||
rect *canvas.Rectangle
|
rect *canvas.Rectangle
|
||||||
|
|
||||||
ColorName fyne.ThemeColorName
|
ColorName fyne.ThemeColorName
|
||||||
|
BorderWidth float32
|
||||||
|
BorderColorName fyne.ThemeColorName
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewThemedRectangle(colorName fyne.ThemeColorName) *ThemedRectangle {
|
func NewThemedRectangle(colorName fyne.ThemeColorName) *ThemedRectangle {
|
||||||
@@ -25,8 +27,11 @@ func NewThemedRectangle(colorName fyne.ThemeColorName) *ThemedRectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThemedRectangle) Refresh() {
|
func (t *ThemedRectangle) Refresh() {
|
||||||
t.rect.FillColor = fyne.CurrentApp().Settings().Theme().Color(t.ColorName,
|
settings := fyne.CurrentApp().Settings()
|
||||||
fyne.CurrentApp().Settings().ThemeVariant())
|
theme := settings.Theme()
|
||||||
|
t.rect.FillColor = theme.Color(t.ColorName, settings.ThemeVariant())
|
||||||
|
t.rect.StrokeWidth = t.BorderWidth
|
||||||
|
t.rect.StrokeColor = theme.Color(t.BorderColorName, settings.ThemeVariant())
|
||||||
t.BaseWidget.Refresh()
|
t.BaseWidget.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-8
@@ -7,7 +7,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
"github.com/dweymouth/supersonic/res"
|
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
@@ -81,6 +80,7 @@ type GridViewState struct {
|
|||||||
itemsMutex sync.RWMutex
|
itemsMutex sync.RWMutex
|
||||||
iter GridViewIterator
|
iter GridViewIterator
|
||||||
imageFetcher ImageFetcher
|
imageFetcher ImageFetcher
|
||||||
|
placeholder fyne.Resource
|
||||||
highestShown int
|
highestShown int
|
||||||
fetchCancel context.CancelFunc
|
fetchCancel context.CancelFunc
|
||||||
done bool
|
done bool
|
||||||
@@ -96,12 +96,13 @@ type GridViewState struct {
|
|||||||
|
|
||||||
var _ fyne.Widget = (*GridView)(nil)
|
var _ fyne.Widget = (*GridView)(nil)
|
||||||
|
|
||||||
func NewFixedGridView(items []GridViewItemModel, fetch ImageFetcher) *GridView {
|
func NewFixedGridView(items []GridViewItemModel, fetch ImageFetcher, placeholder fyne.Resource) *GridView {
|
||||||
g := &GridView{
|
g := &GridView{
|
||||||
GridViewState: GridViewState{
|
GridViewState: GridViewState{
|
||||||
items: items,
|
items: items,
|
||||||
done: true,
|
done: true,
|
||||||
imageFetcher: fetch,
|
imageFetcher: fetch,
|
||||||
|
placeholder: placeholder,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
g.ExtendBaseWidget(g)
|
g.ExtendBaseWidget(g)
|
||||||
@@ -109,7 +110,7 @@ func NewFixedGridView(items []GridViewItemModel, fetch ImageFetcher) *GridView {
|
|||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGridView(iter GridViewIterator, fetch ImageFetcher) *GridView {
|
func NewGridView(iter GridViewIterator, fetch ImageFetcher, placeholder fyne.Resource) *GridView {
|
||||||
g := &GridView{
|
g := &GridView{
|
||||||
GridViewState: GridViewState{
|
GridViewState: GridViewState{
|
||||||
iter: iter,
|
iter: iter,
|
||||||
@@ -117,7 +118,6 @@ func NewGridView(iter GridViewIterator, fetch ImageFetcher) *GridView {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
g.ExtendBaseWidget(g)
|
g.ExtendBaseWidget(g)
|
||||||
|
|
||||||
g.createGridWrap()
|
g.createGridWrap()
|
||||||
|
|
||||||
// fetch initial items
|
// fetch initial items
|
||||||
@@ -174,6 +174,14 @@ func (g *GridView) ResetFixed(items []GridViewItemModel) {
|
|||||||
g.iter = nil
|
g.iter = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GridView) GetScrollOffset() float32 {
|
||||||
|
return g.grid.GetScrollOffset()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GridView) ScrollToOffset(offs float32) {
|
||||||
|
g.grid.ScrollToOffset(offs)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GridView) createGridWrap() {
|
func (g *GridView) createGridWrap() {
|
||||||
g.grid = NewGridWrap(
|
g.grid = NewGridWrap(
|
||||||
func() int {
|
func() int {
|
||||||
@@ -181,7 +189,7 @@ func (g *GridView) createGridWrap() {
|
|||||||
},
|
},
|
||||||
// create func
|
// create func
|
||||||
func() fyne.CanvasObject {
|
func() fyne.CanvasObject {
|
||||||
card := NewGridViewItem()
|
card := NewGridViewItem(g.placeholder)
|
||||||
card.OnPlay = func(shuffle bool) {
|
card.OnPlay = func(shuffle bool) {
|
||||||
if g.OnPlay != nil {
|
if g.OnPlay != nil {
|
||||||
g.OnPlay(card.ItemID(), shuffle)
|
g.OnPlay(card.ItemID(), shuffle)
|
||||||
@@ -244,7 +252,7 @@ func (g *GridView) doUpdateItemCard(itemIdx int, card *GridViewItem) {
|
|||||||
if img, ok := g.imageFetcher.GetCoverThumbnailFromCache(item.CoverArtID); ok {
|
if img, ok := g.imageFetcher.GetCoverThumbnailFromCache(item.CoverArtID); ok {
|
||||||
card.Cover.SetImage(img)
|
card.Cover.SetImage(img)
|
||||||
} else {
|
} else {
|
||||||
card.Cover.SetImageResource(res.ResAlbumplaceholderPng)
|
card.Cover.SetImage(nil)
|
||||||
// asynchronously fetch cover image
|
// asynchronously fetch cover image
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
card.ImgLoadCancel = cancel
|
card.ImgLoadCancel = cancel
|
||||||
@@ -263,8 +271,8 @@ func (g *GridView) doUpdateItemCard(itemIdx int, card *GridViewItem) {
|
|||||||
}(ctx)
|
}(ctx)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// use the placeholder image for an item that has no cover art ID
|
// use the placeholder for an item that has no cover art ID
|
||||||
card.Cover.SetImageResource(res.ResAlbumplaceholderPng)
|
card.Cover.SetImage(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user has scrolled near the bottom, fetch more
|
// if user has scrolled near the bottom, fetch more
|
||||||
|
|||||||
@@ -23,18 +23,18 @@ var _ fyne.SecondaryTappable = (*coverImage)(nil)
|
|||||||
type coverImage struct {
|
type coverImage struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
Im *canvas.Image
|
Im *ImagePlaceholder
|
||||||
playbtn *canvas.Image
|
playbtn *canvas.Image
|
||||||
OnPlay func()
|
OnPlay func()
|
||||||
OnShowPage func()
|
OnShowPage func()
|
||||||
OnShowContextMenu func(fyne.Position)
|
OnShowContextMenu func(fyne.Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCoverImage() *coverImage {
|
func newCoverImage(placeholderResource fyne.Resource) *coverImage {
|
||||||
c := &coverImage{}
|
c := &coverImage{}
|
||||||
c.ExtendBaseWidget(c)
|
c.ExtendBaseWidget(c)
|
||||||
c.Im = &canvas.Image{FillMode: canvas.ImageFillContain, ScaleMode: canvas.ImageScaleFastest}
|
c.Im = NewImagePlaceholder(placeholderResource, 200)
|
||||||
c.Im.SetMinSize(fyne.NewSize(200, 200))
|
c.Im.ScaleMode = canvas.ImageScaleFastest
|
||||||
c.playbtn = &canvas.Image{FillMode: canvas.ImageFillContain, Resource: res.ResPlaybuttonPng}
|
c.playbtn = &canvas.Image{FillMode: canvas.ImageFillContain, Resource: res.ResPlaybuttonPng}
|
||||||
c.playbtn.SetMinSize(fyne.NewSize(60, 60))
|
c.playbtn.SetMinSize(fyne.NewSize(60, 60))
|
||||||
c.playbtn.Hidden = true
|
c.playbtn.Hidden = true
|
||||||
@@ -93,15 +93,7 @@ func (a *coverImage) center() fyne.Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *coverImage) SetImage(im image.Image) {
|
func (a *coverImage) SetImage(im image.Image) {
|
||||||
a.Im.Resource = nil
|
a.Im.SetImage(im, false)
|
||||||
a.Im.Image = im
|
|
||||||
a.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *coverImage) SetImageResource(res *fyne.StaticResource) {
|
|
||||||
a.Im.Image = nil
|
|
||||||
a.Im.Resource = res
|
|
||||||
a.Refresh()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInside(origin fyne.Position, radius float32, point fyne.Position) bool {
|
func isInside(origin fyne.Position, radius float32, point fyne.Position) bool {
|
||||||
@@ -141,11 +133,11 @@ type GridViewItem struct {
|
|||||||
OnShowSecondaryPage func()
|
OnShowSecondaryPage func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGridViewItem() *GridViewItem {
|
func NewGridViewItem(placeholderResource fyne.Resource) *GridViewItem {
|
||||||
g := &GridViewItem{
|
g := &GridViewItem{
|
||||||
primaryText: NewCustomHyperlink(),
|
primaryText: NewCustomHyperlink(),
|
||||||
secondaryText: NewCustomHyperlink(),
|
secondaryText: NewCustomHyperlink(),
|
||||||
Cover: newCoverImage(),
|
Cover: newCoverImage(placeholderResource),
|
||||||
}
|
}
|
||||||
g.ExtendBaseWidget(g)
|
g.ExtendBaseWidget(g)
|
||||||
g.Cover.OnPlay = func() { g.onPlay(false) }
|
g.Cover.OnPlay = func() { g.onPlay(false) }
|
||||||
|
|||||||
@@ -2,48 +2,50 @@ package widgets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A widget that can display an image or else
|
// A widget that can display an image or else
|
||||||
// a placeholder with a rectangular border frame
|
// a placeholder with a rectangular border frame
|
||||||
// and an icon positioned in the center of the frame.
|
// and an icon positioned in the center of the frame.
|
||||||
type ImagePlaceholder struct {
|
type ImagePlaceholder struct {
|
||||||
|
ScaleMode canvas.ImageScale
|
||||||
|
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
container *fyne.Container
|
content *fyne.Container
|
||||||
|
imageDisp *TappableImage
|
||||||
image image.Image
|
image image.Image
|
||||||
|
iconImage *canvas.Image
|
||||||
|
border *myTheme.ThemedRectangle
|
||||||
minSize float32
|
minSize float32
|
||||||
|
|
||||||
OnTapped func()
|
OnTapped func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewImagePlaceholder(centerIcon fyne.Resource, minSize float32) *ImagePlaceholder {
|
func NewImagePlaceholder(centerIcon fyne.Resource, minSize float32) *ImagePlaceholder {
|
||||||
m := &ImagePlaceholder{minSize: minSize}
|
i := &ImagePlaceholder{minSize: minSize}
|
||||||
m.ExtendBaseWidget(m)
|
i.ExtendBaseWidget(i)
|
||||||
img := canvas.NewImageFromResource(centerIcon)
|
i.iconImage = canvas.NewImageFromResource(centerIcon)
|
||||||
img.FillMode = canvas.ImageFillContain
|
i.iconImage.FillMode = canvas.ImageFillContain
|
||||||
img.SetMinSize(fyne.NewSize(minSize/4, minSize/4))
|
i.iconImage.SetMinSize(fyne.NewSize(minSize/4, minSize/4))
|
||||||
rect := canvas.NewRectangle(theme.BackgroundColor())
|
i.imageDisp = NewTappableImage(i.onTapped)
|
||||||
rect.StrokeColor = color.Black
|
i.imageDisp.FillMode = canvas.ImageFillContain
|
||||||
rect.StrokeWidth = 3
|
i.imageDisp.Hidden = true
|
||||||
rect.SetMinSize(fyne.NewSize(minSize, minSize))
|
i.border = myTheme.NewThemedRectangle(theme.ColorNameBackground)
|
||||||
m.container = container.NewMax(
|
i.border.BorderColorName = theme.ColorNameForeground
|
||||||
rect,
|
i.border.BorderWidth = 3
|
||||||
container.NewCenter(img),
|
i.content = container.NewMax(
|
||||||
|
i.border,
|
||||||
|
container.NewCenter(i.iconImage),
|
||||||
|
i.imageDisp,
|
||||||
)
|
)
|
||||||
return m
|
return i
|
||||||
}
|
|
||||||
|
|
||||||
type CanvasImage interface {
|
|
||||||
fyne.CanvasObject
|
|
||||||
|
|
||||||
SetMinSize(fyne.Size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImagePlaceholder) HaveImage() bool {
|
func (i *ImagePlaceholder) HaveImage() bool {
|
||||||
@@ -51,22 +53,13 @@ func (i *ImagePlaceholder) HaveImage() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImagePlaceholder) SetImage(img image.Image, tappable bool) {
|
func (i *ImagePlaceholder) SetImage(img image.Image, tappable bool) {
|
||||||
var cIm CanvasImage
|
|
||||||
i.image = img
|
i.image = img
|
||||||
if tappable {
|
if img != nil {
|
||||||
cImg := NewTappableImage(i.onTapped)
|
i.imageDisp.DisableTapping = !tappable
|
||||||
cImg.Image.Image = img
|
i.imageDisp.Image.Image = img
|
||||||
cImg.FillMode = canvas.ImageFillContain
|
|
||||||
cIm = cImg
|
|
||||||
} else {
|
|
||||||
cImg := canvas.NewImageFromImage(img)
|
|
||||||
cImg.FillMode = canvas.ImageFillContain
|
|
||||||
cIm = cImg
|
|
||||||
}
|
}
|
||||||
cIm.SetMinSize(fyne.NewSize(i.minSize, i.minSize))
|
|
||||||
i.container.RemoveAll()
|
i.Refresh()
|
||||||
i.container.Add(cIm)
|
|
||||||
i.container.Refresh()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImagePlaceholder) Image() image.Image {
|
func (i *ImagePlaceholder) Image() image.Image {
|
||||||
@@ -79,6 +72,18 @@ func (i *ImagePlaceholder) onTapped() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImagePlaceholder) CreateRenderer() fyne.WidgetRenderer {
|
func (i *ImagePlaceholder) MinSize() fyne.Size {
|
||||||
return widget.NewSimpleRenderer(i.container)
|
return fyne.NewSize(i.minSize, i.minSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *ImagePlaceholder) Refresh() {
|
||||||
|
i.border.Hidden = i.HaveImage()
|
||||||
|
i.iconImage.Hidden = i.HaveImage()
|
||||||
|
i.imageDisp.Hidden = !i.HaveImage()
|
||||||
|
i.imageDisp.ScaleMode = i.ScaleMode
|
||||||
|
i.BaseWidget.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *ImagePlaceholder) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
return widget.NewSimpleRenderer(i.content)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ type TappableImage struct {
|
|||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
canvas.Image
|
canvas.Image
|
||||||
|
|
||||||
|
DisableTapping bool
|
||||||
OnTapped func()
|
OnTapped func()
|
||||||
OnTappedSecondary func(pos fyne.Position)
|
OnTappedSecondary func(pos fyne.Position)
|
||||||
}
|
}
|
||||||
@@ -85,20 +86,20 @@ func (t *TappableImage) Resize(size fyne.Size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TappableImage) Cursor() desktop.Cursor {
|
func (t *TappableImage) Cursor() desktop.Cursor {
|
||||||
if t.haveImage() {
|
if !t.DisableTapping && t.haveImage() {
|
||||||
return desktop.PointerCursor
|
return desktop.PointerCursor
|
||||||
}
|
}
|
||||||
return desktop.DefaultCursor
|
return desktop.DefaultCursor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TappableImage) Tapped(_ *fyne.PointEvent) {
|
func (t *TappableImage) Tapped(_ *fyne.PointEvent) {
|
||||||
if t.haveImage() && t.OnTapped != nil {
|
if !t.DisableTapping && t.haveImage() && t.OnTapped != nil {
|
||||||
t.OnTapped()
|
t.OnTapped()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TappableImage) TappedSecondary(e *fyne.PointEvent) {
|
func (t *TappableImage) TappedSecondary(e *fyne.PointEvent) {
|
||||||
if t.haveImage() && t.OnTappedSecondary != nil {
|
if !t.DisableTapping && t.haveImage() && t.OnTappedSecondary != nil {
|
||||||
t.OnTappedSecondary(e.AbsolutePosition)
|
t.OnTappedSecondary(e.AbsolutePosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user