Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
layout: export First/LastDrawn; fix scrollto bug
Browse files Browse the repository at this point in the history
- Export FirstDrawn and LastDrawn, so that client code can know which
  children were drawn.
- Fix a bug that sometimes set scrollTo (and thus Position.First) to -1.
  • Loading branch information
theclapp committed May 27, 2020
1 parent 6236db2 commit 6785cea
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions layout/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type List struct {
fromEnd bool

len int
firstDrawn int
lastDrawn int
FirstDrawn int
LastDrawn int

// maxSize is the total size of visible children.
maxSize int
Expand Down Expand Up @@ -103,16 +103,20 @@ func (l *List) init(gtx Context, len int) {
l.update()
if l.doScrollTo {
if l.scrollTo >= len {
l.scrollTo = len - 1
if len > 0 {
l.scrollTo = len - 1
} else {
l.scrollTo = 0
}
}
// If l.scrollTo is already in view, do nothing.
if l.firstDrawn < l.scrollTo &&
l.scrollTo < l.lastDrawn {
if l.FirstDrawn < l.scrollTo &&
l.scrollTo < l.LastDrawn {
l.doScrollTo = false
} else {
l.Position.Offset = 0
l.Position.First = l.scrollTo
if l.lastDrawn > 0 && l.scrollTo >= l.lastDrawn {
if l.LastDrawn > 0 && l.scrollTo >= l.LastDrawn {
l.fromEnd = true
l.Position.First++
} else {
Expand Down Expand Up @@ -292,8 +296,8 @@ func (l *List) layout() Dimensions {
pos += space
}
if len(children) > 0 {
l.firstDrawn = children[0].index
l.lastDrawn = children[len(children)-1].index
l.FirstDrawn = children[0].index
l.LastDrawn = children[len(children)-1].index
}
for _, child := range children {
sz := child.size
Expand Down

0 comments on commit 6785cea

Please sign in to comment.