diff options
| -rw-r--r-- | tui/layout.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tui/layout.go b/tui/layout.go index 210924f..4feda2f 100644 --- a/tui/layout.go +++ b/tui/layout.go @@ -332,8 +332,19 @@ func (b *Box) computePositions(axis int) { } } if b.Scroll != nil { - var first *Box - var last *Box + first := b.children[0] + last := b.children[len(b.children) - 1] + + lastPos := last.computedPosition + lastPos += last.computedSize[axis] + if b.Dir.reverse() { + lastPos = b.computedSize[axis] - lastPos + } + b.Scroll.absolute = min(b.Scroll.absolute, lastPos - b.computedSize[axis]) + b.Scroll.absolute = max(b.Scroll.absolute, 0) + + var firstShown *Box + var lastShown *Box for _, c := range b.children { if !b.Dir.reverse() { c.computedPosition -= b.Scroll.absolute @@ -342,19 +353,19 @@ func (b *Box) computePositions(axis int) { } if c.computedPosition > b.computedRect.min[axis] && c.computedPosition < b.computedRect.max[axis] { - if first == nil { + if firstShown == nil { first = c } last = c } } - if first == b.children[0] { + if firstShown == first { b.Scroll.atFirst = true } - if last == b.children[len(b.children) - 1] { + if lastShown == last { b.Scroll.atLast = true } - if first != nil { + if firstShown != nil { p := first.computedPosition if b.Dir.reverse() { p = b.computedSize[axis] - p |
