first commit

This commit is contained in:
Drew Weymouth
2022-12-17 16:52:13 -08:00
parent cd1f795bb4
commit c21d7d03eb
16 changed files with 2069 additions and 0 deletions
+39
View File
@@ -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())
}
}