Jazz2::UI::Windows::VirtualList class

List of rows of the same height that draws only the rows that are seen.

It has no element for a row, it asks for the number of rows and draws each one seen by a function, so a list of thousands of rows costs as much as what fits on the screen. It's meant to be the content of a ScrollView, it's as high as all of its rows.

A click picks a row, a double click or Enter activates it. Up, Down, Page Up, Page Down, Home and End move the pick, letters typed go to the next row whose text starts with them.

Rows that hold widgets, such as buttons, get elements of their own from CreateRow, only as many of them as rows are seen at once, each bound by BindRow to the row it's placed over.

Base classes

class Element
Element of the interface.

Constructors, destructors, conversion operators

VirtualList()
Creates a new instance.

Public functions

auto GetSelected() const -> std::int32_t
Returns the picked row, -1 if none.
void SetSelected(std::int32_t index, bool scrollIntoView = true)
Picks a row, -1 for none, it's scrolled to if scrollIntoView, OnSelectionChanged isn't called.
void ScrollToRow(std::int32_t index)
Scrolls the list it's in so a row is seen, once it's laid out.
auto GetRowAt(Vector2f pos) const -> std::int32_t
Returns the row under a position, or -1.
auto GetCount() const -> std::int32_t
Returns the number of rows.
void RebindRows()
Binds the elements of the rows to their rows again, for rows that changed while their number didn't, see BindRow.
auto Measure(const Context& context, Vector2f available) -> Vector2f override
Returns the size the element wants, in pixels.
void Arrange(const Context& context, const Rectf& bounds) override
Places the element and its children.
void Draw(Painter& painter) override
Draws the element and its children.
void Update(float timeMult) override
Advances animations of the element and its children.
auto AcceptsPointer() const -> bool override
Returns true if the element takes the pointer itself.
auto OnPointerDown(const PointerEvent& event) -> bool override
Called when the pointer is pressed over the element, returns true to keep getting it until released.
auto OnKeyPressed(const KeyboardEvent& event) -> bool override
Called when a key is pressed while the element has the focus, returns true if it was used.
auto OnTextInput(const TextInputEvent& event) -> bool override
Called when text is typed while the element has the focus.
auto IsFocusable() const -> bool override
Returns true if the element can take the keyboard focus.
auto GetTooltip(Vector2f pos) const -> StringView override
Returns the tooltip at a position.

Public variables

float RowHeight
Height of a row in units.
Function<std::int32_t()> CountFunc
Returns the number of rows.
Function<void(Painter&, std::int32_t, const Rectf&, bool, float)> DrawRow
Draws a row into its rectangle, with whether it's picked and how much it's pointed at, from 0 to 1.
Function<String(std::int32_t)> RowText
Returns the text of a row, which letters typed are looked for in, optional.
Function<String(std::int32_t)> RowTooltip
Returns the tooltip of a row, optional.
Function<void(std::int32_t)> OnSelectionChanged
Called when the picked row changed, by a click or by the keys.
Function<void(std::int32_t)> OnActivated
Called when a row is activated, by a double click or Enter.
Function<void(std::int32_t, Vector2f, const PointerEvent&)> OnRowPressed
Called when a row is pressed, with the position in it relative to its top left corner, optional.
bool Selectable
Whether a row can be picked, a list only to be read takes neither the pointer nor the keys, the widgets of its rows still do.
String EmptyText
Text shown in place of the rows while there are none, optional.
Colorf EmptyColor
Color of EmptyText.
Function<std::unique_ptr<Element>()> CreateRow
Makes the element of a row, for rows that hold widgets, optional.
Function<void(Element&, std::int32_t)> BindRow
Binds an element made by CreateRow to a row.

Function documentation

Vector2f Jazz2::UI::Windows::VirtualList::Measure(const Context& context, Vector2f available) override

Returns the size the element wants, in pixels.

The available size is what the parent can give, a size without limit is a very large number.

Variable documentation

Function<std::unique_ptr<Element>()> Jazz2::UI::Windows::VirtualList::CreateRow

Makes the element of a row, for rows that hold widgets, optional.

There are only as many of them as rows fit in the list it's in. Each is placed over a row that is seen and bound to it by BindRow, and to another row when that one takes its place as the list is scrolled, so its widgets have to act on the row it's bound to now. It's drawn over what DrawRow draws. The list shows and hides it, it shouldn't be hidden by itself.