add play btn to album page + layout adj.
This commit is contained in:
+18
-6
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
|
"supersonic/ui/layouts"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
|
|
||||||
@@ -33,8 +34,10 @@ type AlbumPage struct {
|
|||||||
func NewAlbumPage(albumID string, lm *backend.LibraryManager, im *backend.ImageManager, nav func(Route)) *AlbumPage {
|
func NewAlbumPage(albumID string, lm *backend.LibraryManager, im *backend.ImageManager, nav func(Route)) *AlbumPage {
|
||||||
a := &AlbumPage{albumID: albumID, lm: lm, im: im, nav: nav}
|
a := &AlbumPage{albumID: albumID, lm: lm, im: im, nav: nav}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.header = NewAlbumPageHeader(nav)
|
a.header = NewAlbumPageHeader(a)
|
||||||
a.container = container.NewBorder(a.header, nil, nil, nil, layout.NewSpacer())
|
a.container = container.NewBorder(
|
||||||
|
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
||||||
|
nil, nil, nil, layout.NewSpacer())
|
||||||
a.loadAsync()
|
a.loadAsync()
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
@@ -67,7 +70,7 @@ func (a *AlbumPage) loadAsync() {
|
|||||||
a.header.Update(album, a.im)
|
a.header.Update(album, a.im)
|
||||||
tl := widgets.NewTracklist(album.Song)
|
tl := widgets.NewTracklist(album.Song)
|
||||||
tl.OnPlayTrackAt = a.onPlayTrackAt
|
tl.OnPlayTrackAt = a.onPlayTrackAt
|
||||||
a.container.Objects[0] = tl
|
a.container.Objects[0] = container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadBottom: 15}, tl)
|
||||||
a.container.Refresh()
|
a.container.Refresh()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -84,10 +87,12 @@ type AlbumPageHeader struct {
|
|||||||
genreLabel *widget.Label // later custom hyperlink
|
genreLabel *widget.Label // later custom hyperlink
|
||||||
miscLabel *widget.Label
|
miscLabel *widget.Label
|
||||||
|
|
||||||
|
playButton *widget.Button
|
||||||
|
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAlbumPageHeader(nav func(Route)) *AlbumPageHeader {
|
func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
||||||
a := &AlbumPageHeader{}
|
a := &AlbumPageHeader{}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.cover = &canvas.Image{FillMode: canvas.ImageFillContain}
|
a.cover = &canvas.Image{FillMode: canvas.ImageFillContain}
|
||||||
@@ -99,13 +104,20 @@ func NewAlbumPageHeader(nav func(Route)) *AlbumPageHeader {
|
|||||||
}
|
}
|
||||||
a.artistLabel = widgets.NewCustomHyperlink()
|
a.artistLabel = widgets.NewCustomHyperlink()
|
||||||
a.artistLabel.OnTapped = func() {
|
a.artistLabel.OnTapped = func() {
|
||||||
nav(ArtistRoute(a.artistID))
|
page.nav(ArtistRoute(a.artistID))
|
||||||
}
|
}
|
||||||
a.genreLabel = widget.NewLabel("")
|
a.genreLabel = widget.NewLabel("")
|
||||||
a.miscLabel = widget.NewLabel("")
|
a.miscLabel = widget.NewLabel("")
|
||||||
|
a.playButton = widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
|
||||||
|
page.onPlayTrackAt(0)
|
||||||
|
})
|
||||||
|
|
||||||
a.container = container.NewBorder(nil, nil, a.cover, nil,
|
a.container = container.NewBorder(nil, nil, a.cover, nil,
|
||||||
container.NewVBox(a.titleLabel, a.artistLabel, a.genreLabel, a.miscLabel),
|
container.NewVBox(
|
||||||
|
a.titleLabel,
|
||||||
|
container.New(&layouts.VboxCustomPadding{ExtraPad: -10}, a.artistLabel, a.genreLabel, a.miscLabel),
|
||||||
|
container.NewHBox(a.playButton),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package layouts
|
||||||
|
|
||||||
|
import "fyne.io/fyne/v2"
|
||||||
|
|
||||||
|
var _ fyne.Layout = (*CenterPadLayout)(nil)
|
||||||
|
|
||||||
|
type MaxPadLayout struct {
|
||||||
|
PadLeft float32
|
||||||
|
PadRight float32
|
||||||
|
PadTop float32
|
||||||
|
PadBottom float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// only supports one object
|
||||||
|
func (c *MaxPadLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||||
|
if len(objects) == 0 {
|
||||||
|
return fyne.NewSize(c.PadLeft+c.PadRight, c.PadTop+c.PadBottom)
|
||||||
|
}
|
||||||
|
return fyne.Size{
|
||||||
|
Width: objects[0].MinSize().Width + c.PadLeft + c.PadRight,
|
||||||
|
Height: objects[0].MinSize().Height + c.PadTop + c.PadBottom,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MaxPadLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||||
|
if len(objects) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, child := range objects {
|
||||||
|
if !child.Visible() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
child.Move(fyne.NewPos(c.PadLeft, c.PadTop))
|
||||||
|
child.Resize(fyne.NewSize(size.Width-c.PadLeft-c.PadRight, size.Height-c.PadTop-c.PadBottom))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user