summaryrefslogtreecommitdiff
path: root/tui/layout.go
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-05-31 05:15:09 -0500
committercitrons <citrons@mondecitronne.com>2025-05-31 05:15:09 -0500
commit22a50b723eb93c97d67eac362422d2424436b16b (patch)
tree56d999728525beb20e2436aa693dd6be360db470 /tui/layout.go
parentb3a01b28cbfe43ef22168a2f81803dccd4e56864 (diff)
confine scrolling to the contents of the box
Diffstat (limited to 'tui/layout.go')
-rw-r--r--tui/layout.go23
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