Horizontal layouts work nearly perfectly
This commit is contained in:
parent
9459bcd942
commit
40bdffc8be
@ -301,9 +301,9 @@ func (element *Container) HandleSelection (direction tomo.SelectionDirection) (o
|
||||
}
|
||||
|
||||
// FIXME: fix this!
|
||||
// func (element *Container) MinimumHeightFor (width int) (height int) {
|
||||
// return element.layout.MinimumHeightFor(element.children, width)
|
||||
// }
|
||||
func (element *Container) MinimumHeightFor (width int) (height int) {
|
||||
return element.layout.MinimumHeightFor(element.children, width)
|
||||
}
|
||||
|
||||
func (element *Container) HandleDeselection () {
|
||||
element.selected = false
|
||||
|
@ -99,20 +99,51 @@ func (layout Horizontal) MinimumHeightFor (
|
||||
) (
|
||||
height int,
|
||||
) {
|
||||
// TODO: maybe put calculating the expanding element width in a separate
|
||||
// method
|
||||
if layout.Pad {
|
||||
width -= theme.Padding() * 2
|
||||
width -= theme.Padding() * 2
|
||||
}
|
||||
freeSpace := width
|
||||
expandingElements := 0
|
||||
|
||||
// count the number of expanding elements and the amount of free space
|
||||
// for them to collectively occupy
|
||||
for index, entry := range entries {
|
||||
if entry.Expand {
|
||||
expandingElements ++
|
||||
} else {
|
||||
entryMinWidth, _ := entry.MinimumSize()
|
||||
freeSpace -= entryMinWidth
|
||||
}
|
||||
if index > 0 && layout.Gap {
|
||||
freeSpace -= theme.Padding()
|
||||
}
|
||||
}
|
||||
expandingElementWidth := 0
|
||||
if expandingElements > 0 {
|
||||
expandingElementWidth = freeSpace / expandingElements
|
||||
}
|
||||
|
||||
x, y := 0, 0
|
||||
if layout.Pad {
|
||||
x += theme.Padding()
|
||||
y += theme.Padding()
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
var entryHeight int
|
||||
// set the size and position of each element
|
||||
for index, entry := range entries {
|
||||
entryWidth, entryHeight := entry.MinimumSize()
|
||||
if entry.Expand {
|
||||
entryWidth = expandingElementWidth
|
||||
}
|
||||
if child, flexible := entry.Element.(tomo.Flexible); flexible {
|
||||
entryHeight = child.MinimumHeightFor(width)
|
||||
} else {
|
||||
_, entryHeight = entry.MinimumSize()
|
||||
}
|
||||
if entryHeight > height {
|
||||
height = entryHeight
|
||||
entryHeight = child.MinimumHeightFor(entryWidth)
|
||||
}
|
||||
if entryHeight > height { height = entryHeight }
|
||||
|
||||
x += entryWidth
|
||||
if index > 0 && layout.Gap { x += theme.Padding() }
|
||||
}
|
||||
|
||||
if layout.Pad {
|
||||
|
Reference in New Issue
Block a user