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

◆ ask_in()

MAYAFLUX_API std::function< void()> MayaFlux::Portal::Forma::internal::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.

ask() builds a window and a surface and calls this. It places the field in the whole surface, gives it focus, and requests the surface's window to close when the prompt finishes. Separate so the behaviour can be driven against a scripted window.

Parameters
surfaceSurface to place the field on.
targetWhere the field's text is drawn.
row_pxHeight of the field in pixels, for the text layout.
initialStarting text.
validatorAccepts or refuses the text. Empty accepts everything.
callbackInvoked once with the text or nullopt.
Returns
Callable that finishes the prompt as cancelled, for a window that closes without the field's own Escape.

Definition at line 55 of file Prompt.cpp.

62 {
63 auto state = std::make_shared<PromptState>();
64 state->callback = std::move(callback);
65 state->validator = std::move(validator);
66 state->window = surface.window();
67
68 const glm::uvec2 dims { surface.window()->get_create_info().width, row_px };
69 auto params = std::make_shared<Text::PressParams>(row_press_params(dims, row_idle_color()));
70
71 const auto tint = [params, state](std::string_view text) {
72 params->color = state->accepts(text) ? k_accepted_color : k_refused_color;
73 };
74 tint(initial);
75
76 TextField field;
77 field.single_line()
78 .on_change([tint](const std::string& text) { tint(text); })
79 .on_commit([state](const std::string& text) {
80 if (state->accepts(text)) {
81 state->finish(text, true);
82 }
83 })
84 .on_cancel([state] { state->finish(std::nullopt, true); });
85
86 field.place(std::move(target), surface, surface.full(), params, std::move(initial));
87 surface.ctx().set_focus(field.element_id);
88
89 return [state] { state->finish(std::nullopt, false); };
90 }
bool set_focus(uint32_t id)
Give keyboard focus to an element from code.
Definition Context.cpp:277
Kinesis::AABB2D full() const noexcept
The entire NDC surface.
Definition Surface.hpp:314
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:178
Context & ctx() noexcept
Access the event router.
Definition Surface.hpp:170
Text::PressParams row_press_params(glm::uvec2 dims, glm::vec4 background)
White text over background, laid out at dims pixels.
Definition TextRow.cpp:18

References MayaFlux::Portal::Forma::Surface::ctx(), MayaFlux::Portal::Forma::TextField::element_id, MayaFlux::Portal::Forma::Surface::full(), MayaFlux::Portal::Forma::TextField::on_change(), MayaFlux::Portal::Forma::TextField::place(), row_idle_color(), row_press_params(), MayaFlux::Portal::Forma::Context::set_focus(), MayaFlux::Portal::Forma::TextField::single_line(), and MayaFlux::Portal::Forma::Surface::window().

Referenced by MayaFlux::Portal::Forma::ask().

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