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

◆ on_press() [1/2]

void MayaFlux::Portal::Forma::Context::on_press ( uint32_t  id,
IO::Keys  key,
KeyFn  fn 
)

Called when a key is pressed while the element has focus.

Focus is transferred on mouse press. The callback fires only once per key press, even if the key is held.

Parameters
idElement id to bind to.
keyThe key to listen for.
fnCallback receiving element id.

Definition at line 73 of file Context.cpp.

74{
75 const int key_code = static_cast<int>(key);
76 m_callbacks[id].key_press[key_code] = std::move(fn);
77
78 if (!m_registered_keys[key_code].has_press) {
79 const std::string key_name = std::to_string(key_code);
81 std::make_shared<Vruta::Event>(
83 [this, key]() { handle_key_press(key); })),
84 m_name + "_key_press_" + key_name);
85 m_registered_keys[key_code].has_press = true;
86 }
87}
std::unordered_map< int, KeyHandlerState > m_registered_keys
Definition Context.hpp:353
void handle_key_press(IO::Keys key)
Definition Context.cpp:478
Vruta::EventManager & m_event_manager
Definition Context.hpp:357
std::shared_ptr< Core::Window > m_window
Definition Context.hpp:356
std::unordered_map< uint32_t, ElementCallbacks > m_callbacks
Definition Context.hpp:361
void add_event(const std::shared_ptr< Event > &event, const std::string &name="")
Add a event to the manager.
Vruta::Event key_pressed(std::shared_ptr< Core::Window > window, IO::Keys key, std::function< void()> callback)
Creates an Event coroutine that triggers on specific key press.

References MayaFlux::Vruta::EventManager::add_event(), handle_key_press(), MayaFlux::Kriya::key_pressed(), m_callbacks, m_event_manager, m_name, m_registered_keys, and m_window.

+ Here is the call graph for this function: