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

◆ set_focus()

bool MayaFlux::Portal::Forma::Context::set_focus ( uint32_t id)

Give keyboard focus to an element from code.

Runs the same focus-lost and focus-gained callbacks, and the WINDOW_FOCUS_LOST and WINDOW_FOCUS_GAINED subscriptions, as a press that moves focus. Key and text callbacks then reach the element, so a menu driven by keys or a controller works without the pointer.

Refused for an id the Layer does not hold, or whose element is hidden or not interactive. Focusing the element that already has focus does nothing and returns true. Call it on the graphics thread, where the other callbacks run.

A focus callback or subscriber may itself move focus, here or on a press, and the later move wins. An element whose focus-gained callback has run is always told when it loses focus, by its callback and its subscriptions. Its WINDOW_FOCUS_GAINED subscriptions are skipped if focus moved on before they were reached.

Parameters
idElement to focus.
Returns
True if id has focus when the call returns: false if it was refused, or if a focus callback moved focus elsewhere.

Definition at line 277 of file Context.cpp.

278{
279 const Element* element = m_layer->get(id);
280 if (!element || !element->visible || !element->interactive)
281 return false;
282
283 move_focus(id, glm::vec2(0.0F));
284 return m_focused == id;
285}
std::shared_ptr< Layer > m_layer
Definition Context.hpp:465
void move_focus(std::optional< uint32_t > target, glm::vec2 ndc)
Definition Context.cpp:287
std::optional< uint32_t > m_focused
Definition Context.hpp:499

References MayaFlux::Portal::Forma::Element::interactive, m_focused, m_layer, move_focus(), and MayaFlux::Portal::Forma::Element::visible.

Referenced by MayaFlux::Portal::Forma::internal::ask_in(), and operator=().

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