onboard to new custom padded box layouts
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
@@ -280,10 +279,10 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
||||
// TODO: there's got to be a way to make this less convoluted. Custom layout?
|
||||
a.container = util.AddHeaderBackground(
|
||||
container.NewBorder(nil, nil, a.cover, nil,
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-10),
|
||||
a.titleLabel,
|
||||
container.NewVBox(
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -12}, artistReleaseTypeLine, a.genreLabel, a.miscLabel),
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-12), artistReleaseTypeLine, a.genreLabel, a.miscLabel),
|
||||
container.NewVBox(
|
||||
container.NewHBox(util.NewHSpace(2), playButton, shuffleBtn, menuBtn),
|
||||
container.NewHBox(util.NewHSpace(2), a.toggleFavButton),
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
@@ -448,7 +447,7 @@ func (a *ArtistPageHeader) createContainer() {
|
||||
a.container = util.AddHeaderBackground(
|
||||
container.NewBorder(nil, nil, a.artistImage, nil,
|
||||
container.NewVBox(
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-10),
|
||||
a.titleDisp, a.biographyDisp, a.similarArtists),
|
||||
btnContainer),
|
||||
))
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
@@ -291,7 +290,7 @@ func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
||||
|
||||
a.container = util.AddHeaderBackground(
|
||||
container.NewBorder(nil, nil, a.image, nil,
|
||||
container.NewVBox(a.titleLabel, container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
|
||||
container.NewVBox(a.titleLabel, container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-10),
|
||||
a.descriptionLabel,
|
||||
a.ownerLabel,
|
||||
a.trackTimeLabel),
|
||||
|
||||
@@ -69,7 +69,7 @@ func (a *AboutDialog) buildMainTabContainer(version string) *fyne.Container {
|
||||
ghUrl, _ := url.Parse(res.GithubURL)
|
||||
kofiUrl, _ := url.Parse(res.KofiURL)
|
||||
githubKofi := container.NewCenter(
|
||||
container.New(&layouts.HboxCustomPadding{DisableThemePad: true, ExtraPad: -10},
|
||||
container.New(layout.NewCustomPaddedHBoxLayout(-10),
|
||||
widget.NewHyperlink("Github page", ghUrl),
|
||||
widget.NewLabel("·"),
|
||||
widget.NewHyperlink("Support the project", kofiUrl)),
|
||||
@@ -77,7 +77,7 @@ func (a *AboutDialog) buildMainTabContainer(version string) *fyne.Container {
|
||||
|
||||
return container.New(&layouts.CenterPadLayout{PadTopBottom: 10},
|
||||
container.NewVBox(iconImage,
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -10}, title, versionLbl, copyright, license, githubKofi)))
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-10), title, versionLbl, copyright, license, githubKofi)))
|
||||
}
|
||||
|
||||
func (a *AboutDialog) licenseLabel(res *fyne.StaticResource) *widget.Label {
|
||||
@@ -94,7 +94,7 @@ func (a *AboutDialog) buildCreditsContainer() fyne.CanvasObject {
|
||||
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.Wrapping = fyne.TextWrapWord
|
||||
return container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
|
||||
return container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-10),
|
||||
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("go-subsonic", goSubsonicURL), widget.NewLabel("GPL v3 License")),
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
@@ -111,7 +110,7 @@ func (a *AlbumInfoDialog) buildUrlContainer(lastFm, musicBrainzID string) *fyne.
|
||||
}
|
||||
}
|
||||
|
||||
urlContainer := container.New(&layouts.HboxCustomPadding{DisableThemePad: true, ExtraPad: -10})
|
||||
urlContainer := container.New(layout.NewCustomPaddedHBoxLayout(-10))
|
||||
for index, url := range urls {
|
||||
if index > 0 {
|
||||
urlContainer.Add(widget.NewLabel("·"))
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
@@ -317,7 +316,7 @@ func (q *searchResult) Tapped(_ *fyne.PointEvent) {
|
||||
func (q *searchResult) CreateRenderer() fyne.WidgetRenderer {
|
||||
if q.content == nil {
|
||||
q.content = container.NewBorder(nil, nil, container.NewCenter(q.image), nil,
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -15},
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-15),
|
||||
q.title,
|
||||
q.secondary,
|
||||
))
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package layouts
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
)
|
||||
|
||||
var _ fyne.Layout = (*HboxCustomPadding)(nil)
|
||||
|
||||
type HboxCustomPadding struct {
|
||||
ExtraPad float32
|
||||
DisableThemePad bool
|
||||
}
|
||||
|
||||
func (*HboxCustomPadding) isSpacer(obj fyne.CanvasObject) bool {
|
||||
spacer, ok := obj.(layout.SpacerObject)
|
||||
return ok && spacer.ExpandHorizontal()
|
||||
}
|
||||
|
||||
func (h *HboxCustomPadding) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
minSize := fyne.NewSize(0, 0)
|
||||
addPadding := false
|
||||
padding := h.themePad() + h.ExtraPad
|
||||
for _, child := range objects {
|
||||
if !child.Visible() || h.isSpacer(child) {
|
||||
continue
|
||||
}
|
||||
|
||||
childMin := child.MinSize()
|
||||
minSize.Height = fyne.Max(childMin.Height, minSize.Height)
|
||||
minSize.Width += childMin.Width
|
||||
if addPadding {
|
||||
minSize.Width += padding
|
||||
}
|
||||
addPadding = true
|
||||
}
|
||||
return minSize
|
||||
}
|
||||
|
||||
func (h *HboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
spacers := 0
|
||||
visibleObjects := 0
|
||||
// Size taken up by visible objects
|
||||
total := float32(0)
|
||||
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
if h.isSpacer(child) {
|
||||
spacers++
|
||||
continue
|
||||
}
|
||||
|
||||
visibleObjects++
|
||||
total += child.MinSize().Width
|
||||
}
|
||||
|
||||
padding := h.themePad() + h.ExtraPad
|
||||
|
||||
// Amount of space not taken up by visible objects and inter-object padding
|
||||
extra := size.Width - total - (padding * float32(visibleObjects-1))
|
||||
|
||||
// Spacers split extra space equally
|
||||
spacerSize := float32(0)
|
||||
if spacers > 0 {
|
||||
spacerSize = extra / float32(spacers)
|
||||
}
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
if h.isSpacer(child) {
|
||||
x += spacerSize
|
||||
continue
|
||||
}
|
||||
child.Move(fyne.NewPos(x, y))
|
||||
|
||||
width := child.MinSize().Width
|
||||
x += padding + width
|
||||
child.Resize(fyne.NewSize(width, size.Height))
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HboxCustomPadding) themePad() float32 {
|
||||
if h.DisableThemePad {
|
||||
return 0
|
||||
}
|
||||
return theme.Padding()
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package layouts
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
)
|
||||
|
||||
var _ fyne.Layout = (*VboxCustomPadding)(nil)
|
||||
|
||||
type VboxCustomPadding struct {
|
||||
ExtraPad float32
|
||||
}
|
||||
|
||||
func (*VboxCustomPadding) isSpacer(obj fyne.CanvasObject) bool {
|
||||
spacer, ok := obj.(layout.SpacerObject)
|
||||
return ok && spacer.ExpandVertical()
|
||||
}
|
||||
|
||||
func (v *VboxCustomPadding) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
minSize := fyne.NewSize(0, 0)
|
||||
addPadding := false
|
||||
padding := theme.Padding() + v.ExtraPad
|
||||
for _, child := range objects {
|
||||
if !child.Visible() || v.isSpacer(child) {
|
||||
continue
|
||||
}
|
||||
|
||||
childMin := child.MinSize()
|
||||
minSize.Width = fyne.Max(childMin.Width, minSize.Width)
|
||||
minSize.Height += childMin.Height
|
||||
if addPadding {
|
||||
minSize.Height += padding
|
||||
}
|
||||
addPadding = true
|
||||
}
|
||||
return minSize
|
||||
}
|
||||
|
||||
func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
spacers := 0
|
||||
visibleObjects := 0
|
||||
// Size taken up by visible objects
|
||||
total := float32(0)
|
||||
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.isSpacer(child) {
|
||||
spacers++
|
||||
continue
|
||||
}
|
||||
|
||||
visibleObjects++
|
||||
total += child.MinSize().Height
|
||||
}
|
||||
|
||||
padding := theme.Padding() + v.ExtraPad
|
||||
|
||||
// Amount of space not taken up by visible objects and inter-object padding
|
||||
extra := size.Height - total - (padding * float32(visibleObjects-1))
|
||||
|
||||
// Spacers split extra space equally
|
||||
spacerSize := float32(0)
|
||||
if spacers > 0 {
|
||||
spacerSize = extra / float32(spacers)
|
||||
}
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.isSpacer(child) {
|
||||
y += spacerSize
|
||||
continue
|
||||
}
|
||||
child.Move(fyne.NewPos(x, y))
|
||||
|
||||
height := child.MinSize().Height
|
||||
y += padding + height
|
||||
child.Resize(fyne.NewSize(size.Width, height))
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
@@ -195,11 +196,11 @@ func NewGridViewItem(placeholderResource fyne.Resource) *GridViewItem {
|
||||
}
|
||||
|
||||
func (g *GridViewItem) createContainer() {
|
||||
info := container.New(&layouts.VboxCustomPadding{ExtraPad: -16}, g.primaryText, g.secondaryText)
|
||||
info := container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-16), g.primaryText, g.secondaryText)
|
||||
g.focusRect = canvas.NewRectangle(color.Transparent)
|
||||
g.focusRect.StrokeWidth = 3
|
||||
coverStack := container.NewStack(g.Cover, g.focusRect)
|
||||
c := container.New(&layouts.VboxCustomPadding{ExtraPad: -5}, coverStack, info)
|
||||
c := container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-5), coverStack, info)
|
||||
pad := &layouts.CenterPadLayout{PadLeftRight: 20, PadTopBottom: 10}
|
||||
g.container = container.New(pad, c)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
)
|
||||
|
||||
@@ -50,7 +49,7 @@ func NewLargeNowPlayingCard() *LargeNowPlayingCard {
|
||||
n.cover.ScaleMode = canvas.ImageScaleFastest
|
||||
// set up the layout
|
||||
n.Content = n.cover
|
||||
n.Caption = container.New(&layouts.VboxCustomPadding{ExtraPad: -13},
|
||||
n.Caption = container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-13),
|
||||
n.trackName,
|
||||
n.artistName,
|
||||
n.albumName,
|
||||
|
||||
@@ -135,7 +135,7 @@ func (l *ListHeader) TappedSecondary(e *fyne.PointEvent) {
|
||||
|
||||
func (l *ListHeader) setupPopUpMenu() {
|
||||
if l.popUpMenu == nil {
|
||||
l.popUpMenu = container.New(&layouts.VboxCustomPadding{ExtraPad: -10})
|
||||
l.popUpMenu = container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding() - 10))
|
||||
for i, c := range l.columns {
|
||||
if c.CanToggleVisible {
|
||||
l.popUpMenu.Add(widget.NewCheck(c.Text, l.createOnChangedCallbk(i)))
|
||||
@@ -258,7 +258,7 @@ func (c *colHeader) Refresh() {
|
||||
|
||||
func (c *colHeader) CreateRenderer() fyne.WidgetRenderer {
|
||||
if c.container == nil {
|
||||
c.container = container.New(&layouts.HboxCustomPadding{DisableThemePad: true, ExtraPad: -8})
|
||||
c.container = container.New(layout.NewCustomPaddedHBoxLayout(-8))
|
||||
if c.columnCfg.Alignment != fyne.TextAlignLeading {
|
||||
c.container.Add(layout.NewSpacer())
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"image"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
|
||||
@@ -12,6 +11,7 @@ import (
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (n *NowPlayingCard) CreateRenderer() fyne.WidgetRenderer {
|
||||
c := container.New(&layout.CustomPaddedLayout{LeftPadding: -4},
|
||||
container.NewBorder(nil, nil, n.cover, nil,
|
||||
container.New(&layout.CustomPaddedLayout{TopPadding: -2},
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -13}, n.trackName, n.artistName, n.albumName))),
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-13), n.trackName, n.artistName, n.albumName))),
|
||||
)
|
||||
return widget.NewSimpleRenderer(c)
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ func NewPlayQueueListRow(playQueueList *PlayQueueList, im *backend.ImageManager,
|
||||
p.Content = container.New(playQueueList.colLayout,
|
||||
container.NewCenter(p.num),
|
||||
container.NewPadded(p.cover),
|
||||
container.New(&layouts.VboxCustomPadding{ExtraPad: -15},
|
||||
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-15),
|
||||
p.title, p.artist),
|
||||
container.NewCenter(p.time),
|
||||
)
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/dweymouth/supersonic/res"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
@@ -43,9 +43,7 @@ func NewStarRating() *StarRating {
|
||||
}
|
||||
|
||||
func (s *StarRating) createContainer() {
|
||||
s.container = container.New(&layouts.HboxCustomPadding{
|
||||
DisableThemePad: true,
|
||||
})
|
||||
s.container = container.New(layout.NewCustomPaddedHBoxLayout(0))
|
||||
var im *canvas.Image
|
||||
for i := 0; i < 5; i++ {
|
||||
if s.IsDisabled {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -22,7 +21,7 @@ type ToggleButtonGroup struct {
|
||||
func NewToggleButtonGroup(activatedBtnIdx int, buttons ...*widget.Button) *ToggleButtonGroup {
|
||||
t := &ToggleButtonGroup{}
|
||||
t.ExtendBaseWidget(t)
|
||||
t.buttonContainer = container.New(&layouts.HboxCustomPadding{DisableThemePad: true})
|
||||
t.buttonContainer = container.New(layout.NewCustomPaddedHBoxLayout(0))
|
||||
for i, b := range buttons {
|
||||
b.Importance = widget.MediumImportance
|
||||
t.buttonContainer.Add(b)
|
||||
|
||||
Reference in New Issue
Block a user