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!
|
// FIXME: fix this!
|
||||||
// func (element *Container) MinimumHeightFor (width int) (height int) {
|
func (element *Container) MinimumHeightFor (width int) (height int) {
|
||||||
// return element.layout.MinimumHeightFor(element.children, width)
|
return element.layout.MinimumHeightFor(element.children, width)
|
||||||
// }
|
}
|
||||||
|
|
||||||
func (element *Container) HandleDeselection () {
|
func (element *Container) HandleDeselection () {
|
||||||
element.selected = false
|
element.selected = false
|
||||||
|
@ -99,21 +99,52 @@ func (layout Horizontal) MinimumHeightFor (
|
|||||||
) (
|
) (
|
||||||
height int,
|
height int,
|
||||||
) {
|
) {
|
||||||
|
// TODO: maybe put calculating the expanding element width in a separate
|
||||||
|
// method
|
||||||
if layout.Pad {
|
if layout.Pad {
|
||||||
width -= theme.Padding() * 2
|
width -= theme.Padding() * 2
|
||||||
}
|
}
|
||||||
|
freeSpace := width
|
||||||
|
expandingElements := 0
|
||||||
|
|
||||||
for _, entry := range entries {
|
// count the number of expanding elements and the amount of free space
|
||||||
var entryHeight int
|
// for them to collectively occupy
|
||||||
if child, flexible := entry.Element.(tomo.Flexible); flexible {
|
for index, entry := range entries {
|
||||||
entryHeight = child.MinimumHeightFor(width)
|
if entry.Expand {
|
||||||
|
expandingElements ++
|
||||||
} else {
|
} else {
|
||||||
_, entryHeight = entry.MinimumSize()
|
entryMinWidth, _ := entry.MinimumSize()
|
||||||
|
freeSpace -= entryMinWidth
|
||||||
}
|
}
|
||||||
if entryHeight > height {
|
if index > 0 && layout.Gap {
|
||||||
height = entryHeight
|
freeSpace -= theme.Padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expandingElementWidth := 0
|
||||||
|
if expandingElements > 0 {
|
||||||
|
expandingElementWidth = freeSpace / expandingElements
|
||||||
|
}
|
||||||
|
|
||||||
|
x, y := 0, 0
|
||||||
|
if layout.Pad {
|
||||||
|
x += theme.Padding()
|
||||||
|
y += theme.Padding()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(entryWidth)
|
||||||
|
}
|
||||||
|
if entryHeight > height { height = entryHeight }
|
||||||
|
|
||||||
|
x += entryWidth
|
||||||
|
if index > 0 && layout.Gap { x += theme.Padding() }
|
||||||
|
}
|
||||||
|
|
||||||
if layout.Pad {
|
if layout.Pad {
|
||||||
height += theme.Padding() * 2
|
height += theme.Padding() * 2
|
||||||
|
Reference in New Issue
Block a user