Horizontal layouts now take into account flexible elements

This commit is contained in:
2023-01-16 23:58:20 -05:00
parent e94e170a04
commit 9459bcd942
3 changed files with 33 additions and 7 deletions

View File

@@ -72,7 +72,6 @@ func (layout Horizontal) Arrange (entries []tomo.LayoutEntry, width, height int)
// arrange the given list of entries.
func (layout Horizontal) MinimumSize (
entries []tomo.LayoutEntry,
squeeze int,
) (
width, height int,
) {
@@ -93,3 +92,31 @@ func (layout Horizontal) MinimumSize (
}
return
}
func (layout Horizontal) MinimumHeightFor (
entries []tomo.LayoutEntry,
width int,
) (
height int,
) {
if layout.Pad {
width -= theme.Padding() * 2
}
for _, entry := range entries {
var entryHeight int
if child, flexible := entry.Element.(tomo.Flexible); flexible {
entryHeight = child.MinimumHeightFor(width)
} else {
_, entryHeight = entry.MinimumSize()
}
if entryHeight > height {
height = entryHeight
}
}
if layout.Pad {
height += theme.Padding() * 2
}
return
}