first commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package layout
|
||||
|
||||
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,50 @@
|
||||
package layout
|
||||
|
||||
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