Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ func (p *Page) ListArea(c C, state *ListState, n int, horizontal bool, row func(
// last paint moved: the rows are placed for that end, not for the offset the
// area had, which would leave the paint that adds them blank.
scroll.Offset = max(state.top(n)-viewport, 0)
} else {
// Measuring the previous paint can shorten the estimated content. Choose
// rows against that extent before layout clamps the old offset; otherwise
// the rows declared at the old end are outside the new viewport.
scroll.Offset = min(max(scroll.Offset, 0), max(state.top(n)-viewport, 0))
}
// The rows are placed and hit-tested on whole logical pixels, as the layout
// applies them, so a label's native texture survives a fractional scroll.
Expand Down
27 changes: 27 additions & 0 deletions ui/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@ func TestListRowHeightAtReportsLaidOutRows(t *testing.T) {
}
}

// The first paint estimates unseen rows at 32 px. Once its 24 px rows are
// measured, a wheel to the old end must use the new extent before choosing rows.
func TestListWheelClampsToTheMeasuredExtent(t *testing.T) {
var state ui.ListState
state.Label = func(i int) string { return "row " + strconv.Itoa(i) }
d := openPage(t, func(c ui.C) {
ui.Column(c).Fill().Children(func() {
ui.List(c, &state, 400, func(row ui.ListRow) {
row.Element.Height(24).Children(func() {
ui.Text(row.C, "row "+strconv.Itoa(row.Index))
})
}).Label("Rows").Grow(1)
})
})
area := d.ListArea("Rows")
if err := d.driver.Scroll(gfx.ScrollEvent{X: area.X + 20, Y: area.Y + 20, DeltaY: 20000, Precise: true}); err != nil {
t.Fatal(err)
}
if !d.has("row 399") {
t.Fatalf("the end is blank after scrolling: Visible %v", visibleOf(&state))
}
bottom := d.hit("row 399").Bounds
if gap := area.Y + area.Height - bottom.Y - bottom.Height; gap < -1 || gap > 1 {
t.Fatalf("last row is %v px from the end of the viewport", gap)
}
}

func fmtSscan(Value string, i *int) (int, error) {
n, err := strconv.Atoi(strings.TrimPrefix(Value, "row "))
*i = n
Expand Down
Loading