Layouts now conform to the new API

This commit is contained in:
Sasha Koshka 2023-01-19 16:54:49 -05:00
parent c813463bb4
commit 6f6591f0d0
5 changed files with 16 additions and 12 deletions

View File

@ -324,7 +324,7 @@ func (element *Container) HandleSelection (direction tomo.SelectionDirection) (o
}
func (element *Container) FlexibleHeightFor (width int) (height int) {
return element.layout.MinimumHeightFor(element.children, width)
return element.layout.FlexibleHeightFor(element.children, width)
}
func (element *Container) OnFlexibleHeightChange (callback func ()) {
@ -431,7 +431,7 @@ func (element *Container) childSelectionRequestCallback (
func (element *Container) updateMinimumSize () {
width, height := element.layout.MinimumSize(element.children)
if element.flexible {
height = element.layout.MinimumHeightFor(element.children, width)
height = element.layout.FlexibleHeightFor(element.children, width)
}
element.core.SetMinimumSize(width, height)
}

View File

@ -23,8 +23,8 @@ type Layout interface {
// needs to properly arrange the given slice of layout entries.
MinimumSize (entries []LayoutEntry) (width, height int)
// MinimumHeightFor Returns the minimum height the layout needs to lay
// FlexibleHeightFor Returns the minimum height the layout needs to lay
// out the specified elements at the given width, taking into account
// flexible elements.
MinimumHeightFor (entries []LayoutEntry, squeeze int) (height int)
FlexibleHeightFor (entries []LayoutEntry, squeeze int) (height int)
}

View File

@ -134,7 +134,9 @@ func (layout Dialog) MinimumSize (
return
}
func (layout Dialog) MinimumHeightFor (
// FlexibleHeightFor Returns the minimum height the layout needs to lay out the
// specified elements at the given width, taking into account flexible elements.
func (layout Dialog) FlexibleHeightFor (
entries []tomo.LayoutEntry,
width int,
) (
@ -147,7 +149,7 @@ func (layout Dialog) MinimumHeightFor (
if len(entries) > 0 {
mainChildHeight := 0
if child, flexible := entries[0].Element.(tomo.Flexible); flexible {
mainChildHeight = child.MinimumHeightFor(width)
mainChildHeight = child.FlexibleHeightFor(width)
} else {
_, mainChildHeight = entries[0].MinimumSize()
}

View File

@ -75,7 +75,9 @@ func (layout Horizontal) MinimumSize (
return
}
func (layout Horizontal) MinimumHeightFor (
// FlexibleHeightFor Returns the minimum height the layout needs to lay out the
// specified elements at the given width, taking into account flexible elements.
func (layout Horizontal) FlexibleHeightFor (
entries []tomo.LayoutEntry,
width int,
) (
@ -100,7 +102,7 @@ func (layout Horizontal) MinimumHeightFor (
entryWidth = expandingElementWidth
}
if child, flexible := entry.Element.(tomo.Flexible); flexible {
entryHeight = child.MinimumHeightFor(entryWidth)
entryHeight = child.FlexibleHeightFor(entryWidth)
}
if entryHeight > height { height = entryHeight }

View File

@ -32,7 +32,7 @@ func (layout Vertical) Arrange (entries []tomo.LayoutEntry, width, height int) {
var entryMinHeight int
if child, flexible := entry.Element.(tomo.Flexible); flexible {
entryMinHeight = child.MinimumHeightFor(width)
entryMinHeight = child.FlexibleHeightFor(width)
} else {
_, entryMinHeight = entry.MinimumSize()
}
@ -102,9 +102,9 @@ func (layout Vertical) MinimumSize (
return
}
// MinimumHeightFor Returns the minimum height the layout needs to lay out the
// FlexibleHeightFor Returns the minimum height the layout needs to lay out the
// specified elements at the given width, taking into account flexible elements.
func (layout Vertical) MinimumHeightFor (
func (layout Vertical) FlexibleHeightFor (
entries []tomo.LayoutEntry,
width int,
) (
@ -118,7 +118,7 @@ func (layout Vertical) MinimumHeightFor (
for index, entry := range entries {
child, flexible := entry.Element.(tomo.Flexible)
if flexible {
height += child.MinimumHeightFor(width)
height += child.FlexibleHeightFor(width)
} else {
_, entryHeight := entry.MinimumSize()
height += entryHeight