ListView
The virtualized list: 10,000 rows cost a screenful per frame.
A lotusui extension — the list family: ListView lays out only the rows
intersecting the viewport, Scrollable is its whole-content sibling for a screen's
mixed content, and HoverRow is the one way a list row reads as interactive. Scroll
position lives in the caller's widget.List.
Installation
Use the module import (the default), or own the source: lotusui add
vendors the component into your app and lotusui update keeps the copy mergeable —
see Registry.
go get github.com/ikaito-com/lotusui
# or vendor the source into your app:
go run github.com/ikaito-com/lotusui/cmd/lotusui add listview
Usage — virtualization
Only visible rows are laid out: in the library's benchmarks a 10,000-row list renders about 270× faster than the non-virtualized path (61µs vs 16.5ms a frame). The demo below scrolls 10,000 real rows — wheel over it to feel it.
var list widget.List
lotusui.ListView(th, &list, gtx, len(items), func(gtx C, i int) D {
return row(items[i])(gtx)
})
Hover rows and selection
HoverRow wraps a row's content: full-width click target, pointer
cursor, and the rounded hover pill — kept while active, so the selected row and
the hovered row speak the same language.
lotusui.HoverRow(th, &rowBtns[i], selected == i,
lotusui.LabelBody(th, items[i].Name).Layout)
Scrollable — the non-virtualized sibling
Scrollable lays its whole content out every frame — right for a
form or a settings screen, wrong past a few dozen rows. Reach for ListView the
moment a collection can grow with data. Content inside must not use a vertical
layout.Flexed expecting to fill "remaining" space — the list measures against an
unbounded height.
var scroll widget.List
lotusui.Scrollable(th, &scroll, gtx, screenContent)
API
| Option | Type | Description |
|---|---|---|
list | *widget.List | Scroll position; must outlive the frame. |
count | int | Number of rows. |
row | func(C, int) D | Lays out row i at the viewport's width. |