40 std::optional<asw::Color>
color { };
105 void toast(
const std::string& text);
Shared state for the UI system.
A box over the rest of the UI that has to be dealt with first, e.g. a question or a login code.
A container widget with a background color or image.
Root container that manages the UI tree, input, and rendering.
T & open_modal(Args &&... args)
Open a modal over the rest of the UI. Its first focusable widget takes focus, and focus goes back whe...
void focus(Widget &w, bool show=false)
Focus a widget.
bool in_root(const Widget *w) const
Panel root
The root panel widget. See through by default, set bg for a background.
bool attached(const Widget *w) const
Root()
Default constructor.
bool dispatch_pointer(const UIEvent &e)
void clear_toasts()
Remove every message, shown or waiting.
void close_modals()
Close every open modal, top first.
Widget * hit_test(Widget &w, const asw::Vec2< float > &pointer_pos)
bool update()
Process input for this frame.
bool dispatch_to_focused(const UIEvent &e)
void clear_focus()
Remove focus from every widget.
void update_modal_focus()
void toast(const std::string &text)
Show a message at the top of the screen for a few seconds, e.g. "Achievement unlocked"....
std::optional< std::chrono::steady_clock::time_point > _last_update
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
Keep the root panel the size of the logical screen. Turned off by set_size.
void free_removed(Widget &w)
bool has_modal() const
True while a modal is open.
Context ctx
The UI context.
std::size_t toast_count() const
Messages shown or waiting.
Widget * _focus_before_modal
void draw()
Draw the UI tree, then the focus ring.
void set_size(float w, float h)
Set a fixed size for the root panel.
Modal * top_modal() const
bool bubble(Widget *target, const UIEvent &e)
std::deque< ShownToast > _toasts
UI context and focus management for the ASW UI module.
Modal widget for the ASW UI module.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Panel widget for the ASW UI module.
A short message shown at the top of the screen, see Root::toast.
std::string text
The message.
float seconds
How long it stays, the theme toast seconds when 0.
std::optional< asw::Color > color
Text colour, the theme toast text colour when empty.
asw::Texture icon
Picture before the text, e.g. an achievement icon. Optional.
Event structure for UI interactions.