2024-03-30 19:26:48 +01:00
|
|
|
package uilayout
|
|
|
|
|
|
|
|
import "fyne.io/fyne/v2"
|
|
|
|
|
2024-04-03 16:07:24 +02:00
|
|
|
// MinSize implements a min size layout.
|
|
|
|
//
|
|
|
|
// The MinSize layout will ensure that the container is rendered at a size that
|
|
|
|
// is at least as large as the minimum size provided.
|
2024-03-30 19:26:48 +01:00
|
|
|
type MinSize struct {
|
|
|
|
minSize fyne.Size
|
|
|
|
}
|
|
|
|
|
2024-04-03 16:07:24 +02:00
|
|
|
// NewMinSizeLayout creates a new MinSize layout with the specified minimum size.
|
|
|
|
//
|
|
|
|
// Arguments:
|
|
|
|
// - minSize: the minimum size for the layout.
|
|
|
|
//
|
|
|
|
// Returns *MinSize: a pointer to the newly created MinSize layout.
|
2024-03-30 19:26:48 +01:00
|
|
|
func NewMinSizeLayout(minSize fyne.Size) *MinSize {
|
|
|
|
return &MinSize{minSize: minSize}
|
|
|
|
}
|
|
|
|
|
2024-04-03 16:07:24 +02:00
|
|
|
// MinSize calculates the minimum size of the layout on the current screen. The
|
|
|
|
// reported size will be at least as large as the configured minimum size.
|
2024-03-30 19:26:48 +01:00
|
|
|
func (l *MinSize) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
|
|
|
size := l.minSize
|
|
|
|
for _, o := range objects {
|
|
|
|
childSize := o.MinSize()
|
|
|
|
if size.Width < childSize.Width {
|
|
|
|
size.Width = childSize.Width
|
|
|
|
}
|
|
|
|
if size.Height < childSize.Height {
|
|
|
|
size.Height = childSize.Height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2024-04-03 16:07:24 +02:00
|
|
|
// Layout implements the Layout interface.
|
2024-03-30 19:26:48 +01:00
|
|
|
func (l *MinSize) Layout(objects []fyne.CanvasObject, containerSize fyne.Size) {
|
|
|
|
pos := fyne.NewPos(0, 0)
|
|
|
|
for _, o := range objects {
|
|
|
|
o.Resize(containerSize)
|
|
|
|
o.Move(pos)
|
|
|
|
}
|
|
|
|
}
|