21 auto& label = add_child<Label>();
24 label.set_text(text,
true);
30 auto& button = add_child<Button>();
31 button.padding = 8.0F;
32 button.set_text(text,
true);
33 button.on_click = std::move(on_click);
49 if (parent !=
nullptr) {
50 parent->remove_child(*
this);
56 const auto& s = get_style(ctx);
63 for (
auto const& c : children()) {
68 width = std::max(width, c->transform.size.x);
69 height += c->transform.size.y;
73 height += gap *
static_cast<float>(shown - 1);
76 transform.size = { std::max(s.min_width, width + (padding * 2.0F)), height + (padding * 2.0F) };
90 const auto& s = get_style(ctx);
94 if (s.border_width > 0.0F && s.border.a > 0) {
Shared state for the UI system.
Theme theme
The current UI theme.
void draw(Context &ctx) override
Draw the box, then the children.
bool on_event(Context &ctx, const UIEvent &e) override
Close on back.
Button & add_button(const std::string &text, std::function< void()> on_click)
Add a button, sized to its text.
void measure(Context &ctx) override
Size to the children, at least the style's min_width.
Label & add_text(const std::string &text, const asw::Font &font=nullptr)
Add a line of text, sized to fit.
void close()
Close the modal. Calls on_close, then takes it off the screen. Safe to call from its own buttons or f...
Modal()
Default constructor.
const ModalStyle & get_style(const Context &ctx) const
Get the style this modal draws with.
Align align
Where children sit across the stack.
Direction direction
Direction children are placed in.
UI context and focus management for the ASW UI module.
Routines for drawing sprites and primitives to the screen.
Modal widget for the ASW UI module.
void rect(const asw::Quad< float > &position, asw::Color color, float thickness=1.0F)
Draw a rectangle.
void rect_fill(const asw::Quad< float > &position, asw::Color color)
Draw a filled rectangle.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Look of a Modal and the dimmed screen behind it.
ModalStyle modal
Modals from Root::open_modal.
Event structure for UI interactions.
Type type
The type of the event.