|
MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
|
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 | CloseFn = std::function< void()> |
| 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 | ResizeFn = std::function< void(uint32_t width, uint32_t height)> |
| using | ScrollFn = std::function< void(uint32_t id, glm::vec2 ndc, double dx, double dy)> |
| using | TextFn = std::function< void(uint32_t id, uint32_t codepoint)> |
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::WindowEventSource & | event_source () const |
| std::optional< uint32_t > | focused () const |
| Get currently focused element, if any. | |
| std::optional< uint32_t > | hovered () const |
| Context & | key_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. | |
| const std::shared_ptr< Layer > & | layer () const noexcept |
| The Layer this Context hit-tests against. | |
| void | on_close (uint32_t id, CloseFn fn) |
| Register a callback invoked when the Context window closes. | |
| 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_resize (uint32_t id, ResizeFn fn) |
| Called on every window resize. | |
| void | on_scroll (uint32_t id, ScrollFn fn) |
| Called on scroll while the cursor is over an element. | |
| void | on_text (uint32_t id, TextFn fn) |
| Called with each resolved Unicode codepoint while the element has keyboard focus. | |
| Context & | operator= (const Context &)=delete |
| Context & | operator= (Context &&)=delete |
| Context & | press_and_hold (uint32_t id, IO::Keys key, KeyFn fn) |
| Register a key handler that fires on the initial press and on every repeat, with a deterministic first event. | |
| void | sync_size () |
| Run the resize callbacks if the window's size differs from the size they last saw. | |
| Kinesis::AABB2D | to_ndc_rect (double x, double y, double w, double h) const noexcept |
Rect of pixel size (w, h) at pixel position (x, y), top-left origin, converted to NDC from the window's current dimensions. | |
| void | unbind (uint32_t id) |
| Remove all callbacks registered for an element id. | |
| Context & | wire_drag (uint32_t id, std::function< void(glm::vec2)> sink, IO::MouseButtons btn=IO::MouseButtons::Left) |
| Register a drag handler receiving only the cursor position. | |
| ~Context () | |
| Cancel all registered event coroutines. | |
Private Member Functions | |
| void | cancel_handlers (bool cancel_close=true) |
| void | detach_window (bool cancel_close=true) |
| void | handle_close () |
| void | handle_drag (double px, double py, IO::MouseButtons btn) |
| void | handle_drags (double px, double py) |
| 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_resize (uint32_t width, uint32_t height) |
| void | handle_scroll (double dx, double dy) |
| void | handle_text (uint32_t codepoint) |
| void | register_handlers () |
| glm::vec2 | to_ndc (double px, double py) const noexcept |
Private Attributes | |
| std::unordered_map< uint32_t, ElementCallbacks > | m_callbacks |
| std::optional< uint32_t > | m_dragging [3] |
| Vruta::EventManager & | m_event_manager |
| std::optional< uint32_t > | m_focused |
| std::optional< uint32_t > | m_hovered |
| uint32_t | m_known_height {} |
| uint32_t | m_known_width {} |
| std::shared_ptr< Layer > | m_layer |
| std::string | m_name |
| std::unordered_map< int, KeyHandlerState > | m_registered_keys |
| std::shared_ptr< Core::Window > | m_window |
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 graphics thread, from window polling at the end of each frame, after that frame's Bridge tasks and buffer processing have run. They may write a MappedState directly, since it is the same thread, and the value is read by the next frame. They must not touch GPU resources directly.
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 41 of file Context.hpp.