|
Aegis2D
Modular C++26 2D game engine for networked games
|
A scrollable list of items, one selected, as a widget of a WidgetTree. More...
#include <aegis2d/ui/widgets.hpp>
Public Member Functions | |
| ListView (WidgetTree &tree, render::Rect bounds, std::vector< std::string > items, std::size_t visible, WidgetId group=root) | |
| Adds the list to a tree. | |
| WidgetId | id () const noexcept |
| The list's widget in its tree. | |
| std::span< const std::string > | items () const noexcept |
| Texts of the rows. | |
| std::size_t | selected () const noexcept |
| Item selected now. | |
| void | select (std::size_t item) |
| Selects an item and scrolls to show it. | |
| std::size_t | top () const noexcept |
| First visible item. | |
| std::size_t | visible () const noexcept |
| Rows shown at once. | |
| std::optional< std::size_t > | update (Navigation &navigation, const WidgetTree &tree) |
| Applies the frame's input to the selection. | |
| void | draw (render::IRenderer &renderer, const WidgetTree &tree, const render::BitmapFont &font, const ListStyle &style={}) const |
| Draws the visible rows, the selection and the scrollbar at the tree's scale. | |
A scrollable list of items, one selected, as a widget of a WidgetTree.
The list is one widget of the tree, so it takes the focus like a button. While it is focused, Up and Down move the selection and are consumed; at the first or last item the move is left to the tree, so the focus walks out of the list. The list scrolls to keep the selection visible, and a scrollbar shows where it is when some items are off screen. A click selects and chooses the row under the mouse; activate chooses the selected one. Bounds are given at 100% and shared by the visible rows.
| aegis2d::ui::ListView::ListView | ( | WidgetTree & | tree, |
| render::Rect | bounds, | ||
| std::vector< std::string > | items, | ||
| std::size_t | visible, | ||
| WidgetId | group = root |
||
| ) |
Adds the list to a tree.
| tree | Tree it lives in; the list keeps only the widget's identifier. |
| bounds | Rectangle at 100% for the visible rows together, in logical pixels. |
| items | Texts of the rows, at least one. |
| visible | Rows shown at once, at least 1; fewer items show them all. |
| group | Group of the tree to put it in, root by default. |
| std::invalid_argument | if items is empty or visible is 0; as WidgetTree::add() for group. |
| void aegis2d::ui::ListView::draw | ( | render::IRenderer & | renderer, |
| const WidgetTree & | tree, | ||
| const render::BitmapFont & | font, | ||
| const ListStyle & | style = {} |
||
| ) | const |
Draws the visible rows, the selection and the scrollbar at the tree's scale.
| renderer | Renderer in a frame. |
| tree | The tree the list was added to. |
| font | Font of the texts. |
| style | Colors, text size and layer. |
|
noexcept |
The list's widget in its tree.
|
noexcept |
Texts of the rows.
| void aegis2d::ui::ListView::select | ( | std::size_t | item | ) |
Selects an item and scrolls to show it.
| item | Index of the item. |
| std::out_of_range | if item does not exist. |
|
noexcept |
Item selected now.
|
noexcept |
First visible item.
| std::optional< std::size_t > aegis2d::ui::ListView::update | ( | Navigation & | navigation, |
| const WidgetTree & | tree | ||
| ) |
Applies the frame's input to the selection.
While the list is focused, Up or Down moves the selection and is consumed (taken out of navigation), except at the first or last item, where the tree moves the focus out instead. A click on a row selects and chooses it; activate chooses the selected one. A disabled list changes nothing.
| navigation | Input of the frame; its direction is consumed when used. |
| tree | The tree the list was added to. |
|
noexcept |
Rows shown at once.