remove redundant CenterPad layout

This commit is contained in:
Drew Weymouth
2024-05-24 17:07:44 -07:00
parent 819f42dac0
commit ceed42dcf2
4 changed files with 4 additions and 47 deletions
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"net/url"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/ui/layouts"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
@@ -75,7 +74,7 @@ func (a *AboutDialog) buildMainTabContainer(version string) *fyne.Container {
widget.NewHyperlink("Support the project", kofiUrl)),
)
return container.New(&layouts.CenterPadLayout{PadTopBottom: 10},
return container.New(&layout.CustomPaddedLayout{TopPadding: 10, BottomPadding: 10},
container.NewVBox(iconImage,
container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-10), title, versionLbl, copyright, license, githubKofi)))
}
-39
View File
@@ -1,39 +0,0 @@
package layouts
import (
"fyne.io/fyne/v2"
)
var _ fyne.Layout = (*CenterPadLayout)(nil)
type CenterPadLayout struct {
PadLeftRight float32
PadTopBottom float32
}
// only supports one object
func (c *CenterPadLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
if len(objects) == 0 {
return fyne.NewSize(0, 0)
}
return fyne.Size{
Width: objects[0].MinSize().Width + c.PadLeftRight*2,
Height: objects[0].MinSize().Height + c.PadTopBottom*2,
}
}
func (c *CenterPadLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
if len(objects) == 0 {
return
}
objSize := objects[0].MinSize()
xOffs := (size.Width - objSize.Width) / 2
yOffs := (size.Height - objSize.Height) / 2
for _, child := range objects {
if !child.Visible() {
continue
}
child.Move(fyne.NewPos(xOffs, yOffs))
child.Resize(child.MinSize())
}
}
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"slices"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/ui/layouts"
"github.com/dweymouth/supersonic/ui/util"
"fyne.io/fyne/v2"
@@ -201,7 +200,7 @@ func (g *GridViewItem) createContainer() {
g.focusRect.StrokeWidth = 3
coverStack := container.NewStack(g.Cover, g.focusRect)
c := container.New(layout.NewCustomPaddedVBoxLayout(theme.Padding()-5), coverStack, info)
pad := &layouts.CenterPadLayout{PadLeftRight: 20, PadTopBottom: 10}
pad := layout.NewCustomPaddedLayout(10, 10, 20, 20)
g.container = container.New(pad, c)
}
+2 -4
View File
@@ -9,9 +9,9 @@ import (
"fyne.io/fyne/v2"
"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"
"github.com/dweymouth/supersonic/ui/layouts"
)
type LoadingDots struct {
@@ -92,9 +92,7 @@ func (l *LoadingDots) doTick(foreground, disabled color.Color) {
func (l *LoadingDots) CreateRenderer() fyne.WidgetRenderer {
if l.container == nil {
layout := &layouts.CenterPadLayout{
PadLeftRight: 3,
}
layout := layout.NewCustomPaddedLayout(0, 0, 3, 3)
l.container = container.NewHBox(
container.New(layout, &l.dots[0]),
container.New(layout, &l.dots[1]),