diff --git a/examples/dialogLayout/main.go b/examples/dialogLayout/main.go index d2bc039..736c817 100644 --- a/examples/dialogLayout/main.go +++ b/examples/dialogLayout/main.go @@ -16,7 +16,7 @@ func run () { container := basic.NewContainer(layouts.Dialog { true, true }) window.Adopt(container) - container.Adopt(basic.NewLabel("you will explode", false), true) + container.Adopt(basic.NewLabel("you will explode", true), true) cancel := basic.NewButton("Cancel") cancel.SetEnabled(false) container.Adopt(cancel, false) diff --git a/layouts/dialog.go b/layouts/dialog.go index f7915b9..f662129 100644 --- a/layouts/dialog.go +++ b/layouts/dialog.go @@ -28,7 +28,7 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) { controlRowWidth, controlRowHeight := 0, 0 if len(entries) > 1 { controlRowWidth, - controlRowHeight = layout.minimumSizeOf(entries[1:]) + controlRowHeight = layout.minimumSizeOfControlRow(entries[1:]) } if len(entries) > 0 { @@ -108,7 +108,6 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, width, height int) { // arrange the given list of entries. func (layout Dialog) MinimumSize ( entries []tomo.LayoutEntry, - squeeze int, ) ( width, height int, ) { @@ -121,7 +120,7 @@ func (layout Dialog) MinimumSize ( if len(entries) > 1 { if layout.Gap { height += theme.Padding() } additionalWidth, - additionalHeight := layout.minimumSizeOf(entries[1:]) + additionalHeight := layout.minimumSizeOfControlRow(entries[1:]) height += additionalHeight if additionalWidth > width { width = additionalWidth @@ -135,7 +134,41 @@ func (layout Dialog) MinimumSize ( return } -func (layout Dialog) minimumSizeOf ( +func (layout Dialog) MinimumHeightFor ( + entries []tomo.LayoutEntry, + width int, +) ( + height int, +) { + if layout.Pad { + width -= theme.Padding() * 2 + } + + if len(entries) > 0 { + mainChildHeight := 0 + if child, flexible := entries[0].Element.(tomo.Flexible); flexible { + mainChildHeight = child.MinimumHeightFor(width) + } else { + _, mainChildHeight = entries[0].MinimumSize() + } + height += mainChildHeight + } + + if len(entries) > 1 { + if layout.Gap { height += theme.Padding() } + _, additionalHeight := layout.minimumSizeOfControlRow(entries[1:]) + height += additionalHeight + } + + if layout.Pad { + height += theme.Padding() * 2 + } + return +} + +// TODO: possibly flatten this method to account for flexible elements within +// the control row. +func (layout Dialog) minimumSizeOfControlRow ( entries []tomo.LayoutEntry, ) ( width, height int,