Root container that manages the UI tree, input, and rendering.
More...
#include <root.h>
|
| | Root () |
| | Default constructor.
|
| |
| void | set_size (float w, float h) |
| | Set a fixed size for the root panel.
|
| |
| bool | update () |
| | Process input for this frame.
|
| |
| void | draw () |
| | Draw the UI tree, then the focus ring.
|
| |
| void | focus (Widget &w, bool show=false) |
| | Focus a widget.
|
| |
| void | clear_focus () |
| | Remove focus from every widget.
|
| |
| void | toast (const std::string &text) |
| | Show a message at the top of the screen for a few seconds, e.g. "Achievement unlocked". Messages queue when several arrive together.
|
| |
| void | toast (Toast message) |
| | Show a message with an icon, colour or length of its own.
|
| |
| void | clear_toasts () |
| | Remove every message, shown or waiting.
|
| |
| std::size_t | toast_count () const |
| | Messages shown or waiting.
|
| |
| template<class T = Modal, class... Args> |
| T & | open_modal (Args &&... args) |
| | Open a modal over the rest of the UI. Its first focusable widget takes focus, and focus goes back where it was once every modal closes.
|
| |
| bool | has_modal () const |
| | True while a modal is open.
|
| |
| void | close_modals () |
| | Close every open modal, top first.
|
| |
|
| Context | ctx |
| | The UI context.
|
| |
| Panel | root |
| | The root panel widget. See through by default, set bg for a background.
|
| |
| std::function< void()> | on_back |
| | Called when back is pressed and the focused widget does not handle it, e.g. to leave a menu.
|
| |
| bool | auto_size = true |
| | Keep the root panel the size of the logical screen. Turned off by set_size.
|
| |
Root container that manages the UI tree, input, and rendering.
Call update() once per frame after asw::core::update(), then draw(). Root tracks hover, press, focus and the focus ring for every widget, and reads navigation from Context::navigation.
Definition at line 49 of file root.h.
◆ Root()
Default constructor.
Definition at line 48 of file root.cpp.
◆ activate()
| void asw::ui::Root::activate |
( |
Widget & | w | ) |
|
|
private |
◆ active_root()
◆ attached()
| bool asw::ui::Root::attached |
( |
const Widget * | w | ) |
const |
|
private |
◆ bubble()
| bool asw::ui::Root::bubble |
( |
Widget * | target, |
|
|
const UIEvent & | e ) |
|
private |
◆ clear_focus()
| void asw::ui::Root::clear_focus |
( |
| ) |
|
Remove focus from every widget.
Definition at line 664 of file root.cpp.
◆ clear_toasts()
| void asw::ui::Root::clear_toasts |
( |
| ) |
|
Remove every message, shown or waiting.
Definition at line 562 of file root.cpp.
◆ close_modals()
| void asw::ui::Root::close_modals |
( |
| ) |
|
Close every open modal, top first.
Definition at line 129 of file root.cpp.
◆ dispatch_pointer()
| bool asw::ui::Root::dispatch_pointer |
( |
const UIEvent & | e | ) |
|
|
private |
◆ dispatch_to_focused()
| bool asw::ui::Root::dispatch_to_focused |
( |
const UIEvent & | e | ) |
|
|
private |
◆ draw()
| void asw::ui::Root::draw |
( |
| ) |
|
Draw the UI tree, then the focus ring.
Definition at line 670 of file root.cpp.
◆ draw_toasts()
| void asw::ui::Root::draw_toasts |
( |
| ) |
|
|
private |
◆ fit_to_screen()
| void asw::ui::Root::fit_to_screen |
( |
| ) |
|
|
private |
◆ focus()
| void asw::ui::Root::focus |
( |
Widget & | w, |
|
|
bool | show = false ) |
Focus a widget.
- Parameters
-
| w | The widget, it must be focusable and in this tree. |
| show | Show the focus ring, as keyboard navigation would. |
Definition at line 658 of file root.cpp.
◆ free_removed()
| void asw::ui::Root::free_removed |
( |
Widget & | w | ) |
|
|
private |
◆ has_modal()
| bool asw::ui::Root::has_modal |
( |
| ) |
const |
True while a modal is open.
- Returns
- true - If a modal is open.
Definition at line 113 of file root.cpp.
◆ hit_test()
◆ in_root()
| bool asw::ui::Root::in_root |
( |
const Widget * | w | ) |
const |
|
private |
◆ layout_modals()
| void asw::ui::Root::layout_modals |
( |
| ) |
|
|
private |
◆ open_modal()
template<class T = Modal, class... Args>
| T & asw::ui::Root::open_modal |
( |
Args &&... | args | ) |
|
|
inline |
Open a modal over the rest of the UI. Its first focusable widget takes focus, and focus goes back where it was once every modal closes.
- Template Parameters
-
| T | Modal or a class derived from it. |
- Parameters
-
| args | Arguments for the modal's constructor. |
- Returns
- The modal, add its content with add_text and add_button.
Definition at line 134 of file root.h.
◆ opened_modal()
| void asw::ui::Root::opened_modal |
( |
| ) |
|
|
private |
◆ set_size()
| void asw::ui::Root::set_size |
( |
float | w, |
|
|
float | h ) |
Set a fixed size for the root panel.
- Parameters
-
Definition at line 68 of file root.cpp.
◆ toast() [1/2]
| void asw::ui::Root::toast |
( |
const std::string & | text | ) |
|
Show a message at the top of the screen for a few seconds, e.g. "Achievement unlocked". Messages queue when several arrive together.
- Parameters
-
Definition at line 552 of file root.cpp.
◆ toast() [2/2]
| void asw::ui::Root::toast |
( |
Toast | message | ) |
|
Show a message with an icon, colour or length of its own.
- Parameters
-
Definition at line 557 of file root.cpp.
◆ toast_count()
| std::size_t asw::ui::Root::toast_count |
( |
| ) |
const |
|
inline |
Messages shown or waiting.
- Returns
- The number of messages.
Definition at line 121 of file root.h.
◆ top_modal()
◆ update()
| bool asw::ui::Root::update |
( |
| ) |
|
Process input for this frame.
- Returns
- True if the UI used input this frame: the pointer is over a widget or pressing one, or a navigation, activate, back or text key went to the UI. Games can skip their own input for the frame.
Definition at line 521 of file root.cpp.
◆ update_keys()
| void asw::ui::Root::update_keys |
( |
| ) |
|
|
private |
◆ update_modal_focus()
| void asw::ui::Root::update_modal_focus |
( |
| ) |
|
|
private |
◆ update_pointer()
| void asw::ui::Root::update_pointer |
( |
| ) |
|
|
private |
◆ update_toasts()
| void asw::ui::Root::update_toasts |
( |
| ) |
|
|
private |
◆ validate()
| void asw::ui::Root::validate |
( |
| ) |
|
|
private |
◆ _focus_before_modal
| Widget* asw::ui::Root::_focus_before_modal = nullptr |
|
private |
◆ _focused_modal
| Widget* asw::ui::Root::_focused_modal = nullptr |
|
private |
◆ _last_update
| std::optional<std::chrono::steady_clock::time_point> asw::ui::Root::_last_update |
|
private |
◆ _modals
| Panel asw::ui::Root::_modals |
|
private |
◆ _toasts
◆ _used
| bool asw::ui::Root::_used = false |
|
private |
◆ auto_size
| bool asw::ui::Root::auto_size = true |
Keep the root panel the size of the logical screen. Turned off by set_size.
Definition at line 68 of file root.h.
◆ ctx
The UI context.
Definition at line 56 of file root.h.
◆ on_back
| std::function<void()> asw::ui::Root::on_back |
Called when back is pressed and the focused widget does not handle it, e.g. to leave a menu.
Definition at line 64 of file root.h.
◆ root
| Panel asw::ui::Root::root |
The root panel widget. See through by default, set bg for a background.
Definition at line 60 of file root.h.
The documentation for this class was generated from the following files: