MayaFlux 0.4.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 68 of file Context.cpp.

69{
70 const int key_code = static_cast<int>(key);
71 m_callbacks[id].key_press[key_code] = std::move(fn);
72
73 if (!m_registered_keys[key_code].has_press) {
74 const std::string key_name = std::to_string(key_code);
76 std::make_shared<Vruta::Event>(
78 [this, key]() { handle_key_press(key); })),
79 m_name + "_key_press_" + key_name);
80 m_registered_keys[key_code].has_press = true;
81 }
82}
std::unordered_map< int, KeyHandlerState > m_registered_keys
Definition Context.hpp:244
void handle_key_press(IO::Keys key)
Definition Context.cpp:377
Vruta::EventManager & m_event_manager
Definition Context.hpp:248
std::shared_ptr< Core::Window > m_window
Definition Context.hpp:247
std::unordered_map< uint32_t, ElementCallbacks > m_callbacks
Definition Context.hpp:252
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: