maxlayout.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Package layout defines the various layouts available to Fyne apps.
  2. package layout // import "fyne.io/fyne/v2/layout"
  3. import "fyne.io/fyne/v2"
  4. // Declare conformity with Layout interface
  5. var _ fyne.Layout = (*maxLayout)(nil)
  6. type maxLayout struct {
  7. }
  8. // NewMaxLayout creates a new MaxLayout instance
  9. func NewMaxLayout() fyne.Layout {
  10. return &maxLayout{}
  11. }
  12. // Layout is called to pack all child objects into a specified size.
  13. // For MaxLayout this sets all children to the full size passed.
  14. func (m *maxLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
  15. topLeft := fyne.NewPos(0, 0)
  16. for _, child := range objects {
  17. child.Resize(size)
  18. child.Move(topLeft)
  19. }
  20. }
  21. // MinSize finds the smallest size that satisfies all the child objects.
  22. // For MaxLayout this is determined simply as the MinSize of the largest child.
  23. func (m *maxLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
  24. minSize := fyne.NewSize(0, 0)
  25. for _, child := range objects {
  26. if !child.Visible() {
  27. continue
  28. }
  29. minSize = minSize.Max(child.MinSize())
  30. }
  31. return minSize
  32. }