Skip to content

Commit

Permalink
container: better track VerticalScrollBox updates
Browse files Browse the repository at this point in the history
Only update the screen when something actually changed.
  • Loading branch information
aykevl committed Jan 31, 2024
1 parent 7f2d6e9 commit 5cf2331
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ func (b *VerticalScrollBox[T]) Layout(width, height int) {
}

func (b *VerticalScrollBox[T]) Update(screen *Screen[T], displayX, displayY, displayWidth, displayHeight, x, y int) {
if b.flags&(flagNeedsUpdate|flagNeedsChildUpdate) == 0 {
return
}

// The code below assumes x and y are both 0.
if x != 0 || y != 0 {
panic("todo: x and y inside VerticalScrollBox")
Expand Down Expand Up @@ -526,7 +530,10 @@ func (b *VerticalScrollBox[T]) HandleEvent(event Event, x, y int) {
if scrollOffset > b.maxScrollOffset {
scrollOffset = b.maxScrollOffset
}
b.scrollOffset = scrollOffset
if scrollOffset != b.scrollOffset {
b.scrollOffset = scrollOffset
b.Rect.RequestUpdate()
}
b.lastTouchY = int16(y)
case TouchTap:
if y < int(b.topHeight) {
Expand Down Expand Up @@ -557,7 +564,7 @@ func (b *VerticalScrollBox[T]) ScrollIntoViewVertical(top, bottom int, child Obj
if top < b.scrollOffset {
// Scroll up if 'top' is above the visible area.
b.scrollOffset = top
b.RequestLayout()
b.Rect.RequestUpdate()
} else {
// Scroll down if 'bottom' is below the visible area.
bottomScrollOffset := bottom - int(b.childHeight)
Expand All @@ -569,7 +576,7 @@ func (b *VerticalScrollBox[T]) ScrollIntoViewVertical(top, bottom int, child Obj
}
if bottomScrollOffset != b.scrollOffset {
b.scrollOffset = bottomScrollOffset
b.RequestLayout()
b.Rect.RequestUpdate()
}
}
}
Expand Down

0 comments on commit 5cf2331

Please sign in to comment.