atomize-parent-hooks #4

Merged
sashakoshka merged 8 commits from atomize-parent-hooks into main 2023-01-19 15:35:51 -07:00
5 changed files with 16 additions and 12 deletions
Showing only changes of commit 6f6591f0d0 - Show all commits

View File

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

View File

@ -23,8 +23,8 @@ type Layout interface {
// needs to properly arrange the given slice of layout entries. // needs to properly arrange the given slice of layout entries.
MinimumSize (entries []LayoutEntry) (width, height int) 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 // out the specified elements at the given width, taking into account
// flexible elements. // 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 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, entries []tomo.LayoutEntry,
width int, width int,
) ( ) (
@ -147,7 +149,7 @@ func (layout Dialog) MinimumHeightFor (
if len(entries) > 0 { if len(entries) > 0 {
mainChildHeight := 0 mainChildHeight := 0
if child, flexible := entries[0].Element.(tomo.Flexible); flexible { if child, flexible := entries[0].Element.(tomo.Flexible); flexible {
mainChildHeight = child.MinimumHeightFor(width) mainChildHeight = child.FlexibleHeightFor(width)
} else { } else {
_, mainChildHeight = entries[0].MinimumSize() _, mainChildHeight = entries[0].MinimumSize()
} }

View File

@ -75,7 +75,9 @@ func (layout Horizontal) MinimumSize (
return 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, entries []tomo.LayoutEntry,
width int, width int,
) ( ) (
@ -100,7 +102,7 @@ func (layout Horizontal) MinimumHeightFor (
entryWidth = expandingElementWidth entryWidth = expandingElementWidth
} }
if child, flexible := entry.Element.(tomo.Flexible); flexible { if child, flexible := entry.Element.(tomo.Flexible); flexible {
entryHeight = child.MinimumHeightFor(entryWidth) entryHeight = child.FlexibleHeightFor(entryWidth)
} }
if entryHeight > height { height = entryHeight } if entryHeight > height { height = entryHeight }

View File

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