morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
backend.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4#include <cstddef>
5#include <cstdint>
6#include <functional>
7#include <memory>
8#include <optional>
9#include <string>
10#include <string_view>
11#include <vector>
12
13#include "../util/datetime.hpp"
14#include "view.hpp"
15
16/// @file
17/// @brief The backend contract: the retained widgets a mount drives, and the factory that makes them.
18///
19/// Specified in `docs/spec/ui/backend_contract.md`.
20
21namespace morph::ui {
22
23/// @brief A retained widget. A new widget is visible, enabled, content-sized, not draggable and not a drop target.
24///
25/// Its destructor detaches it from its parent and frees its native resources; no handler of the widget runs after
26/// the destructor returns. A handler may destroy its own widget: the backend keeps the handler alive until that call
27/// returns, for example by calling a copy. A backend may assume a handler, a drop's `accepts` predicate included,
28/// never throws: the mount catches and reports what one throws. Every setter takes UTF-8.
29///
30/// A setter called with the value the widget already shows changes nothing: a text input keeps its cursor, its
31/// selection and an input method's composition. Input widgets are controlled: a user's action changes what the
32/// widget shows, as the toolkit does, and reports the request through the handler; the mount then shows what the
33/// application's slot says, in a turn posted after the request's flush, so a refused request snaps back.
34class Widget {
35public:
36 Widget() = default;
37 virtual ~Widget() = default;
38 Widget(Widget const&) = delete;
39 Widget& operator=(Widget const&) = delete;
40 Widget(Widget&&) = delete;
41 Widget& operator=(Widget&&) = delete;
42
43 /// @brief Shows or hides the widget and everything inside it.
44 /// @param visible Whether it is shown.
45 virtual void setVisible(bool visible) = 0;
46
47 /// @brief Enables or disables input on the widget and everything inside it.
48 /// @param enabled Whether it accepts input.
49 virtual void setEnabled(bool enabled) = 0;
50
51 /// @brief Sets the size request.
52 /// @param hints The request in both dimensions.
53 virtual void setLayout(LayoutHints const& hints) = 0;
54
55 /// @brief Makes the widget draggable, carrying @p key, or not draggable.
56 /// @param key Engaged: the key a drop delivers. `nullopt`: not draggable.
57 virtual void setDragKey(std::optional<Key> const& key) = 0;
58
59 /// @brief Makes the widget a drop target.
60 /// @param accepts Whether a dragged key may be dropped here; the backend asks before highlighting.
61 /// @param onDrop Called with the key on a drop that `accepts` allowed.
62 virtual void setDropHandler(std::function<bool(Key const&)> accepts, std::function<void(Key)> onDrop) = 0;
63
64 /// @brief Sets the name assistive technology reads for the widget.
65 /// @param name The accessible name; empty leaves the widget's own text as its name.
66 virtual void setAccessibleName(std::string_view name) = 0;
67
68 /// @brief Sets the role assistive technology announces for the widget.
69 /// @param role The role, such as `"heading"`; empty leaves the kind's own role.
70 virtual void setAccessibleRole(std::string_view role) = 0;
71
72 /// @brief Sets the stable identifier an automated test finds the widget by.
73 /// @param testId The identifier; empty means none.
74 virtual void setTestId(std::string_view testId) = 0;
75
76 /// @brief Sets the text shown while the pointer rests on the widget.
77 /// @param text The tooltip; empty shows none.
78 virtual void setTooltip(std::string_view text) = 0;
79
80 /// @brief Styles the widget and everything inside it with a named token set of the theme.
81 /// @param surface The surface's name; empty is the theme's default.
82 virtual void setSurface(std::string_view surface) = 0;
83
84 /// @brief Declares the keyboard chords the widget handles while focus is inside it.
85 ///
86 /// A chord pressed while focus is inside several widgets that declare it goes to the innermost of them only.
87 /// @param chords The chords, each modifiers joined to a key name, such as `"Ctrl+S"`.
88 /// @param onChord Called with the chord that was pressed.
89 virtual void setKeys(std::vector<std::string> const& chords, std::function<void(std::string)> onChord) = 0;
90
91 /// @brief Moves keyboard focus to the widget.
92 virtual void focus() = 0;
93
94 /// @brief Calls @p onHover each time the pointer comes to rest over the widget. A backend without a pointer, or
95 /// one that does not report hovering, keeps the default, which never calls it: hovering is a hint, such as
96 /// a prefetch, never something a widget relies on.
97 /// @param onHover The handler; empty stops calling one.
98 // NOLINTNEXTLINE(performance-unnecessary-value-param): a sink every override moves from; the default drops it.
99 virtual void setOnHover(std::function<void()> onHover) { static_cast<void>(onHover); }
100};
101
102/// @brief A widget with children. A factory given this container appends the new widget as its last child.
103class ContainerWidget : public Widget {
104public:
105 /// @brief Moves @p child to position @p index: it is removed, then inserted before the child now at @p index.
106 ///
107 /// The child is moved, not recreated: it keeps its native state, such as its properties, handlers, focus and
108 /// selection.
109 /// @param child One of this container's children.
110 /// @param index The new position; past the end means last.
111 virtual void moveChild(Widget& child, std::size_t index) = 0;
112};
113
114/// @brief A widget that shows a value: text, or an input. A new field is editable, not required, without errors and
115/// not stale.
116class FieldWidget : public Widget {
117public:
118 /// @brief Makes the value read-only or editable again. A read-only field still takes focus and lets its text be
119 /// selected, and reports no edit, submit or commit.
120 /// @param readonly Whether the user may not change the value.
121 virtual void setReadOnly(bool readonly) = 0;
122
123 /// @brief Shows or clears the mark of a field that must be given.
124 /// @param required Whether to show the mark.
125 virtual void setRequired(bool required) = 0;
126
127 /// @brief Replaces the messages shown with the field.
128 /// @param errors The messages, in order, UTF-8; empty shows none.
129 virtual void setErrors(std::vector<std::string> const& errors) = 0;
130
131 /// @brief Shows or clears the mark of a value that is being recomputed.
132 /// @param stale Whether the value shown is the last known one.
133 virtual void setStale(bool stale) = 0;
134};
135
136/// @brief Read-only text.
137class TextWidget : public FieldWidget {
138public:
139 /// @brief Replaces the text.
140 /// @param text The text, UTF-8.
141 virtual void setText(std::string_view text) = 0;
142
143 /// @brief Sets the style.
144 /// @param role The role, mapped to the backend's theme.
145 virtual void setRole(TextRole role) = 0;
146};
147
148/// @brief A push button.
149class ButtonWidget : public Widget {
150public:
151 /// @brief Replaces the caption.
152 /// @param label The caption, UTF-8.
153 virtual void setLabel(std::string_view label) = 0;
154
155 /// @brief Sets what activation calls (Enter, Space or a click).
156 /// @param onClick The handler; empty does nothing.
157 virtual void setOnClick(Action onClick) = 0;
158
159 /// @brief Sets how much the button stands out. The mount calls it only for another value than `Normal`.
160 /// @param emphasis The emphasis.
161 virtual void setEmphasis(ButtonEmphasis emphasis) = 0;
162
163 /// @brief Sets the icon drawn beside the caption; called once, and only for a button that has one.
164 /// @param icon The name of an icon in the theme's icon set.
165 virtual void setIcon(std::string_view icon) = 0;
166
167 /// @brief Sets how the button is drawn. A new button is a push button; the mount calls it once, only for `Item`.
168 /// @param style The style.
169 virtual void setStyle(ButtonStyle style) = 0;
170
171 /// @brief Marks a list entry as the current one, or clears the mark. A new button is not selected; the mount
172 /// calls it only for an `Item`, when bound or `true`.
173 /// @param selected Whether it is the current one.
174 virtual void setSelected(bool selected) = 0;
175};
176
177/// @brief An editable text field.
179public:
180 /// @brief Replaces the text. Never calls the `onChange` handler. With the text the field already shows, it changes
181 /// nothing: the cursor, the selection and an input method's composition stay as they are.
182 /// @param text The text, UTF-8.
183 virtual void setText(std::string_view text) = 0;
184
185 /// @brief Sets the text shown while the field is empty.
186 /// @param placeholder The text, UTF-8.
187 virtual void setPlaceholder(std::string_view placeholder) = 0;
188
189 /// @brief Sets what a user edit calls, with the whole new text.
190 /// @param onChange The handler; empty does nothing.
191 virtual void setOnChange(std::function<void(std::string)> onChange) = 0;
192
193 /// @brief Sets what a submit (Enter in single-line mode) calls, with the text.
194 /// @param onSubmit The handler; empty does nothing.
195 virtual void setOnSubmit(std::function<void(std::string)> onSubmit) = 0;
196
197 /// @brief Sets what a commit calls, with the text: Enter in single-line mode, before the submit, or focus
198 /// leaving the field after an edit.
199 /// @param onCommit The handler; empty does nothing.
200 virtual void setOnCommit(std::function<void(std::string)> onCommit) = 0;
201
202 /// @brief Sets the unit the input shows, muted, at its trailing edge, inside the field; empty shows none. Called
203 /// only on a single-line or password input.
204 /// @param unit The unit's display text, UTF-8.
205 virtual void setUnit(std::string_view unit) = 0;
206
207 /// @brief Sets the fraction digits a number is entered with: what a backend or a kit may use to align or
208 /// format the text. Nothing is required of a backend that draws nothing from it. Called only on a
209 /// single-line or password input.
210 /// @param decimals The places, from 0; -1 when the input does not hold a number.
211 virtual void setDecimals(int decimals) = 0;
212
213 /// @brief Sets the icon drawn at the field's leading edge; empty shows none. Called once, and only for a
214 /// single-line or password input that has one.
215 /// @param icon An icon name of the theme's icon set.
216 virtual void setIcon(std::string_view icon) = 0;
217
218 /// @brief Sets the field's label, and whether the input draws it as a visible caption above its control.
219 /// Without `shown`, the caption is drawn elsewhere (a form's cell), or not at all.
220 /// @param label The label, UTF-8.
221 /// @param shown Whether the input shows it.
222 virtual void setCaption(std::string_view label, bool shown) = 0;
223};
224
225/// @brief A labelled check box.
227public:
228 /// @brief Replaces the caption.
229 /// @param label The caption, UTF-8.
230 virtual void setLabel(std::string_view label) = 0;
231
232 /// @brief Sets the state. Never calls the `onToggle` handler.
233 /// @param checked Whether it is checked.
234 virtual void setChecked(bool checked) = 0;
235
236 /// @brief Sets what a user toggle calls, with the new state.
237 /// @param onToggle The handler; empty does nothing.
238 virtual void setOnToggle(std::function<void(bool)> onToggle) = 0;
239};
240
241/// @brief A choice of one keyed option.
242///
243/// The widget keeps the key last requested by `setSelected` or chosen by the user, and marks the option with that key
244/// whenever the current options contain one. A key outside the options marks none, and stays requested: options that
245/// bring it back mark it again. Options and selection may therefore arrive in either order.
246class SelectWidget : public FieldWidget {
247public:
248 /// @brief Replaces the options, and marks the requested key's option if they contain it.
249 /// @param options The options, in order.
250 virtual void setOptions(std::vector<SelectOption> const& options) = 0;
251
252 /// @brief Requests the option with @p key. It is marked while the options contain it; otherwise none is marked.
253 /// Never calls `onSelect`.
254 /// @param key The key, or `nullopt` for no selection.
255 virtual void setSelected(std::optional<Key> const& key) = 0;
256
257 /// @brief Sets what a user choice calls, with the option's key.
258 /// @param onSelect The handler; empty does nothing.
259 virtual void setOnSelect(std::function<void(Key)> onSelect) = 0;
260
261 /// @brief Calls @p onOpen each time the user opens the dropdown, also when it has no options to show. A radio
262 /// group, and a backend that does not report opening, keep the default, which never calls it: opening is a
263 /// hint, such as a retry of a failed fetch of the options, never something a select relies on.
264 /// @param onOpen The handler; empty stops calling one.
265 // NOLINTNEXTLINE(performance-unnecessary-value-param): a sink every override moves from; the default drops it.
266 virtual void setOnOpen(Action onOpen) { static_cast<void>(onOpen); }
267
268 /// @brief Sets the field's label, and whether the input draws it as a visible caption above its control.
269 /// Without `shown`, the caption is drawn elsewhere (a form's cell), or not at all.
270 /// @param label The label, UTF-8.
271 /// @param shown Whether the input shows it.
272 virtual void setCaption(std::string_view label, bool shown) = 0;
273};
274
275/// @brief One entry of a menu as a `MenuWidget` shows it.
276struct MenuEntry {
277 /// @brief The caption.
278 std::string label;
279 /// @brief The icon's name in the theme's icon map; empty shows none.
280 std::string icon;
281 /// @brief The chord shown beside the label; empty shows none.
282 std::string keys;
283 /// @brief Engaged: a checkable entry with this mark; `nullopt`: not checkable.
284 std::optional<bool> checked;
285 /// @brief Whether the entry can be chosen, or its submenu opened.
286 bool enabled = true;
287 /// @brief The submenu; empty for an entry that is chosen.
288 std::vector<MenuEntry> items;
289
290 /// @brief Memberwise equality, submenus included.
291 /// @return Whether every field matches.
292 bool operator==(MenuEntry const&) const = default;
293};
294
295/// @brief A menu of commands, with nested submenus.
296class MenuWidget : public Widget {
297public:
298 /// @brief Replaces the entries.
299 /// @param entries The entries, in order, each with its submenu.
300 virtual void setItems(std::vector<MenuEntry> const& entries) = 0;
301
302 /// @brief Sets what choosing an entry calls, with its path.
303 ///
304 /// Only an enabled entry without a submenu, inside enabled entries, can be chosen.
305 /// @param onActivate The handler, given the entry's index at each level from the top; empty does nothing.
306 virtual void setOnActivate(std::function<void(std::vector<std::size_t>)> onActivate) = 0;
307};
308
309/// @brief Children stacked along one axis, fixed at creation.
311public:
312 /// @brief Sets the space between children.
313 /// @param gap A spacing step, 0 to `kMaxSpacingStep`; the mount never passes another value.
314 virtual void setGap(int gap) = 0;
315
316 /// @brief Places the children across the axis. A new stack stretches them; a child's own `alignSelf` wins.
317 /// @param align Where they sit.
318 virtual void setAlign(Align align) = 0;
319
320 /// @brief Places the spare length along the axis while no shown child stretches. A new stack packs at the start.
321 /// @param justify Where it goes.
322 virtual void setJustify(Justify justify) = 0;
323};
324
325/// @brief Children laid out row-major in columns.
327public:
328 /// @brief Sets the column count.
329 /// @param columns At least one.
330 virtual void setColumns(int columns) = 0;
331
332 /// @brief Sets the space between cells.
333 /// @param gap A spacing step, 0 to `kMaxSpacingStep`; the mount never passes another value.
334 virtual void setGap(int gap) = 0;
335
336 /// @brief Sets how many columns a child spans; a child spans one until this is called.
337 /// @param child One of this grid's children.
338 /// @param span The column count it occupies.
339 virtual void setSpan(Widget& child, int span) = 0;
340
341 /// @brief Places each cell's content vertically in its row. A new grid stretches it; a child's own `alignSelf`
342 /// wins.
343 /// @param align Where it sits.
344 virtual void setAlign(Align align) = 0;
345};
346
347/// @brief Empty space.
348class SpacerWidget : public Widget {};
349
350/// @brief A titled frame around its children, optionally collapsible.
352public:
353 /// @brief Replaces the title.
354 /// @param title The title, UTF-8.
355 virtual void setTitle(std::string_view title) = 0;
356
357 /// @brief Sets the space between frame and content.
358 /// @param padding A spacing step, 0 to `kMaxSpacingStep`; the mount never passes another value.
359 virtual void setPadding(int padding) = 0;
360
361 /// @brief Sets whether the user can collapse the panel.
362 /// @param collapsible Whether a collapse control is shown.
363 virtual void setCollapsible(bool collapsible) = 0;
364
365 /// @brief Shows one of its children beside the title; called at most once. The header stays visible and usable
366 /// while the panel is collapsed.
367 /// @param header A child of this widget.
368 virtual void setHeader(Widget& header) = 0;
369
370 /// @brief Collapses or expands the panel. A collapsed panel hides its content, which takes no input; its own
371 /// collapse control still works. The header is not part of "its content" for this purpose: it stays
372 /// shown and usable while collapsed. Never calls the `onToggle` handler.
373 /// @param collapsed Whether the content is hidden.
374 virtual void setCollapsed(bool collapsed) = 0;
375
376 /// @brief Sets what a user collapse or expand calls, with the requested state.
377 /// @param onToggle The handler; empty does nothing.
378 virtual void setOnToggle(std::function<void(bool)> onToggle) = 0;
379};
380
381/// @brief A scrollable viewport, on the axis fixed at creation, that keeps the focused child visible.
383
384/// @brief A container that shows its children and nothing else: the host of a Switch's case and of a Tabs page.
385class SlotWidget : public ContainerWidget {};
386
387/// @brief A tab bar over page slots.
388///
389/// Its children are page slots in the order they were first shown; the mount keeps exactly the selected page's
390/// slot visible. `setSelected` moves the bar's highlight only.
392public:
393 /// @brief Replaces the tab captions.
394 /// @param labels One caption per tab, in order.
395 virtual void setTabs(std::vector<std::string> const& labels) = 0;
396
397 /// @brief Highlights a tab. Never calls the `onSelect` handler.
398 /// @param index The tab; past the last one highlights none.
399 virtual void setSelected(std::size_t index) = 0;
400
401 /// @brief Sets what a user's tab choice calls, with its index.
402 /// @param onSelect The handler; empty does nothing.
403 virtual void setOnSelect(std::function<void(std::size_t)> onSelect) = 0;
404
405 /// @brief Shows or hides the strip of tab buttons. The selected page shows either way. A new tabs widget shows
406 /// its strip.
407 /// @param shown Whether the strip is drawn.
408 virtual void setBarShown(bool shown) = 0;
409};
410
411/// @brief A modal overlay around its children, with a focus trap while open. A new dialog is closed.
412///
413/// A closed dialog shows nothing and takes no input, its children included. A user's dismissal closes it, as the
414/// toolkit does, before `onDismiss` runs; an application that keeps it open opens it again.
416public:
417 /// @brief Shows or hides the overlay.
418 /// @param open Whether it is shown.
419 virtual void setOpen(bool open) = 0;
420
421 /// @brief Replaces the title.
422 /// @param title The title, UTF-8.
423 virtual void setTitle(std::string_view title) = 0;
424
425 /// @brief Sets what a user dismissal (Esc on the TUI) of the open dialog calls.
426 /// @param onDismiss The handler; empty does nothing.
427 virtual void setOnDismiss(Action onDismiss) = 0;
428
429 /// @brief The dialog's footer: a container it lays out after its content, which shows nothing while it is empty.
430 /// The mount puts the dialog's actions here.
431 /// @return It, owned by the dialog and valid as long as the dialog.
432 virtual ContainerWidget& footer() = 0;
433};
434
435/// @brief A progress indicator.
436class BusyWidget : public Widget {
437public:
438 /// @brief Starts or stops the animation.
439 /// @param active Whether it animates.
440 virtual void setActive(bool active) = 0;
441
442 /// @brief Replaces the caption.
443 /// @param label The caption, UTF-8.
444 virtual void setLabel(std::string_view label) = 0;
445};
446
447/// @brief Keyed rows under column headers, with selection and activation by key.
448///
449/// Its children are the rows, each a horizontal stack whose children are the cells in column order. A hidden cell
450/// keeps its column: the cells after it stay under their own headers.
451///
452/// Selection is kept by key. The widget keeps the keys last requested by `setSelection` or selected by the user, and
453/// marks the current rows that have one of them: a key with no row marks nothing and stays requested, so a row that
454/// arrives with it later is marked, a row that goes is unmarked, and a reorder keeps the marks. Rows and selection
455/// may therefore arrive in either order. The selection mode limits what the user can select, not what `setSelection`
456/// marks.
457///
458/// A user's selection replaces the requested keys, and the widget shows it whether or not the application binds the
459/// selection. `onSelectionChange` then gets exactly the keys of the existing rows now selected, in any mode: a key
460/// still waiting for its row is dropped by a user's change, while `setSelection` keeps it waiting. It reports the
461/// user's selections only: no setter, and no row arriving or going, calls it.
463public:
464 /// @brief Sets the column headers and widths.
465 /// @param columns The columns, in order.
466 virtual void setColumns(std::vector<TableColumn> const& columns) = 0;
467
468 /// @brief Sets whether the header row is drawn.
469 /// @param shown `false` suits several tables sharing one visual header.
470 virtual void setShowHeader(bool shown) = 0;
471
472 /// @brief Sets how many rows the user can select.
473 /// @param mode None, one, or any number.
474 virtual void setSelectionMode(SelectionMode mode) = 0;
475
476 /// @brief Tells the table which key a row stands for; called once per row, right after it is built. Marks the row
477 /// when its key is requested.
478 /// @param row One of this table's rows.
479 /// @param key The row's key.
480 virtual void setRowKey(Widget& row, Key const& key) = 0;
481
482 /// @brief Sets a row's tone; called after `setRowKey` for a row given a tone, and on every change.
483 /// @param row One of this table's rows.
484 /// @param tone The tone, or none.
485 virtual void setRowTone(Widget& row, std::optional<Tone> tone) = 0;
486
487 /// @brief Requests the rows with these keys, and marks those it has. Never calls the `onSelectionChange` handler.
488 /// @param keys The selected keys.
489 virtual void setSelection(std::vector<Key> const& keys) = 0;
490
491 /// @brief Sets what a user's selection change calls, with the keys of every row then selected.
492 /// @param onSelectionChange The handler; empty does nothing.
493 virtual void setOnSelectionChange(std::function<void(std::vector<Key>)> onSelectionChange) = 0;
494
495 /// @brief Sets what activating a row (Enter or a double click) calls, with its key.
496 /// @param onActivate The handler; empty does nothing.
497 virtual void setOnActivate(std::function<void(Key)> onActivate) = 0;
498
499 /// @brief Tells the backend how many of the table's rows are realized, where, and how many exist in total, so
500 /// it can size a scrollbar and place leading/trailing space for the rows that are not realized. A
501 /// backend that never virtualizes (the default for every implementer but a windowed Qt Quick table)
502 /// never calls `setOnVisibleRangeChanged`, so this is never called either.
503 /// @param first The view index of the first realized row.
504 /// @param count How many rows are realized, starting at `first`.
505 /// @param total How many rows the table's data has, realized or not.
506 virtual void setRealizedWindow(std::size_t first, std::size_t count, std::size_t total) {
507 static_cast<void>(first);
508 static_cast<void>(count);
509 static_cast<void>(total);
510 }
511
512 /// @brief Sets what the backend calls when the user scrolls, asking the mount to realize roughly this range of
513 /// rows next. A backend that never virtualizes leaves this empty; the mount then never dewindows a row.
514 /// @param onVisibleRangeChanged The handler, with the first view index and how many rows are wanted from there;
515 /// empty does nothing.
516 virtual void setOnVisibleRangeChanged(std::function<void(std::size_t, std::size_t)> onVisibleRangeChanged) {
517 static_cast<void>(onVisibleRangeChanged);
518 }
519
520 /// @brief Tells the backend every key currently in the table's data, realized or not -- called whenever that
521 /// set changes (a data change, or a scroll that dewindows or re-realizes a row). A virtualized backend
522 /// needs this to know a selected key still exists in the data when it has no realized row for it right
523 /// now (`setRowKey` alone cannot say that, since it is only ever called for a realized row): without
524 /// it, a backend that reconstructs "does this key still exist" purely from its realized children would
525 /// silently drop a selected key's membership the moment its row scrolls out of view. A backend that
526 /// never virtualizes may ignore this -- every key it cares about already has a realized row, by
527 /// definition, so `setRowKey` alone already tells it everything this call would add.
528 /// @param keys Every key currently in the table's data, in no particular order.
529 virtual void setExistingKeys(std::vector<Key> const& keys) { static_cast<void>(keys); }
530};
531
532/// @brief A date or date-and-time field, in the mode and display zone fixed at creation.
534public:
535 /// @brief Shows an instant. Never calls the `onChange` handler.
536 /// @param value The instant; `nullopt` or an empty `Timestamp` shows an empty field.
537 virtual void setValue(std::optional<morph::time::Timestamp> const& value) = 0;
538
539 /// @brief Sets what a user edit calls, with the instant entered or `nullopt` for a cleared field.
540 /// @param onChange The handler; empty does nothing.
541 virtual void setOnChange(std::function<void(std::optional<morph::time::Timestamp>)> onChange) = 0;
542
543 /// @brief Sets the field's label, and whether the input draws it as a visible caption above its control.
544 /// Without `shown`, the caption is drawn elsewhere (a form's cell), or not at all.
545 /// @param label The label, UTF-8.
546 /// @param shown Whether the input shows it.
547 virtual void setCaption(std::string_view label, bool shown) = 0;
548};
549
550/// @brief An integer on a range.
551class SliderWidget : public FieldWidget {
552public:
553 /// @brief Sets the range and the increment.
554 /// @param minimum The smallest value.
555 /// @param maximum The largest value.
556 /// @param step The increment between neighbouring values.
557 virtual void setRange(std::int64_t minimum, std::int64_t maximum, std::int64_t step) = 0;
558
559 /// @brief Shows a value. Never calls the `onChange` handler.
560 /// @param value The value.
561 virtual void setValue(std::int64_t value) = 0;
562
563 /// @brief Sets what a user move calls, with the new value.
564 /// @param onChange The handler; empty does nothing.
565 virtual void setOnChange(std::function<void(std::int64_t)> onChange) = 0;
566
567 /// @brief Sets what a finished move calls, with the value it ended on: a release after a drag, a key step, or a
568 /// wheel step.
569 /// @param onCommit The handler; empty does nothing.
570 virtual void setOnCommit(std::function<void(std::int64_t)> onCommit) = 0;
571};
572
573/// @brief A file path field, in the mode fixed at creation.
575public:
576 /// @brief Shows a path. Never calls the `onPicked` handler.
577 /// @param path The path, UTF-8.
578 virtual void setPath(std::string_view path) = 0;
579
580 /// @brief Sets what a user pick calls, with the path.
581 /// @param onPicked The handler; empty does nothing.
582 virtual void setOnPicked(std::function<void(std::string)> onPicked) = 0;
583};
584
585/// @brief A message across the top of a region, with an optional action button and an optional dismissal.
586class BannerWidget : public Widget {
587public:
588 /// @brief Sets what the message conveys.
589 /// @param tone The tone, mapped to the backend's theme.
590 virtual void setTone(Tone tone) = 0;
591
592 /// @brief Replaces the message.
593 /// @param text The message, UTF-8.
594 virtual void setText(std::string_view text) = 0;
595
596 /// @brief Replaces the action button's caption.
597 /// @param label The caption, UTF-8; empty shows no button.
598 virtual void setActionLabel(std::string_view label) = 0;
599
600 /// @brief Sets what activating the action button calls.
601 /// @param onAction The handler; empty does nothing.
602 virtual void setOnAction(Action onAction) = 0;
603
604 /// @brief Sets whether the user can dismiss the banner; called once, before the banner is shown.
605 /// @param dismissible Whether to offer the dismissal.
606 virtual void setDismissible(bool dismissible) = 0;
607
608 /// @brief Sets what a dismissal calls. A dismissal leaves the banner shown: the application hides it.
609 /// @param onDismiss The handler; empty does nothing.
610 virtual void setOnDismiss(Action onDismiss) = 0;
611};
612
613/// @brief A passive, transient message outside the normal flow: non-modal, dims nothing, and never takes keyboard
614/// focus. Auto-dismisses after a backend-chosen interval.
615class ToastWidget : public Widget {
616public:
617 /// @brief Shows the message, replacing any shown or dismissing, and (re)starts the dismissal interval regardless
618 /// of whether the toast is already on-screen — a second call while one is showing replaces its text and
619 /// tone and restarts the interval, rather than being a no-op or stacking a second message.
620 /// @param text The message, UTF-8.
621 /// @param tone The tone, mapped to the backend's theme.
622 virtual void show(std::string_view text, Tone tone) = 0;
623};
624
625/// @brief A short label marking a state.
626class BadgeWidget : public Widget {
627public:
628 /// @brief Sets what the mark conveys.
629 /// @param tone The tone, mapped to the backend's theme.
630 virtual void setTone(Tone tone) = 0;
631
632 /// @brief Replaces the label.
633 /// @param text The label, UTF-8.
634 virtual void setText(std::string_view text) = 0;
635
636 /// @brief Sets the icon; called once.
637 /// @param icon The name of an icon in the theme's icon map; empty shows none.
638 virtual void setIcon(std::string_view icon) = 0;
639};
640
641/// @brief A progress bar.
642class ProgressWidget : public Widget {
643public:
644 /// @brief Sets how far along it is.
645 /// @param value From 0 to 1, a value outside shown at the nearer end; `nullopt` shows an indeterminate bar.
646 virtual void setValue(std::optional<double> value) = 0;
647
648 /// @brief Replaces the caption beside the bar.
649 /// @param label The caption, UTF-8.
650 virtual void setLabel(std::string_view label) = 0;
651};
652
653/// @brief The steps of a process, each with its state.
654class StepsWidget : public Widget {
655public:
656 /// @brief Replaces the steps.
657 /// @param steps The steps, in order.
658 virtual void setSteps(std::vector<Step> const& steps) = 0;
659
660 /// @brief Highlights one step.
661 /// @param index The step's position; `nullopt` or a position past the last highlights none.
662 virtual void setCurrent(std::optional<std::size_t> index) = 0;
663};
664
665/// @brief Captions beside their values.
666class KeyValueWidget : public Widget {
667public:
668 /// @brief Replaces the pairs.
669 /// @param items The pairs, in order.
670 virtual void setItems(std::vector<KeyValueItem> const& items) = 0;
671};
672
673/// @brief What a region shows when it has nothing to show.
674class EmptyStateWidget : public Widget {
675public:
676 /// @brief Replaces the title.
677 /// @param title The title, UTF-8.
678 virtual void setTitle(std::string_view title) = 0;
679
680 /// @brief Replaces the explanation.
681 /// @param text The explanation, UTF-8.
682 virtual void setText(std::string_view text) = 0;
683
684 /// @brief Sets the icon; called once.
685 /// @param icon The name of an icon in the theme's icon map; empty shows none.
686 virtual void setIcon(std::string_view icon) = 0;
687
688 /// @brief Replaces the action button's caption.
689 /// @param label The caption, UTF-8; empty shows no button.
690 virtual void setActionLabel(std::string_view label) = 0;
691
692 /// @brief Sets what activating the action button calls.
693 /// @param onAction The handler; empty does nothing.
694 virtual void setOnAction(Action onAction) = 0;
695};
696
697/// @brief A panel over the content that slides in from the side fixed at creation; it follows a dialog's rules. A new
698/// drawer is closed.
700public:
701 /// @brief Shows or hides it. Never calls the `onDismiss` handler.
702 /// @param open Whether it is shown.
703 virtual void setOpen(bool open) = 0;
704
705 /// @brief Replaces the title.
706 /// @param title The title, UTF-8.
707 virtual void setTitle(std::string_view title) = 0;
708
709 /// @brief Sets what a user dismissal (Esc on the TUI) calls.
710 /// @param onDismiss The handler; empty does nothing.
711 virtual void setOnDismiss(Action onDismiss) = 0;
712
713 /// @brief The drawer's footer: a container it lays out after its content, which shows nothing while it is empty.
714 /// The mount puts the drawer's actions here.
715 /// @return It, owned by the drawer and valid as long as the drawer.
716 virtual ContainerWidget& footer() = 0;
717};
718
719/// @brief Panes along the axis fixed at creation, with handles between them that the user drags.
721public:
722 /// @brief Sets each pane's size. Never calls the `onResize` handler.
723 /// @param sizes Each pane's size, in backend units, in order; a list that is empty or whose length differs from
724 /// the number of panes shares the space equally.
725 virtual void setSizes(std::vector<int> const& sizes) = 0;
726
727 /// @brief Sets what dragging a handle calls, with every pane's size once the user lets go.
728 /// @param onResize The handler; empty does nothing.
729 virtual void setOnResize(std::function<void(std::vector<int>)> onResize) = 0;
730};
731
732/// @brief A titled section the user opens and closes. A new collapsible is open.
733///
734/// A widget inside it takes no input while it is closed, except the header and everything inside the header.
736public:
737 /// @brief Replaces the title.
738 /// @param title The title, UTF-8.
739 virtual void setTitle(std::string_view title) = 0;
740
741 /// @brief Shows one of its children beside the title, open or closed; called at most once.
742 /// @param header A child of this widget.
743 virtual void setHeader(Widget& header) = 0;
744
745 /// @brief Opens or closes it. Never calls the `onToggle` handler.
746 /// @param open Whether the content is shown.
747 virtual void setOpen(bool open) = 0;
748
749 /// @brief Sets what the user opening or closing it calls.
750 /// @param onToggle The handler, given the state the user asked for; empty does nothing.
751 virtual void setOnToggle(std::function<void(bool)> onToggle) = 0;
752};
753
754/// @brief A region that takes files dropped from the operating system.
756public:
757 /// @brief Sets the extensions it takes; called once.
758 /// @param extensions Such as `".csv"`, compared without regard to case; empty takes every file.
759 virtual void setAccept(std::vector<std::string> const& extensions) = 0;
760
761 /// @brief Sets whether a drop may carry more than one file; called once.
762 /// @param multiple Whether several files are taken at once.
763 virtual void setMultiple(bool multiple) = 0;
764
765 /// @brief Sets what a drop it takes calls. A drop with a file outside the accepted extensions, or with several
766 /// files when only one is taken, is refused whole and calls nothing.
767 /// @param onDrop The handler, given the paths in the order dropped; empty does nothing.
768 virtual void setOnDrop(std::function<void(std::vector<std::string>)> onDrop) = 0;
769};
770
771/// @brief A component a renderer loaded in a `custom` node's place (spec 5 §10): a bundle's verified QML or a host
772/// component, given the props the document binds and handing back the events it raises.
773class CustomWidget : public Widget {
774public:
775 /// @brief Sets a text prop: `string`, and `int`, `exact` and `json`, which cross as text so that no value loses
776 /// precision.
777 /// @param name The prop.
778 /// @param value Its text.
779 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters): a prop's name, then its value, as every setter takes them.
780 virtual void setTextProp(std::string_view name, std::string_view value) = 0;
781
782 /// @brief Sets a `bool` prop.
783 /// @param name The prop.
784 /// @param value Its value.
785 virtual void setBoolProp(std::string_view name, bool value) = 0;
786
787 /// @brief Sets a `number` prop: the one kind of value that crosses as a double.
788 /// @param name The prop.
789 /// @param value Its value.
790 virtual void setNumberProp(std::string_view name, double value) = 0;
791
792 /// @brief Hands over the handler of the component's events.
793 /// @param onEvent Called with the event's name and its payload as text (a key as `i:<int64>` or `s:<text>`,
794 /// anything else as the component wrote it); empty does nothing.
795 virtual void setOnEvent(std::function<void(std::string event, std::string payload)> onEvent) = 0;
796};
797
798/// @brief What `IViewBackend::createCustom` asks for.
800 /// @brief The component's name, as the document's `components` declares it.
801 std::string name;
802 /// @brief The props the document declares for it; a component that does not declare each one is refused.
803 std::vector<std::string> props;
804 /// @brief The lowest version of a host component that will do; a bundle component ignores it.
805 int minVersion = 0;
806};
807
808/// @brief Makes widgets. Each factory appends the new widget to @p parent, or makes a root when it is null, and never
809/// returns null, except `createCustom`, whose null shows a custom node's fallback.
810class IViewBackend {
811public:
812 IViewBackend() = default;
813 virtual ~IViewBackend() = default;
814 IViewBackend(IViewBackend const&) = delete;
815 IViewBackend& operator=(IViewBackend const&) = delete;
816 IViewBackend(IViewBackend&&) = delete;
817 IViewBackend& operator=(IViewBackend&&) = delete;
818
819 /// @brief Makes read-only text.
820 /// @param parent The container to append to, or null for a root.
821 /// @return The widget.
822 [[nodiscard]] virtual std::unique_ptr<TextWidget> createText(ContainerWidget* parent) = 0;
823
824 /// @brief Makes a push button.
825 /// @param parent The container to append to, or null for a root.
826 /// @return The widget.
827 [[nodiscard]] virtual std::unique_ptr<ButtonWidget> createButton(ContainerWidget* parent) = 0;
828
829 /// @brief Makes a text field.
830 /// @param parent The container to append to, or null for a root.
831 /// @param mode Single-line, multiline or password.
832 /// @return The widget.
833 [[nodiscard]] virtual std::unique_ptr<TextInputWidget> createTextInput(ContainerWidget* parent,
834 TextInputMode mode) = 0;
835
836 /// @brief Makes a check box.
837 /// @param parent The container to append to, or null for a root.
838 /// @return The widget.
839 [[nodiscard]] virtual std::unique_ptr<CheckboxWidget> createCheckbox(ContainerWidget* parent) = 0;
840
841 /// @brief Makes a choice of one option.
842 /// @param parent The container to append to, or null for a root.
843 /// @param style Dropdown or radio.
844 /// @return The widget.
845 [[nodiscard]] virtual std::unique_ptr<SelectWidget> createSelect(ContainerWidget* parent, SelectStyle style) = 0;
846
847 /// @brief Makes a command list.
848 /// @param parent The container to append to, or null for a root.
849 /// @return The widget.
850 [[nodiscard]] virtual std::unique_ptr<MenuWidget> createMenu(ContainerWidget* parent) = 0;
851
852 /// @brief Makes a stack.
853 /// @param parent The container to append to, or null for a root.
854 /// @param axis Vertical (a column) or horizontal (a row).
855 /// @return The widget.
856 [[nodiscard]] virtual std::unique_ptr<StackWidget> createStack(ContainerWidget* parent, Axis axis) = 0;
857
858 /// @brief Makes a grid.
859 /// @param parent The container to append to, or null for a root.
860 /// @return The widget.
861 [[nodiscard]] virtual std::unique_ptr<GridWidget> createGrid(ContainerWidget* parent) = 0;
862
863 /// @brief Makes empty space.
864 /// @param parent The container to append to, or null for a root.
865 /// @return The widget.
866 [[nodiscard]] virtual std::unique_ptr<SpacerWidget> createSpacer(ContainerWidget* parent) = 0;
867
868 /// @brief Makes a titled frame.
869 /// @param parent The container to append to, or null for a root.
870 /// @return The widget.
871 [[nodiscard]] virtual std::unique_ptr<PanelWidget> createPanel(ContainerWidget* parent) = 0;
872
873 /// @brief Makes a scroll area.
874 /// @param parent The container to append to, or null for a root.
875 /// @param axis The scroll direction.
876 /// @return The widget.
877 [[nodiscard]] virtual std::unique_ptr<ScrollWidget> createScroll(ContainerWidget* parent, Axis axis) = 0;
878
879 /// @brief Makes a slot.
880 /// @param parent The container to append to, or null for a root.
881 /// @return The widget.
882 [[nodiscard]] virtual std::unique_ptr<SlotWidget> createSlot(ContainerWidget* parent) = 0;
883
884 /// @brief Makes a tab bar.
885 /// @param parent The container to append to, or null for a root.
886 /// @return The widget.
887 [[nodiscard]] virtual std::unique_ptr<TabsWidget> createTabs(ContainerWidget* parent) = 0;
888
889 /// @brief Makes a modal overlay.
890 /// @param parent The container to append to, or null for a root.
891 /// @return The widget.
892 [[nodiscard]] virtual std::unique_ptr<DialogWidget> createDialog(ContainerWidget* parent) = 0;
893
894 /// @brief Makes a transient message.
895 /// @param parent The container to append to, or null for a root.
896 /// @return The widget.
897 [[nodiscard]] virtual std::unique_ptr<ToastWidget> createToast(ContainerWidget* parent) = 0;
898
899 /// @brief Makes a progress indicator.
900 /// @param parent The container to append to, or null for a root.
901 /// @return The widget.
902 [[nodiscard]] virtual std::unique_ptr<BusyWidget> createBusy(ContainerWidget* parent) = 0;
903
904 /// @brief Makes a table.
905 /// @param parent The container to append to, or null for a root.
906 /// @return The widget.
907 [[nodiscard]] virtual std::unique_ptr<TableWidget> createTable(ContainerWidget* parent) = 0;
908
909 /// @brief Makes a date or date-and-time field.
910 /// @param parent The container to append to, or null for a root.
911 /// @param mode Date, or date and time.
912 /// @param offsetMinutes The display zone's offset from UTC.
913 /// @return The widget.
914 [[nodiscard]] virtual std::unique_ptr<DateTimeInputWidget> createDateTimeInput(ContainerWidget* parent,
915 DateMode mode,
916 int offsetMinutes) = 0;
917
918 /// @brief Makes a slider.
919 /// @param parent The container to append to, or null for a root.
920 /// @return The widget.
921 [[nodiscard]] virtual std::unique_ptr<SliderWidget> createSlider(ContainerWidget* parent) = 0;
922
923 /// @brief Makes a file path field.
924 /// @param parent The container to append to, or null for a root.
925 /// @param mode Open or save.
926 /// @return The widget.
927 [[nodiscard]] virtual std::unique_ptr<FilePickerWidget> createFilePicker(ContainerWidget* parent,
928 FilePickerMode mode) = 0;
929
930 /// @brief Makes a banner.
931 /// @param parent The container to append to, or null for a root.
932 /// @return The widget.
933 [[nodiscard]] virtual std::unique_ptr<BannerWidget> createBanner(ContainerWidget* parent) = 0;
934
935 /// @brief Makes a badge.
936 /// @param parent The container to append to, or null for a root.
937 /// @return The widget.
938 [[nodiscard]] virtual std::unique_ptr<BadgeWidget> createBadge(ContainerWidget* parent) = 0;
939
940 /// @brief Makes a progress bar.
941 /// @param parent The container to append to, or null for a root.
942 /// @return The widget.
943 [[nodiscard]] virtual std::unique_ptr<ProgressWidget> createProgress(ContainerWidget* parent) = 0;
944
945 /// @brief Makes a steps indicator.
946 /// @param parent The container to append to, or null for a root.
947 /// @return The widget.
948 [[nodiscard]] virtual std::unique_ptr<StepsWidget> createSteps(ContainerWidget* parent) = 0;
949
950 /// @brief Makes a key-value list.
951 /// @param parent The container to append to, or null for a root.
952 /// @return The widget.
953 [[nodiscard]] virtual std::unique_ptr<KeyValueWidget> createKeyValue(ContainerWidget* parent) = 0;
954
955 /// @brief Makes an empty state.
956 /// @param parent The container to append to, or null for a root.
957 /// @return The widget.
958 [[nodiscard]] virtual std::unique_ptr<EmptyStateWidget> createEmptyState(ContainerWidget* parent) = 0;
959
960 /// @brief Makes a drawer.
961 /// @param parent The container to append to, or null for a root.
962 /// @param side The edge it slides in from.
963 /// @return The widget.
964 [[nodiscard]] virtual std::unique_ptr<DrawerWidget> createDrawer(ContainerWidget* parent, Side side) = 0;
965
966 /// @brief Makes a splitter.
967 /// @param parent The container to append to, or null for a root.
968 /// @param axis The axis its panes are laid out along.
969 /// @return The widget.
970 [[nodiscard]] virtual std::unique_ptr<SplitterWidget> createSplitter(ContainerWidget* parent, Axis axis) = 0;
971
972 /// @brief Makes a collapsible section.
973 /// @param parent The container to append to, or null for a root.
974 /// @return The widget.
975 [[nodiscard]] virtual std::unique_ptr<CollapsibleWidget> createCollapsible(ContainerWidget* parent) = 0;
976
977 /// @brief Makes a drop zone.
978 /// @param parent The container to append to, or null for a root.
979 /// @return The widget.
980 [[nodiscard]] virtual std::unique_ptr<DropZoneWidget> createDropZone(ContainerWidget* parent) = 0;
981
982 /// @brief Loads the component a `custom` node names, if this backend can. The only factory that may return null:
983 /// null means "not loaded", and the mount shows the node's fallback instead. A backend that loads no
984 /// components keeps this default.
985 /// @param parent The container to append it to; null makes a root.
986 /// @param request The component, the props the document declares and the host component's lowest version.
987 /// @return The component, or null to show the fallback.
988 [[nodiscard]] virtual std::unique_ptr<CustomWidget> createCustom(ContainerWidget* parent,
989 CustomRequest const& request) {
990 static_cast<void>(parent);
991 static_cast<void>(request);
992 return nullptr;
993 }
994};
995
996} // namespace morph::ui
Justify
Where a stack places its spare length along its axis, while no shown child stretches.
Definition alignment.hpp:23
Align
Where a child is placed across its container's axis: a column's horizontally, a row's vertically,...
Definition alignment.hpp:15
ButtonEmphasis
How much a button stands out; each backend maps it to its theme.
ButtonStyle
How a button is drawn; it behaves the same either way.
A short label marking a state.
Definition backend.hpp:626
virtual void setIcon(std::string_view icon)=0
Sets the icon; called once.
virtual void setTone(Tone tone)=0
Sets what the mark conveys.
virtual void setText(std::string_view text)=0
Replaces the label.
A message across the top of a region, with an optional action button and an optional dismissal.
Definition backend.hpp:586
virtual void setTone(Tone tone)=0
Sets what the message conveys.
virtual void setActionLabel(std::string_view label)=0
Replaces the action button's caption.
virtual void setText(std::string_view text)=0
Replaces the message.
virtual void setOnDismiss(Action onDismiss)=0
Sets what a dismissal calls. A dismissal leaves the banner shown: the application hides it.
virtual void setOnAction(Action onAction)=0
Sets what activating the action button calls.
virtual void setDismissible(bool dismissible)=0
Sets whether the user can dismiss the banner; called once, before the banner is shown.
A progress indicator.
Definition backend.hpp:436
virtual void setActive(bool active)=0
Starts or stops the animation.
virtual void setLabel(std::string_view label)=0
Replaces the caption.
virtual void setLabel(std::string_view label)=0
Replaces the caption.
virtual void setSelected(bool selected)=0
Marks a list entry as the current one, or clears the mark. A new button is not selected; the mount ca...
virtual void setEmphasis(ButtonEmphasis emphasis)=0
Sets how much the button stands out. The mount calls it only for another value than Normal.
virtual void setStyle(ButtonStyle style)=0
Sets how the button is drawn. A new button is a push button; the mount calls it once,...
virtual void setIcon(std::string_view icon)=0
Sets the icon drawn beside the caption; called once, and only for a button that has one.
virtual void setOnClick(Action onClick)=0
Sets what activation calls (Enter, Space or a click).
A labelled check box.
Definition backend.hpp:226
virtual void setLabel(std::string_view label)=0
Replaces the caption.
virtual void setOnToggle(std::function< void(bool)> onToggle)=0
Sets what a user toggle calls, with the new state.
virtual void setChecked(bool checked)=0
Sets the state. Never calls the onToggle handler.
A titled section the user opens and closes. A new collapsible is open.
Definition backend.hpp:735
virtual void setOnToggle(std::function< void(bool)> onToggle)=0
Sets what the user opening or closing it calls.
virtual void setTitle(std::string_view title)=0
Replaces the title.
virtual void setOpen(bool open)=0
Opens or closes it. Never calls the onToggle handler.
virtual void setHeader(Widget &header)=0
Shows one of its children beside the title, open or closed; called at most once.
A widget with children. A factory given this container appends the new widget as its last child.
Definition backend.hpp:103
virtual void moveChild(Widget &child, std::size_t index)=0
Moves child to position index: it is removed, then inserted before the child now at index.
A component a renderer loaded in a custom node's place (spec 5 §10): a bundle's verified QML or a hos...
Definition backend.hpp:773
virtual void setNumberProp(std::string_view name, double value)=0
Sets a number prop: the one kind of value that crosses as a double.
virtual void setOnEvent(std::function< void(std::string event, std::string payload)> onEvent)=0
Hands over the handler of the component's events.
virtual void setTextProp(std::string_view name, std::string_view value)=0
Sets a text prop: string, and int, exact and json, which cross as text so that no value loses precisi...
virtual void setBoolProp(std::string_view name, bool value)=0
Sets a bool prop.
A date or date-and-time field, in the mode and display zone fixed at creation.
Definition backend.hpp:533
virtual void setOnChange(std::function< void(std::optional< morph::time::Timestamp >)> onChange)=0
Sets what a user edit calls, with the instant entered or nullopt for a cleared field.
virtual void setValue(std::optional< morph::time::Timestamp > const &value)=0
Shows an instant. Never calls the onChange handler.
virtual void setCaption(std::string_view label, bool shown)=0
Sets the field's label, and whether the input draws it as a visible caption above its control....
A modal overlay around its children, with a focus trap while open. A new dialog is closed.
Definition backend.hpp:415
virtual ContainerWidget & footer()=0
The dialog's footer: a container it lays out after its content, which shows nothing while it is empty...
virtual void setTitle(std::string_view title)=0
Replaces the title.
virtual void setOpen(bool open)=0
Shows or hides the overlay.
virtual void setOnDismiss(Action onDismiss)=0
Sets what a user dismissal (Esc on the TUI) of the open dialog calls.
A panel over the content that slides in from the side fixed at creation; it follows a dialog's rules....
Definition backend.hpp:699
virtual ContainerWidget & footer()=0
The drawer's footer: a container it lays out after its content, which shows nothing while it is empty...
virtual void setOnDismiss(Action onDismiss)=0
Sets what a user dismissal (Esc on the TUI) calls.
virtual void setTitle(std::string_view title)=0
Replaces the title.
virtual void setOpen(bool open)=0
Shows or hides it. Never calls the onDismiss handler.
A region that takes files dropped from the operating system.
Definition backend.hpp:755
virtual void setOnDrop(std::function< void(std::vector< std::string >)> onDrop)=0
Sets what a drop it takes calls. A drop with a file outside the accepted extensions,...
virtual void setAccept(std::vector< std::string > const &extensions)=0
Sets the extensions it takes; called once.
virtual void setMultiple(bool multiple)=0
Sets whether a drop may carry more than one file; called once.
What a region shows when it has nothing to show.
Definition backend.hpp:674
virtual void setIcon(std::string_view icon)=0
Sets the icon; called once.
virtual void setActionLabel(std::string_view label)=0
Replaces the action button's caption.
virtual void setText(std::string_view text)=0
Replaces the explanation.
virtual void setOnAction(Action onAction)=0
Sets what activating the action button calls.
virtual void setTitle(std::string_view title)=0
Replaces the title.
A widget that shows a value: text, or an input. A new field is editable, not required,...
Definition backend.hpp:116
virtual void setRequired(bool required)=0
Shows or clears the mark of a field that must be given.
virtual void setReadOnly(bool readonly)=0
Makes the value read-only or editable again. A read-only field still takes focus and lets its text be...
virtual void setErrors(std::vector< std::string > const &errors)=0
Replaces the messages shown with the field.
virtual void setStale(bool stale)=0
Shows or clears the mark of a value that is being recomputed.
A file path field, in the mode fixed at creation.
Definition backend.hpp:574
virtual void setPath(std::string_view path)=0
Shows a path. Never calls the onPicked handler.
virtual void setOnPicked(std::function< void(std::string)> onPicked)=0
Sets what a user pick calls, with the path.
Children laid out row-major in columns.
Definition backend.hpp:326
virtual void setColumns(int columns)=0
Sets the column count.
virtual void setGap(int gap)=0
Sets the space between cells.
virtual void setSpan(Widget &child, int span)=0
Sets how many columns a child spans; a child spans one until this is called.
virtual void setAlign(Align align)=0
Places each cell's content vertically in its row. A new grid stretches it; a child's own alignSelf wi...
virtual std::unique_ptr< CheckboxWidget > createCheckbox(ContainerWidget *parent)=0
Makes a check box.
virtual std::unique_ptr< ToastWidget > createToast(ContainerWidget *parent)=0
Makes a transient message.
virtual std::unique_ptr< PanelWidget > createPanel(ContainerWidget *parent)=0
Makes a titled frame.
virtual std::unique_ptr< DateTimeInputWidget > createDateTimeInput(ContainerWidget *parent, DateMode mode, int offsetMinutes)=0
Makes a date or date-and-time field.
virtual std::unique_ptr< TextWidget > createText(ContainerWidget *parent)=0
Makes read-only text.
virtual std::unique_ptr< SelectWidget > createSelect(ContainerWidget *parent, SelectStyle style)=0
Makes a choice of one option.
virtual std::unique_ptr< SplitterWidget > createSplitter(ContainerWidget *parent, Axis axis)=0
Makes a splitter.
virtual std::unique_ptr< CollapsibleWidget > createCollapsible(ContainerWidget *parent)=0
Makes a collapsible section.
virtual std::unique_ptr< DrawerWidget > createDrawer(ContainerWidget *parent, Side side)=0
Makes a drawer.
virtual std::unique_ptr< ProgressWidget > createProgress(ContainerWidget *parent)=0
Makes a progress bar.
virtual std::unique_ptr< ScrollWidget > createScroll(ContainerWidget *parent, Axis axis)=0
Makes a scroll area.
virtual std::unique_ptr< TableWidget > createTable(ContainerWidget *parent)=0
Makes a table.
virtual std::unique_ptr< EmptyStateWidget > createEmptyState(ContainerWidget *parent)=0
Makes an empty state.
virtual std::unique_ptr< ButtonWidget > createButton(ContainerWidget *parent)=0
Makes a push button.
virtual std::unique_ptr< CustomWidget > createCustom(ContainerWidget *parent, CustomRequest const &request)
Loads the component a custom node names, if this backend can. The only factory that may return null: ...
Definition backend.hpp:988
virtual std::unique_ptr< TabsWidget > createTabs(ContainerWidget *parent)=0
Makes a tab bar.
virtual std::unique_ptr< StepsWidget > createSteps(ContainerWidget *parent)=0
Makes a steps indicator.
virtual std::unique_ptr< SliderWidget > createSlider(ContainerWidget *parent)=0
Makes a slider.
virtual std::unique_ptr< SlotWidget > createSlot(ContainerWidget *parent)=0
Makes a slot.
virtual std::unique_ptr< BadgeWidget > createBadge(ContainerWidget *parent)=0
Makes a badge.
virtual std::unique_ptr< StackWidget > createStack(ContainerWidget *parent, Axis axis)=0
Makes a stack.
virtual std::unique_ptr< SpacerWidget > createSpacer(ContainerWidget *parent)=0
Makes empty space.
virtual std::unique_ptr< BusyWidget > createBusy(ContainerWidget *parent)=0
Makes a progress indicator.
virtual std::unique_ptr< BannerWidget > createBanner(ContainerWidget *parent)=0
Makes a banner.
virtual std::unique_ptr< FilePickerWidget > createFilePicker(ContainerWidget *parent, FilePickerMode mode)=0
Makes a file path field.
virtual std::unique_ptr< GridWidget > createGrid(ContainerWidget *parent)=0
Makes a grid.
virtual std::unique_ptr< MenuWidget > createMenu(ContainerWidget *parent)=0
Makes a command list.
virtual std::unique_ptr< DropZoneWidget > createDropZone(ContainerWidget *parent)=0
Makes a drop zone.
virtual std::unique_ptr< DialogWidget > createDialog(ContainerWidget *parent)=0
Makes a modal overlay.
virtual std::unique_ptr< KeyValueWidget > createKeyValue(ContainerWidget *parent)=0
Makes a key-value list.
virtual std::unique_ptr< TextInputWidget > createTextInput(ContainerWidget *parent, TextInputMode mode)=0
Makes a text field.
Captions beside their values.
Definition backend.hpp:666
virtual void setItems(std::vector< KeyValueItem > const &items)=0
Replaces the pairs.
A menu of commands, with nested submenus.
Definition backend.hpp:296
virtual void setItems(std::vector< MenuEntry > const &entries)=0
Replaces the entries.
virtual void setOnActivate(std::function< void(std::vector< std::size_t >)> onActivate)=0
Sets what choosing an entry calls, with its path.
A titled frame around its children, optionally collapsible.
Definition backend.hpp:351
virtual void setOnToggle(std::function< void(bool)> onToggle)=0
Sets what a user collapse or expand calls, with the requested state.
virtual void setCollapsed(bool collapsed)=0
Collapses or expands the panel. A collapsed panel hides its content, which takes no input; its own co...
virtual void setPadding(int padding)=0
Sets the space between frame and content.
virtual void setHeader(Widget &header)=0
Shows one of its children beside the title; called at most once. The header stays visible and usable ...
virtual void setCollapsible(bool collapsible)=0
Sets whether the user can collapse the panel.
virtual void setTitle(std::string_view title)=0
Replaces the title.
virtual void setLabel(std::string_view label)=0
Replaces the caption beside the bar.
virtual void setValue(std::optional< double > value)=0
Sets how far along it is.
A scrollable viewport, on the axis fixed at creation, that keeps the focused child visible.
Definition backend.hpp:382
A choice of one keyed option.
Definition backend.hpp:246
virtual void setOnSelect(std::function< void(Key)> onSelect)=0
Sets what a user choice calls, with the option's key.
virtual void setOptions(std::vector< SelectOption > const &options)=0
Replaces the options, and marks the requested key's option if they contain it.
virtual void setSelected(std::optional< Key > const &key)=0
Requests the option with key. It is marked while the options contain it; otherwise none is marked....
virtual void setOnOpen(Action onOpen)
Calls onOpen each time the user opens the dropdown, also when it has no options to show....
Definition backend.hpp:266
virtual void setCaption(std::string_view label, bool shown)=0
Sets the field's label, and whether the input draws it as a visible caption above its control....
An integer on a range.
Definition backend.hpp:551
virtual void setOnCommit(std::function< void(std::int64_t)> onCommit)=0
Sets what a finished move calls, with the value it ended on: a release after a drag,...
virtual void setValue(std::int64_t value)=0
Shows a value. Never calls the onChange handler.
virtual void setOnChange(std::function< void(std::int64_t)> onChange)=0
Sets what a user move calls, with the new value.
virtual void setRange(std::int64_t minimum, std::int64_t maximum, std::int64_t step)=0
Sets the range and the increment.
A container that shows its children and nothing else: the host of a Switch's case and of a Tabs page.
Definition backend.hpp:385
Panes along the axis fixed at creation, with handles between them that the user drags.
Definition backend.hpp:720
virtual void setOnResize(std::function< void(std::vector< int >)> onResize)=0
Sets what dragging a handle calls, with every pane's size once the user lets go.
virtual void setSizes(std::vector< int > const &sizes)=0
Sets each pane's size. Never calls the onResize handler.
Children stacked along one axis, fixed at creation.
Definition backend.hpp:310
virtual void setJustify(Justify justify)=0
Places the spare length along the axis while no shown child stretches. A new stack packs at the start...
virtual void setAlign(Align align)=0
Places the children across the axis. A new stack stretches them; a child's own alignSelf wins.
virtual void setGap(int gap)=0
Sets the space between children.
The steps of a process, each with its state.
Definition backend.hpp:654
virtual void setSteps(std::vector< Step > const &steps)=0
Replaces the steps.
virtual void setCurrent(std::optional< std::size_t > index)=0
Highlights one step.
Keyed rows under column headers, with selection and activation by key.
Definition backend.hpp:462
virtual void setRowTone(Widget &row, std::optional< Tone > tone)=0
Sets a row's tone; called after setRowKey for a row given a tone, and on every change.
virtual void setRealizedWindow(std::size_t first, std::size_t count, std::size_t total)
Tells the backend how many of the table's rows are realized, where, and how many exist in total,...
Definition backend.hpp:506
virtual void setOnVisibleRangeChanged(std::function< void(std::size_t, std::size_t)> onVisibleRangeChanged)
Sets what the backend calls when the user scrolls, asking the mount to realize roughly this range of ...
Definition backend.hpp:516
virtual void setColumns(std::vector< TableColumn > const &columns)=0
Sets the column headers and widths.
virtual void setOnSelectionChange(std::function< void(std::vector< Key >)> onSelectionChange)=0
Sets what a user's selection change calls, with the keys of every row then selected.
virtual void setExistingKeys(std::vector< Key > const &keys)
Tells the backend every key currently in the table's data, realized or not – called whenever that set...
Definition backend.hpp:529
virtual void setOnActivate(std::function< void(Key)> onActivate)=0
Sets what activating a row (Enter or a double click) calls, with its key.
virtual void setSelectionMode(SelectionMode mode)=0
Sets how many rows the user can select.
virtual void setRowKey(Widget &row, Key const &key)=0
Tells the table which key a row stands for; called once per row, right after it is built....
virtual void setShowHeader(bool shown)=0
Sets whether the header row is drawn.
virtual void setSelection(std::vector< Key > const &keys)=0
Requests the rows with these keys, and marks those it has. Never calls the onSelectionChange handler.
A tab bar over page slots.
Definition backend.hpp:391
virtual void setSelected(std::size_t index)=0
Highlights a tab. Never calls the onSelect handler.
virtual void setTabs(std::vector< std::string > const &labels)=0
Replaces the tab captions.
virtual void setBarShown(bool shown)=0
Shows or hides the strip of tab buttons. The selected page shows either way. A new tabs widget shows ...
virtual void setOnSelect(std::function< void(std::size_t)> onSelect)=0
Sets what a user's tab choice calls, with its index.
An editable text field.
Definition backend.hpp:178
virtual void setOnChange(std::function< void(std::string)> onChange)=0
Sets what a user edit calls, with the whole new text.
virtual void setUnit(std::string_view unit)=0
Sets the unit the input shows, muted, at its trailing edge, inside the field; empty shows none....
virtual void setCaption(std::string_view label, bool shown)=0
Sets the field's label, and whether the input draws it as a visible caption above its control....
virtual void setDecimals(int decimals)=0
Sets the fraction digits a number is entered with: what a backend or a kit may use to align or format...
virtual void setPlaceholder(std::string_view placeholder)=0
Sets the text shown while the field is empty.
virtual void setIcon(std::string_view icon)=0
Sets the icon drawn at the field's leading edge; empty shows none. Called once, and only for a single...
virtual void setText(std::string_view text)=0
Replaces the text. Never calls the onChange handler. With the text the field already shows,...
virtual void setOnSubmit(std::function< void(std::string)> onSubmit)=0
Sets what a submit (Enter in single-line mode) calls, with the text.
virtual void setOnCommit(std::function< void(std::string)> onCommit)=0
Sets what a commit calls, with the text: Enter in single-line mode, before the submit,...
Read-only text.
Definition backend.hpp:137
virtual void setText(std::string_view text)=0
Replaces the text.
virtual void setRole(TextRole role)=0
Sets the style.
A passive, transient message outside the normal flow: non-modal, dims nothing, and never takes keyboa...
Definition backend.hpp:615
virtual void show(std::string_view text, Tone tone)=0
Shows the message, replacing any shown or dismissing, and (re)starts the dismissal interval regardles...
A retained widget. A new widget is visible, enabled, content-sized, not draggable and not a drop targ...
Definition backend.hpp:34
virtual void setLayout(LayoutHints const &hints)=0
Sets the size request.
virtual void setTestId(std::string_view testId)=0
Sets the stable identifier an automated test finds the widget by.
virtual void setEnabled(bool enabled)=0
Enables or disables input on the widget and everything inside it.
virtual void setSurface(std::string_view surface)=0
Styles the widget and everything inside it with a named token set of the theme.
virtual void focus()=0
Moves keyboard focus to the widget.
virtual void setKeys(std::vector< std::string > const &chords, std::function< void(std::string)> onChord)=0
Declares the keyboard chords the widget handles while focus is inside it.
virtual void setAccessibleName(std::string_view name)=0
Sets the name assistive technology reads for the widget.
virtual void setTooltip(std::string_view text)=0
Sets the text shown while the pointer rests on the widget.
virtual void setDragKey(std::optional< Key > const &key)=0
Makes the widget draggable, carrying key, or not draggable.
virtual void setOnHover(std::function< void()> onHover)
Calls onHover each time the pointer comes to rest over the widget. A backend without a pointer,...
Definition backend.hpp:99
virtual void setDropHandler(std::function< bool(Key const &)> accepts, std::function< void(Key)> onDrop)=0
Makes the widget a drop target.
virtual void setVisible(bool visible)=0
Shows or hides the widget and everything inside it.
virtual void setAccessibleRole(std::string_view role)=0
Sets the role assistive technology announces for the widget.
UTC timestamps for morph actions.
What IViewBackend::createCustom asks for.
Definition backend.hpp:799
std::string name
The component's name, as the document's components declares it.
Definition backend.hpp:801
int minVersion
The lowest version of a host component that will do; a bundle component ignores it.
Definition backend.hpp:805
std::vector< std::string > props
The props the document declares for it; a component that does not declare each one is refused.
Definition backend.hpp:803
A widget's size request in both dimensions, and the bounds its extent is clamped into.
Definition view.hpp:308
One entry of a menu as a MenuWidget shows it.
Definition backend.hpp:276
std::optional< bool > checked
Engaged: a checkable entry with this mark; nullopt: not checkable.
Definition backend.hpp:284
bool operator==(MenuEntry const &) const =default
Memberwise equality, submenus included.
std::string keys
The chord shown beside the label; empty shows none.
Definition backend.hpp:282
std::vector< MenuEntry > items
The submenu; empty for an entry that is chosen.
Definition backend.hpp:288
std::string icon
The icon's name in the theme's icon map; empty shows none.
Definition backend.hpp:280
std::string label
The caption.
Definition backend.hpp:278
bool enabled
Whether the entry can be chosen, or its submenu opened.
Definition backend.hpp:286
The toolkit-agnostic view tree: props, node kinds and their builders.
Tone
What a message or a mark conveys, mapped to the theme's colours.
Definition view.hpp:240
Node collapsible(Collapsible spec)
A titled section the user opens and closes.
Definition view.hpp:1334
TextInputMode
How a TextInput edits.
Definition view.hpp:209
TextRole
How a Text is styled; each backend maps a role to its theme.
Definition view.hpp:199
DateMode
What a DateTimeInput edits.
Definition view.hpp:228
std::function< void()> Action
A widget event handler taking no arguments.
Definition view.hpp:33
SelectionMode
How many rows of a Table the user can select.
Definition view.hpp:263
Side
The edge a Drawer slides in from, in reading direction.
Definition view.hpp:249
FilePickerMode
Whether a FilePicker chooses an existing file or a file to write.
Definition view.hpp:234
Node text(Text spec)
Static or bound text.
Definition view.hpp:1194
SelectStyle
How a Select presents its options.
Definition view.hpp:216
Node row(Row spec)
Children laid out left to right.
Definition view.hpp:1229
std::variant< std::int64_t, std::string > Key
The identity of a Switch case, a Select option, a ForEach or Table row and a drag payload.
Definition view.hpp:38
Node steps(Steps spec)
The steps of a process.
Definition view.hpp:1304
Axis
The direction a stack arranges, or a scroll area scrolls, its content.
Definition view.hpp:222