46 lines
801 B
Go
46 lines
801 B
Go
package uilayout
|
|
|
|
import "fyne.io/fyne/v2"
|
|
|
|
type Margin struct {
|
|
top float32
|
|
bottom float32
|
|
left float32
|
|
right float32
|
|
}
|
|
|
|
func NewMargin(
|
|
top, bottom, left, right float32,
|
|
) *Margin {
|
|
return &Margin{
|
|
top: top,
|
|
bottom: bottom,
|
|
left: left,
|
|
right: right,
|
|
}
|
|
}
|
|
|
|
func (m *Margin) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
|
w := m.left + m.right
|
|
h := m.top + m.bottom
|
|
if len(objects) > 0 {
|
|
w += objects[0].MinSize().Width
|
|
h += objects[0].MinSize().Height
|
|
}
|
|
return fyne.NewSize(w, h)
|
|
}
|
|
|
|
func (m *Margin) Layout(
|
|
objects []fyne.CanvasObject,
|
|
containerSize fyne.Size,
|
|
) {
|
|
pos := fyne.NewPos(m.left, m.top)
|
|
if len(objects) > 0 {
|
|
o := objects[0]
|
|
size := containerSize.Subtract(
|
|
fyne.NewSize(m.left+m.right, m.top+m.bottom))
|
|
o.Resize(size)
|
|
o.Move(pos)
|
|
}
|
|
}
|