MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ ask() [2/2]

MAYAFLUX_API void MayaFlux::Portal::Forma::ask ( std::string title,
std::string initial,
AskValidator validator,
AskCallback callback )

Open a one line text prompt and report what the user typed.

Requires Portal::Forma to be initialized and the engine running. The window holds one text field with the focus, started on initial with the cursor at its end. Enter accepts the text, Escape cancels, and closing the window cancels. The callback fires exactly once, on the event thread, so it must not block, and the window closes as it fires.

When a validator is given it runs on every edit. Text it refuses is drawn in a warning colour and Enter does nothing until the text is accepted, so the callback only ever receives text the validator took.

Parameters
titleWindow title, with a note that Enter accepts and Escape cancels.
initialStarting text.
validatorAccepts or refuses the text. Empty accepts everything.
callbackInvoked once with the text or nullopt.

Definition at line 94 of file Prompt.cpp.

99{
100 uint32_t row_px = k_min_row_px;
101 if (auto atlas = Text::TypeFaceFoundry::instance().get_default_glyph_atlas()) {
102 row_px = std::max(row_px, static_cast<uint32_t>(atlas->pixel_size()) + k_row_padding_px);
103 }
104
105 auto& atelier = internal::atelier();
106
107 auto window = atelier.create_window(Core::WindowCreateInfo {
108 .title = std::move(title) + " (Enter accepts, Escape cancels)",
109 .width = k_width_px,
110 .height = row_px,
111 .resizable = false,
112 });
113
114 auto cancel = std::make_shared<std::function<void()>>();
115
116 Surface surface = atelier.create_surface(SurfaceConfig {
117 .window = window,
118 .name = window->get_create_info().title,
119 .on_close = [cancel] {
120 if (*cancel) {
121 (*cancel)();
122 }
123 },
124 });
125
126 *cancel = internal::ask_in(
127 surface,
129 row_px, std::move(initial), std::move(validator), std::move(callback));
130}
Surface create_surface(SurfaceConfig config)
Build a Surface from a SurfaceConfig, creating Layer and Context when config.layer/config....
Definition Atelier.cpp:210
FormaTarget batch_slice(Surface &surface, Graphics::PrimitiveTopology topology)
A new slice of surface_batch(), of topology.
Definition Atelier.cpp:189
std::shared_ptr< Core::Window > create_window(const Core::WindowCreateInfo &info)
Create a window through the stored WindowManager and show it.
Definition Atelier.cpp:108
Atelier & atelier()
Accessor for the process-wide Atelier.
Definition Atelier.hpp:352
std::function< void()> ask_in(Surface &surface, FormaTarget target, uint32_t row_px, std::string initial, AskValidator validator, AskCallback callback)
The prompt itself, placed on a surface that already exists.
Definition Prompt.cpp:55
Configuration for creating a single window instance.

References MayaFlux::Portal::Forma::internal::ask_in(), MayaFlux::Portal::Forma::internal::atelier(), MayaFlux::Portal::Forma::internal::Atelier::batch_slice(), MayaFlux::Portal::Forma::internal::Atelier::create_surface(), MayaFlux::Portal::Forma::internal::Atelier::create_window(), MayaFlux::Portal::Text::TypeFaceFoundry::instance(), and MayaFlux::Portal::Graphics::TRIANGLE_LIST.

Referenced by ask(), and MayaFlux::detail::ask_one().

Here is the call graph for this function:
Here is the caller graph for this function: