Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
ui.hpp
Go to the documentation of this file.
1// ui — Cadran's helpers for dialogs, toasts, pickers, sheets, keyboards,
2// visibility and focus. The app adds its own (background tasks, its
3// settings file, its error codes) in the same namespace.
4// Copyright (C) 2026 JigSawFr, (C) 2026 Taylor. GPLv3-or-later (see LICENSE.GPL).
5#pragma once
6
7#include <chrono>
8#include <cstdint>
9#include <functional>
10#include <initializer_list>
11#include <string>
12#include <utility>
13#include <vector>
14#include <aurore.hpp>
15
21
22namespace ui
23{
24
25// The status colours below are the boards' inks (cadran::install_theme(),
26// which must run before the first lookup: Aurore aborts on an unknown
27// theme key), one shade per theme (>= 4.5:1).
28
34void use_font_for(const std::string& locale);
35
38enum class Toast
39{
40 Info,
41 Done,
42 Refused,
43};
46void notify(const std::string& text, Toast kind = Toast::Info);
49void refuse(const std::string& text);
53void error(const std::string& text);
55void error(const std::string& what, const std::string& why);
66void confirm(const std::string& body, const std::string& confirm_label,
67 std::function<void()> on_yes, std::function<void()> on_no = nullptr, bool danger = false);
70void confirm_danger(const std::string& body, const std::string& confirm_label, std::function<void()> on_yes);
71void info(const std::string& body);
74void qr_dialog(const std::string& body, const std::string& url);
75
79enum class Check
80{
81 Ok,
82 Warn,
83 Bad,
84 Info,
85 Header,
86};
89{
91 std::string text;
92};
94aurore::Box* check_row(const CheckLine& line, float size = 17);
97aurore::Box* checklist_body(const std::string& title, const std::vector<CheckLine>& lines, const std::string& note = "",
98 const std::string& subtitle = "");
101void notice(const char* icon, Check tone, const std::string& title, const std::string& text);
106void hold_confirm(aurore::Box* body, const std::string& hold_label, std::function<void()> on_yes,
107 std::function<void()> on_no = nullptr);
108
112aurore::Dialog* dialog(const std::string& text);
115aurore::Dialog* dialog(const std::string& text, aurore::View* below);
119
121void on_cancel(aurore::Dialog* dialog, std::function<void()> on_cancel);
124void add_cancel(aurore::Dialog* dialog, std::function<void()> cancel);
125
128
140void pick(const std::string& title, const std::vector<std::string>& values, int selected,
141 std::function<void(int)> on_pick, bool checked = true, const std::vector<std::string>& details = {},
142 const std::vector<std::string>& icons = {}, const std::vector<Swatch>& swatches = {});
146void pick_grid(const std::string& title, const std::vector<std::string>& values, const std::vector<std::string>& icons,
147 int selected, std::function<void(int)> on_pick, int columns = 4);
151void pick_marked(const std::string& title, const std::vector<std::string>& values, const std::vector<bool>& marks,
152 int focus, std::function<void(int)> on_pick, const std::vector<std::string>& details = {});
162struct Choice
163{
164 enum class Tone
165 {
166 PLAIN,
167 ON,
168 WARN,
169 DANGER
170 };
171 Choice(std::string text, std::function<void()> action, const char* icon_name = nullptr, std::string detail_text = "",
172 std::string group_name = "", Tone line_tone = Tone::PLAIN)
173 : label(std::move(text))
174 , run(std::move(action))
175 , icon(icon_name)
176 , detail(std::move(detail_text))
177 , group(std::move(group_name))
178 , tone(line_tone)
179 {
180 }
181 Choice& switched(bool on)
182 {
183 this->toggle = on ? 1 : 0;
184 return *this;
185 }
186 std::string label;
187 std::function<void()> run;
188 const char* icon;
189 std::string detail;
190 std::string group;
192 int toggle = -1;
193};
195void pick_actions(const std::string& title, const std::vector<Choice>& choices, const std::string& subtitle = "",
196 int image = 0);
199
201void prompt_text(const std::string& header, const std::string& initial, int max_len,
202 std::function<void(std::string)> on_value);
203
208void show_writable(aurore::DetailCell* cell, bool writable, const char* title_key = "cadran/text",
209 const char* detail_key = "cadran/text2");
210
215void set_visible(aurore::View* view, bool visible);
216
220void set_visible_all(std::initializer_list<std::pair<aurore::View*, bool>> changes);
221
225void set_text(aurore::Label* label, const std::string& text);
226void set_detail(aurore::DetailCell* cell, const std::string& text);
227
232void batch_layout(aurore::Box* box, const std::function<void()>& fill);
233
240void keep_focus(aurore::Activity* activity, aurore::View* fallback = nullptr);
241
248bool on_top(aurore::Activity* activity);
253void open_tab(int position, const std::string& row = "");
257
261void go_to_tab(aurore::View* from, int position);
264void open_screen(aurore::View* content, const std::string& title);
265
277void pick_language(std::function<void()> after = nullptr);
278void pick_theme(std::function<void()> after = nullptr);
279void pick_palette(std::function<void()> after = nullptr);
280std::string palette_name();
281void pick_text_size(std::function<void()> after = nullptr);
282std::string text_size_name(bool tile = false);
288void pick_rail(std::function<void()> after = nullptr);
289std::string rail_name();
293std::string language_name(bool tile = false);
294std::string theme_name(bool tile = false);
297void quick_settings(std::function<void()> after = nullptr);
298
302
303} // namespace ui
Definition activity.hpp:45
Generic FlexBox layout.
Definition box.hpp:74
Definition cell_detail.hpp:28
Definition dialog.hpp:44
Definition label.hpp:65
Definition view.hpp:232
Definition text.hpp:13
Definition action_sheet.hpp:11
void info(const std::string &body)
void confirm(const std::string &body, const std::string &confirm_label, std::function< void()> on_yes, std::function< void()> on_no=nullptr, bool danger=false)
void error(const std::string &text)
void replace_screen(aurore::Activity *next)
void qr_dialog(const std::string &body, const std::string &url)
void use_font_for(const std::string &locale)
void batch_layout(aurore::Box *box, const std::function< void()> &fill)
std::string language_name(bool tile=false)
void set_text(aurore::Label *label, const std::string &text)
aurore::Box * checklist_body(const std::string &title, const std::vector< CheckLine > &lines, const std::string &note="", const std::string &subtitle="")
void open_tab(int position, const std::string &row="")
std::string text_size_name(bool tile=false)
void show_writable(aurore::DetailCell *cell, bool writable, const char *title_key="cadran/text", const char *detail_key="cadran/text2")
void on_cancel(aurore::Dialog *dialog, std::function< void()> on_cancel)
B closes dialog and runs on_cancel (Aurore's own B only closes it).
void notify(const std::string &text, Toast kind=Toast::Info)
bool save_prefs()
std::string rail_name()
void set_detail(aurore::DetailCell *cell, const std::string &text)
void prompt_text(const std::string &header, const std::string &initial, int max_len, std::function< void(std::string)> on_value)
The system keyboard for a text. The callback only on confirm.
bool is_sheet(aurore::View *view)
The sheet those open: its view, on top of the activities' stack.
void show_failure(const cadran_text::Failure &f)
Toast
Definition ui.hpp:39
aurore::Activity * main_screen()
The main screen, wherever it is in the stack; nullptr before it opens.
void pick_palette(std::function< void()> after=nullptr)
void pick_text_size(std::function< void()> after=nullptr)
void open_screen(aurore::View *content, const std::string &title)
aurore::Dialog * dialog(const std::string &text)
void quick_settings(std::function< void()> after=nullptr)
void pick_rail(std::function< void()> after=nullptr)
aurore::Dialog * box_dialog(aurore::Box *body)
void add_cancel(aurore::Dialog *dialog, std::function< void()> cancel)
void notice(const char *icon, Check tone, const std::string &title, const std::string &text)
void hold_confirm(aurore::Box *body, const std::string &hold_label, std::function< void()> on_yes, std::function< void()> on_no=nullptr)
aurore::Box * check_row(const CheckLine &line, float size=17)
One of them: the mark, then the text (size px).
std::string theme_name(bool tile=false)
void pick_theme(std::function< void()> after=nullptr)
void set_visible_all(std::initializer_list< std::pair< aurore::View *, bool > > changes)
void set_visible(aurore::View *view, bool visible)
void pick(const std::string &title, const std::vector< std::string > &values, int selected, std::function< void(int)> on_pick, bool checked=true, const std::vector< std::string > &details={}, const std::vector< std::string > &icons={}, const std::vector< Swatch > &swatches={})
void refresh_shown_tab()
void pick_actions(const std::string &title, const std::vector< Choice > &choices, const std::string &subtitle="", int image=0)
The sheet of choices (see Choice) under title.
void keep_focus(aurore::Activity *activity, aurore::View *fallback=nullptr)
void pick_grid(const std::string &title, const std::vector< std::string > &values, const std::vector< std::string > &icons, int selected, std::function< void(int)> on_pick, int columns=4)
bool has_focus(aurore::Activity *activity)
void pick_language(std::function< void()> after=nullptr)
void confirm_danger(const std::string &body, const std::string &confirm_label, std::function< void()> on_yes)
bool on_top(aurore::Activity *activity)
void go_to_tab(aurore::View *from, int position)
std::string palette_name()
void pick_marked(const std::string &title, const std::vector< std::string > &values, const std::vector< bool > &marks, int focus, std::function< void(int)> on_pick, const std::vector< std::string > &details={})
void refuse(const std::string &text)
Check
Definition ui.hpp:80
@ Header
not a check: the name of the panel of lines after it
Definition cadran_icon.hpp:76
Definition cadran_text.hpp:34
A line of checklist_body().
Definition ui.hpp:89
Check state
Definition ui.hpp:90
std::string text
Definition ui.hpp:91
Definition ui.hpp:163
Tone
Definition ui.hpp:165
Tone tone
Definition ui.hpp:191
std::function< void()> run
Definition ui.hpp:187
std::string group
Definition ui.hpp:190
const char * icon
Definition ui.hpp:188
int toggle
switched(): 1 on, 0 off
Definition ui.hpp:192
Choice(std::string text, std::function< void()> action, const char *icon_name=nullptr, std::string detail_text="", std::string group_name="", Tone line_tone=Tone::PLAIN)
Definition ui.hpp:171
Choice & switched(bool on)
Definition ui.hpp:181
std::string label
Definition ui.hpp:186
std::string detail
Definition ui.hpp:189