|
Aegis2D
Modular C++26 2D game engine for networked games
|
Buttons and labels of a menu, on a WidgetTree. More...
#include <aegis2d/ui/menu.hpp>
Public Member Functions | |
| Menu (const MenuStyle &style={}) | |
| Creates an empty menu. | |
| WidgetId | add_button (std::string text, render::Rect bounds, WidgetId group=root) |
| Adds a button. | |
| std::size_t | add_label (std::string text, Vec2 position) |
| Adds a label, a text that never takes the focus. | |
| void | set_text (WidgetId button, std::string text) |
| Changes the text of a button. | |
| void | set_label (std::size_t label, std::string text) |
| Changes the text of a label. | |
| const std::string & | text (WidgetId button) const |
| Text of a button. | |
| WidgetTree & | tree () noexcept |
| The tree of the buttons: focus, enabled buttons, scale. | |
| const WidgetTree & | tree () const noexcept |
| The tree of the buttons. | |
| std::optional< WidgetId > | update (const Navigation &navigation) |
| Moves the focus and tells which button was used during the frame. | |
| WidgetState | state (WidgetId button) const |
| How a button looks now. | |
| void | draw (render::IRenderer &renderer, const render::BitmapFont &font) const |
| Draws the buttons and the labels at the tree's scale. | |
Buttons and labels of a menu, on a WidgetTree.
Buttons are widgets of the tree, with a text centered in them; labels are texts that never take the focus. update() moves the focus and tells which button the player used: the focused one when activate is pressed (Enter, Space, South), or the one clicked. draw() shows each button in its state, and follows the tree's scale, so the menu grows with the player's text size.
|
explicit |
Creates an empty menu.
| style | Colors, text size and layer. |
| WidgetId aegis2d::ui::Menu::add_button | ( | std::string | text, |
| render::Rect | bounds, | ||
| WidgetId | group = root |
||
| ) |
Adds a button.
| text | Text shown centered in it. |
| bounds | Rectangle at 100%, in logical pixels. |
| group | Group of the tree to put it in, root by default. |
| as | WidgetTree::add(). |
| std::size_t aegis2d::ui::Menu::add_label | ( | std::string | text, |
| Vec2 | position | ||
| ) |
Adds a label, a text that never takes the focus.
| text | Text, lines separated by \n. |
| position | Top-left corner at 100%, in logical pixels. |
| void aegis2d::ui::Menu::draw | ( | render::IRenderer & | renderer, |
| const render::BitmapFont & | font | ||
| ) | const |
Draws the buttons and the labels at the tree's scale.
| renderer | Renderer in a frame. |
| font | Font of the texts. |
| void aegis2d::ui::Menu::set_label | ( | std::size_t | label, |
| std::string | text | ||
| ) |
Changes the text of a label.
| label | Index returned by add_label(). |
| text | New text. |
| std::out_of_range | if label does not exist. |
| void aegis2d::ui::Menu::set_text | ( | WidgetId | button, |
| std::string | text | ||
| ) |
Changes the text of a button.
| button | Widget returned by add_button(). |
| text | New text. |
| std::out_of_range | if button is not a button of this menu. |
| WidgetState aegis2d::ui::Menu::state | ( | WidgetId | button | ) | const |
How a button looks now.
| button | Widget returned by add_button(). |
| std::out_of_range | if button does not exist. |
| const std::string & aegis2d::ui::Menu::text | ( | WidgetId | button | ) | const |
Text of a button.
| button | Widget returned by add_button(). |
| std::out_of_range | if button is not a button of this menu. |
|
noexcept |
The tree of the buttons.
|
noexcept |
The tree of the buttons: focus, enabled buttons, scale.
| std::optional< WidgetId > aegis2d::ui::Menu::update | ( | const Navigation & | navigation | ) |
Moves the focus and tells which button was used during the frame.
| navigation | Input of the frame, from NavigationInput::read(). |