ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
modal.h
Go to the documentation of this file.
1
8
9#ifndef ASW_MODULES_UI_MODAL_H
10#define ASW_MODULES_UI_MODAL_H
11
12#include <functional>
13#include <optional>
14#include <string>
15
16#include "button.h"
17#include "label.h"
18#include "layout.h"
19#include "theme.h"
20
21namespace asw::ui {
22
31class Modal : public Stack {
32public:
35 Modal();
36
38 std::function<void()> on_close;
39
42 bool close_on_back = true;
43
45 std::optional<ModalStyle> style;
46
52 const ModalStyle& get_style(const Context& ctx) const;
53
60 Label& add_text(const std::string& text, const asw::Font& font = nullptr);
61
68 Button& add_button(const std::string& text, std::function<void()> on_click);
69
73 void close();
74
79 bool closed() const
80 {
81 return _closed;
82 }
83
88 void measure(Context& ctx) override;
89
96 bool on_event(Context& ctx, const UIEvent& e) override;
97
102 void draw(Context& ctx) override;
103
104private:
105 bool _closed = false;
106};
107
108} // namespace asw::ui
109
110#endif // ASW_MODULES_UI_MODAL_H
Button widget for the ASW UI module.
An interactive button widget.
Definition button.h:24
Shared state for the UI system.
Definition context.h:97
A text display widget.
Definition label.h:23
A box over the rest of the UI that has to be dealt with first, e.g. a question or a login code.
Definition modal.h:31
std::optional< ModalStyle > style
Style for this modal only. Uses the theme modal style when empty.
Definition modal.h:45
bool on_event(Context &ctx, const UIEvent &e) override
Close on back.
Definition modal.cpp:79
Button & add_button(const std::string &text, std::function< void()> on_click)
Add a button, sized to its text.
Definition modal.cpp:28
bool closed() const
True once closed.
Definition modal.h:79
std::function< void()> on_close
Called once when the modal closes, from close() or back.
Definition modal.h:38
void measure(Context &ctx) override
Size to the children, at least the style's min_width.
Definition modal.cpp:54
Label & add_text(const std::string &text, const asw::Font &font=nullptr)
Add a line of text, sized to fit.
Definition modal.cpp:19
bool _closed
Definition modal.h:105
bool close_on_back
Close back when pressed. Turn off for a modal the player must answer with one of its buttons.
Definition modal.h:42
void close()
Close the modal. Calls on_close, then takes it off the screen. Safe to call from its own buttons or f...
Definition modal.cpp:37
Modal()
Default constructor.
Definition modal.cpp:8
const ModalStyle & get_style(const Context &ctx) const
Get the style this modal draws with.
Definition modal.cpp:14
Places children one after another, top to bottom or left to right.
Definition layout.h:100
Label widget for the ASW UI module.
Layout widgets for the ASW UI module.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition types.h:79
Look of a Modal and the dimmed screen behind it.
Definition theme.h:214
Event structure for UI interactions.
Definition event.h:21
UI theme configuration for the ASW UI module.