|
| | WidgetTree () |
| | Creates a tree with its root group only, and no focus.
|
| |
| WidgetId | add (render::Rect bounds, WidgetId parent=root) |
| | Adds a widget that can take the focus.
|
| |
| WidgetId | add_group (WidgetId parent=root) |
| | Adds a group, which never takes the focus.
|
| |
| std::size_t | size () const noexcept |
| | Number of widgets and groups, the root included.
|
| |
| WidgetId | parent (WidgetId id) const |
| | Group a widget or a group is in.
|
| |
| std::span< const WidgetId > | children (WidgetId id) const |
| | Widgets and groups in a group.
|
| |
| void | set_bounds (WidgetId id, render::Rect bounds) |
| | Moves or resizes a widget.
|
| |
| render::Rect | bounds (WidgetId id) const |
| | Rectangle of a widget on screen, at the tree's scale.
|
| |
| void | set_enabled (WidgetId id, bool enabled) |
| | Enables or disables a widget or a whole group.
|
| |
| bool | enabled (WidgetId id) const |
| | Tells whether a widget can be used.
|
| |
| void | set_scale (float scale, Vec2 origin={0.0F, 0.0F}) noexcept |
| | Scales the tree, such as with the player's text size.
|
| |
| float | scale () const noexcept |
| | Factor given to set_scale().
|
| |
| Vec2 | scaled (Vec2 point) const noexcept |
| | Where a point given at 100% is on screen, at the tree's scale.
|
| |
| std::optional< WidgetId > | focused () const noexcept |
| | Widget that has the focus.
|
| |
| bool | focus (WidgetId id) |
| | Gives the focus to a widget.
|
| |
| void | clear_focus () noexcept |
| | Takes the focus away from every widget.
|
| |
| bool | focus_next () |
| | Focuses the next widget in the tree's order, the first one after the last.
|
| |
| bool | focus_previous () |
| | Focuses the previous widget in the tree's order, the last one before the first.
|
| |
| bool | move_focus (Direction direction) |
| | Focuses the nearest widget in a direction.
|
| |
| std::optional< WidgetId > | at (Vec2 point) const |
| | Widget under a point.
|
| |
| bool | update (const Navigation &navigation) |
| | Moves the focus as the player asked during a frame.
|
| |
Widgets of a menu or a form, in groups, and which one has the focus.
A widget is a rectangle that can take the focus, such as a button; a group holds widgets and other groups, such as a panel, and never takes the focus itself. The focus goes from widget to widget in the order of the tree (each group's children in the order they were added), with Tab and Shift+Tab, wrapping around at the ends; to the nearest widget in a direction with the arrows, the D-pad or a stick; and to the widget under the mouse when it moves or clicks. Disabled widgets, and every widget of a disabled group, are skipped. Bounds are given at 100% and in logical pixels; with set_scale(), the tree follows the player's text size (render::TextSize::scale()), so a form laid out for 100% grows from its origin.
const auto name = form.
add({.x = 40, .y = 40, .width = 200, .height = 24});
const auto port = form.
add({.x = 40, .y = 72, .width = 200, .height = 24});
form.
set_scale(text_size.scale(), {40.0F, 40.0F});
form.
update(navigation.read(window.keyboard(), window.gamepad(), window.mouse(),
renderer.to_logical(window.mouse().position())));
AEGIS2D_UI_EXPORT std::string_view name() noexcept
Name of the module, used to check that it is linked.
| bool aegis2d::ui::WidgetTree::move_focus |
( |
Direction |
direction | ) |
|
Focuses the nearest widget in a direction.
Among the widgets whose center is past the focused one's in direction, picks the one with the smallest distance along it plus twice the offset across it, so the widget straight ahead wins over a closer one to the side; the first in the tree's order on a tie. Without a focus, focuses the first widget.
- Parameters
-
- Returns
true if the focus changed; false at the edge of the form.