Specific commits ported, to update the layouts and reduce differences with upstream Fyne code: * https://github.com/fyne-io/fyne/commit/a9a66f60d2167d7945bcf7718a781335541317c0 * https://github.com/fyne-io/fyne/commit/2cde868904092382ca5f645802ee9d444d8ae6e8 * https://github.com/fyne-io/fyne/commit/99fa7e3a7dc83dd273ad366cc7d336a1e1cee5f6 * https://github.com/fyne-io/fyne/commit/4ea8a5762f1744401ede9f7bd35b3b75890f925e
39 lines
902 B
Go
39 lines
902 B
Go
package layouts
|
|
|
|
import "fyne.io/fyne/v2"
|
|
|
|
var _ fyne.Layout = (*MaxPadLayout)(nil)
|
|
|
|
type MaxPadLayout struct {
|
|
PadLeft float32
|
|
PadRight float32
|
|
PadTop float32
|
|
PadBottom float32
|
|
}
|
|
|
|
// only supports one object
|
|
func (c *MaxPadLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
|
if len(objects) == 0 {
|
|
return fyne.NewSize(c.PadLeft+c.PadRight, c.PadTop+c.PadBottom)
|
|
}
|
|
return fyne.Size{
|
|
Width: objects[0].MinSize().Width + c.PadLeft + c.PadRight,
|
|
Height: objects[0].MinSize().Height + c.PadTop + c.PadBottom,
|
|
}
|
|
}
|
|
|
|
func (c *MaxPadLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
|
if len(objects) == 0 {
|
|
return
|
|
}
|
|
pos := fyne.NewPos(c.PadLeft, c.PadTop)
|
|
objSize := fyne.NewSize(size.Width-c.PadLeft-c.PadRight, size.Height-c.PadTop-c.PadBottom)
|
|
for _, child := range objects {
|
|
if !child.Visible() {
|
|
continue
|
|
}
|
|
child.Move(pos)
|
|
child.Resize(objSize)
|
|
}
|
|
}
|