handle uneven disribution of space

This commit is contained in:
2021-07-04 09:41:22 -04:00
parent 40b4cd3668
commit 78d80aef6c
2 changed files with 41 additions and 2 deletions

View File

@@ -56,22 +56,35 @@ func (c *Container) Draw(s tcell.Screen) {
func (c *Container) SetSize(x, y, h, w int) {
c.x, c.y, c.h, c.w = x, y, h, w
carry := 0
if c.layoutMethod == LayoutVerticalEven {
num := len(c.contents)
extra := c.h % num
for r := range c.contents {
w := c.w
h := c.h / num
x := c.x
y := c.y + (h * r)
y := c.y + (h * r) + carry
if extra > 0 { // distribute "extra" space to containers as we have some left
h++
extra--
carry++
}
c.contents[r].Container.SetSize(x, y, h, w)
}
} else if c.layoutMethod == LayoutHorizontalEven {
num := len(c.contents)
extra := c.w % num
for r := range c.contents {
w := c.w / num
h := c.h
x := c.x + (w * r)
x := c.x + (w * r) + carry
y := c.y
if extra > 0 { // distribute "extra" space to containers as we have some left
w++
extra--
carry++
}
c.contents[r].Container.SetSize(x, y, h, w)
}
} else {