13class WindowEventSource;
42 using PressFn = std::function<void(uint32_t
id, glm::vec2 ndc)>;
43 using MoveFn = std::function<void(uint32_t
id, glm::vec2 ndc)>;
44 using EnterFn = std::function<void(uint32_t
id)>;
45 using LeaveFn = std::function<void(uint32_t
id)>;
46 using ScrollFn = std::function<void(uint32_t
id, glm::vec2 ndc,
double dx,
double dy)>;
47 using KeyFn = std::function<void(uint32_t
id)>;
57 Context(std::shared_ptr<Layer> layer,
58 std::shared_ptr<Core::Window> window,
92 void on_move(uint32_t
id,
MoveFn fn);
118 void on_enter(uint32_t
id,
EnterFn fn);
123 void on_leave(uint32_t
id,
LeaveFn fn);
133 void unbind(uint32_t
id);
172 void on_focus_gained(uint32_t
id,
EnterFn fn);
177 void on_focus_lost(uint32_t
id,
LeaveFn fn);
187 [[nodiscard]] std::optional<uint32_t>
focused()
const {
return m_focused; }
210 float clamp_min = 0.0F,
211 float clamp_max = 1.0F);
217 [[nodiscard]] std::optional<uint32_t>
hovered()
const {
return m_hovered; }
223 std::unordered_map<int, PressFn>
press;
225 std::unordered_map<int, MoveFn>
drag;
240 bool has_press =
false;
241 bool has_release =
false;
242 bool has_held =
false;
254 void register_handlers();
255 void cancel_handlers();
257 [[nodiscard]] glm::vec2 to_ndc(
double px,
double py)
const noexcept;
259 void handle_move(
double px,
double py);
262 void handle_scroll(
double dx,
double dy);
264 void handle_key_press(
IO::Keys key);
265 void handle_key_release(
IO::Keys key);
268 std::optional<uint32_t> m_dragging[3];
std::function< void(uint32_t id)> KeyFn
std::unordered_map< int, KeyHandlerState > m_registered_keys
Context(const Context &)=delete
Context & operator=(Context &&)=delete
std::shared_ptr< Layer > m_layer
std::optional< uint32_t > hovered() const
std::function< void(uint32_t id, glm::vec2 ndc)> MoveFn
Context(Context &&)=delete
std::function< void(uint32_t id, glm::vec2 ndc, double dx, double dy)> ScrollFn
Vruta::EventManager & m_event_manager
std::shared_ptr< Core::Window > m_window
std::function< void(uint32_t id, glm::vec2 ndc)> PressFn
std::function< void(uint32_t id)> LeaveFn
std::unordered_map< uint32_t, ElementCallbacks > m_callbacks
std::optional< uint32_t > focused() const
Get currently focused element, if any.
std::optional< uint32_t > m_hovered
std::function< void(uint32_t id)> EnterFn
Context & operator=(const Context &)=delete
std::optional< uint32_t > m_focused
Event wiring between a Layer and a window surface.
Awaitable stream of GLFW window input events.
MouseButtons
Enumeration for mouse buttons.
void on_scroll(const std::shared_ptr< Core::Window > &window, std::function< void(double, double)> callback, std::string name)
Schedule a mouse scroll handler.
std::unordered_map< int, KeyFn > key_press
std::unordered_map< int, KeyFn > key_release
std::unordered_map< int, PressFn > press
std::unordered_map< int, KeyFn > key_held
std::unordered_map< int, MoveFn > drag
std::unordered_map< int, PressFn > release