MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Portal::Forma::Context Class Reference

Event wiring between a Layer and a window surface. More...

#include <Context.hpp>

+ Collaboration diagram for MayaFlux::Portal::Forma::Context:

Classes

struct  ElementCallbacks
 
struct  KeyHandlerState
 

Public Types

using EnterFn = std::function< void(uint32_t id)>
 
using KeyFn = std::function< void(uint32_t id)>
 
using LeaveFn = std::function< void(uint32_t id)>
 
using MoveFn = std::function< void(uint32_t id, glm::vec2 ndc)>
 
using PressFn = std::function< void(uint32_t id, glm::vec2 ndc)>
 
using ScrollFn = std::function< void(uint32_t id, glm::vec2 ndc, double dx, double dy)>
 

Public Member Functions

void clear_focus ()
 Clear keyboard focus (no element focused).
 
 Context (const Context &)=delete
 
 Context (Context &&)=delete
 
 Context (std::shared_ptr< Layer > layer, std::shared_ptr< Core::Window > window, Vruta::EventManager &event_manager, std::string name)
 Construct and immediately register event coroutines.
 
const Vruta::WindowEventSourceevent_source () const
 
std::optional< uint32_t > focused () const
 Get currently focused element, if any.
 
std::optional< uint32_t > hovered () const
 
Contextkey_step (uint32_t id, std::shared_ptr< MappedState< float > > state, IO::Keys decrease, IO::Keys increase, float delta, float clamp_min=0.0F, float clamp_max=1.0F)
 Attach key-delta handlers to a Mapped<float> element.
 
void on_drag (uint32_t id, IO::MouseButtons btn, MoveFn fn)
 Called on each mouse-move event while btn is held, tracking the element where the drag began even when the cursor leaves its bounds.
 
void on_enter (uint32_t id, EnterFn fn)
 Called once when the cursor enters an element's region.
 
void on_focus_gained (uint32_t id, EnterFn fn)
 Called once when an element gains keyboard focus (via click).
 
void on_focus_lost (uint32_t id, LeaveFn fn)
 Called once when an element loses keyboard focus.
 
void on_held (uint32_t id, IO::Keys key, KeyFn fn)
 Called repeatedly while a key is held and the element has focus.
 
void on_leave (uint32_t id, LeaveFn fn)
 Called once when the cursor leaves an element's region.
 
void on_move (uint32_t id, MoveFn fn)
 Called each move event while the cursor is over an element.
 
void on_press (uint32_t id, IO::Keys key, KeyFn fn)
 Called when a key is pressed while the element has focus.
 
void on_press (uint32_t id, IO::MouseButtons btn, PressFn fn)
 Called when a mouse button is pressed over an element.
 
void on_release (uint32_t id, IO::Keys key, KeyFn fn)
 Called when a key is released while the element has focus.
 
void on_release (uint32_t id, IO::MouseButtons btn, PressFn fn)
 Called when a mouse button is released over an element.
 
void on_scroll (uint32_t id, ScrollFn fn)
 Called on scroll while the cursor is over an element.
 
Contextoperator= (const Context &)=delete
 
Contextoperator= (Context &&)=delete
 
void unbind (uint32_t id)
 Remove all callbacks registered for an element id.
 
 ~Context ()
 Cancel all registered event coroutines.
 

Private Member Functions

void cancel_handlers ()
 
void handle_drag (double px, double py, IO::MouseButtons btn)
 
void handle_key_held (IO::Keys key)
 
void handle_key_press (IO::Keys key)
 
void handle_key_release (IO::Keys key)
 
void handle_move (double px, double py)
 
void handle_press (double px, double py, IO::MouseButtons btn)
 
void handle_release (double px, double py, IO::MouseButtons btn)
 
void handle_scroll (double dx, double dy)
 
void register_handlers ()
 
glm::vec2 to_ndc (double px, double py) const noexcept
 

Private Attributes

std::unordered_map< uint32_t, ElementCallbacksm_callbacks
 
std::optional< uint32_t > m_dragging [3]
 
Vruta::EventManagerm_event_manager
 
std::optional< uint32_t > m_focused
 
std::optional< uint32_t > m_hovered
 
std::shared_ptr< Layerm_layer
 
std::string m_name
 
std::unordered_map< int, KeyHandlerStatem_registered_keys
 
std::shared_ptr< Core::Windowm_window
 

Detailed Description

Event wiring between a Layer and a window surface.

Subscribes to mouse events on a window by constructing Kriya input coroutines and registering them with a Vruta::EventManager, following the same pattern as Nexus::Fabric. The EventManager and Window are injected; Context holds no engine-level singletons.

Callbacks fire on the scheduler tick. They must not touch GPU resources directly. State intended for the graphics tick should be written through shared_ptr captures and read on the next graphics cycle.

All registered events are cancelled on destruction via EventManager::cancel_event, keyed by names scoped to this Context.

Window dimensions are read from window->get_state() at event time, so resize is handled automatically.

Definition at line 40 of file Context.hpp.


The documentation for this class was generated from the following files: