add cover and details to album page
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package layouts
|
||||
|
||||
import "fyne.io/fyne/v2"
|
||||
|
||||
type ColumnsLayout struct {
|
||||
ColumnWidths []float32
|
||||
}
|
||||
|
||||
func NewColumnsLayout(widths []float32) *ColumnsLayout {
|
||||
return &ColumnsLayout{ColumnWidths: widths}
|
||||
}
|
||||
|
||||
func (c *ColumnsLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
var width float32
|
||||
var height float32
|
||||
for i := 0; i < len(objects); i++ {
|
||||
if !objects[i].Visible() {
|
||||
continue
|
||||
}
|
||||
height = fyne.Max(height, objects[i].MinSize().Height)
|
||||
w := objects[i].MinSize().Width
|
||||
if i < len(c.ColumnWidths) && c.ColumnWidths[i] > w {
|
||||
w = c.ColumnWidths[i]
|
||||
}
|
||||
width += w
|
||||
}
|
||||
return fyne.NewSize(width, height)
|
||||
}
|
||||
|
||||
func (c *ColumnsLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
var fixedW float32
|
||||
var expandObjCount int
|
||||
for i := 0; i < min(len(objects), len(c.ColumnWidths)); i++ {
|
||||
if !objects[i].Visible() {
|
||||
continue
|
||||
}
|
||||
if c.ColumnWidths[i] < 0 {
|
||||
expandObjCount++
|
||||
} else {
|
||||
itemW := objects[i].MinSize().Width
|
||||
fixedW += fyne.Max(itemW, c.ColumnWidths[i])
|
||||
}
|
||||
}
|
||||
extraW := size.Width - fixedW
|
||||
expandObjW := extraW / float32(expandObjCount)
|
||||
|
||||
var x float32
|
||||
for i := 0; i < len(objects); i++ {
|
||||
w := objects[i].MinSize().Width
|
||||
if i < len(c.ColumnWidths) && c.ColumnWidths[i] > w {
|
||||
w = c.ColumnWidths[i]
|
||||
} else if c.ColumnWidths[i] < 0 && expandObjW > w {
|
||||
w = expandObjW
|
||||
}
|
||||
objects[i].Resize(fyne.NewSize(w, size.Height))
|
||||
objects[i].Move(fyne.NewPos(x, 0))
|
||||
x += w
|
||||
}
|
||||
}
|
||||
|
||||
func min(x, y int) int {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package layouts
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
)
|
||||
|
||||
var _ fyne.Layout = (*VboxCustomPadding)(nil)
|
||||
|
||||
type VboxCustomPadding struct {
|
||||
ExtraPad float32
|
||||
}
|
||||
|
||||
func (v *VboxCustomPadding) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||
minSize := fyne.NewSize(0, 0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
|
||||
minSize.Width = fyne.Max(child.MinSize().Width, minSize.Width)
|
||||
minSize.Height += child.MinSize().Height
|
||||
}
|
||||
minSize.Height += (theme.Padding() + v.ExtraPad) * float32(len(objects)-1)
|
||||
return minSize
|
||||
}
|
||||
|
||||
func (v *VboxCustomPadding) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||
total := float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
total += child.MinSize().Height
|
||||
}
|
||||
|
||||
x, y := float32(0), float32(0)
|
||||
|
||||
extra := float32(0)
|
||||
for _, child := range objects {
|
||||
if !child.Visible() {
|
||||
continue
|
||||
}
|
||||
height := child.MinSize().Height
|
||||
child.Move(fyne.NewPos(x, y+extra))
|
||||
y += height
|
||||
child.Resize(fyne.NewSize(size.Width, height))
|
||||
extra += (theme.Padding() + v.ExtraPad)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user