add play btn to album page + layout adj.
This commit is contained in:
+18
-6
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/util"
|
||||
"supersonic/ui/widgets"
|
||||
|
||||
@@ -33,8 +34,10 @@ type AlbumPage struct {
|
||||
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.ExtendBaseWidget(a)
|
||||
a.header = NewAlbumPageHeader(nav)
|
||||
a.container = container.NewBorder(a.header, nil, nil, nil, layout.NewSpacer())
|
||||
a.header = NewAlbumPageHeader(a)
|
||||
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()
|
||||
return a
|
||||
}
|
||||
@@ -67,7 +70,7 @@ func (a *AlbumPage) loadAsync() {
|
||||
a.header.Update(album, a.im)
|
||||
tl := widgets.NewTracklist(album.Song)
|
||||
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()
|
||||
}()
|
||||
}
|
||||
@@ -84,10 +87,12 @@ type AlbumPageHeader struct {
|
||||
genreLabel *widget.Label // later custom hyperlink
|
||||
miscLabel *widget.Label
|
||||
|
||||
playButton *widget.Button
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewAlbumPageHeader(nav func(Route)) *AlbumPageHeader {
|
||||
func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
||||
a := &AlbumPageHeader{}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.cover = &canvas.Image{FillMode: canvas.ImageFillContain}
|
||||
@@ -99,13 +104,20 @@ func NewAlbumPageHeader(nav func(Route)) *AlbumPageHeader {
|
||||
}
|
||||
a.artistLabel = widgets.NewCustomHyperlink()
|
||||
a.artistLabel.OnTapped = func() {
|
||||
nav(ArtistRoute(a.artistID))
|
||||
page.nav(ArtistRoute(a.artistID))
|
||||
}
|
||||
a.genreLabel = 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,
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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