13class WindowEventSource;
43 using PressFn = std::function<void(uint32_t
id, glm::vec2 ndc)>;
44 using MoveFn = std::function<void(uint32_t
id, glm::vec2 ndc)>;
45 using EnterFn = std::function<void(uint32_t
id)>;
46 using LeaveFn = std::function<void(uint32_t
id)>;
47 using ScrollFn = std::function<void(uint32_t
id, glm::vec2 ndc,
double dx,
double dy)>;
48 using KeyFn = std::function<void(uint32_t
id)>;
49 using TextFn = std::function<void(uint32_t
id, uint32_t codepoint)>;
61 Context(std::shared_ptr<Layer> layer,
62 std::shared_ptr<Core::Window>
window,
96 void on_move(uint32_t
id,
MoveFn fn);
128 void on_leave(uint32_t
id,
LeaveFn fn);
142 void unbind(uint32_t
id);
189 void on_text(uint32_t
id,
TextFn fn);
194 void on_focus_gained(uint32_t
id,
EnterFn fn);
199 void on_focus_lost(uint32_t
id,
LeaveFn fn);
221 void on_resize(uint32_t
id,
ResizeFn fn);
239 [[nodiscard]] std::optional<uint32_t>
focused()
const {
return m_focused; }
246 void on_close(uint32_t
id, CloseFn fn);
269 float clamp_min = 0.0F,
270 float clamp_max = 1.0F);
303 std::function<
void(glm::vec2)> sink,
310 [[nodiscard]] std::optional<uint32_t>
hovered()
const {
return m_hovered; }
315 [[nodiscard]]
const std::shared_ptr<Layer>&
layer() const noexcept {
return m_layer; }
325 [[nodiscard]]
Kinesis::AABB2D to_ndc_rect(
double x,
double y,
double w,
double h)
const noexcept;
329 std::unordered_map<int, PressFn>
press;
331 std::unordered_map<int, MoveFn>
drag;
349 bool has_press =
false;
350 bool has_release =
false;
351 bool has_held =
false;
363 void register_handlers();
364 void cancel_handlers(
bool cancel_close =
true);
366 [[nodiscard]] glm::vec2 to_ndc(
double px,
double py)
const noexcept;
368 void handle_move(
double px,
double py);
371 void handle_scroll(
double dx,
double dy);
373 void handle_drags(
double px,
double py);
374 void handle_key_press(
IO::Keys key);
375 void handle_key_release(
IO::Keys key);
377 void handle_text(uint32_t codepoint);
378 void handle_resize(uint32_t
width, uint32_t
height);
380 void detach_window(
bool cancel_close =
true);
382 std::optional<uint32_t> m_dragging[3];
384 uint32_t m_known_width {};
385 uint32_t m_known_height {};
Expanse::CrossingFn on_enter
std::weak_ptr< Core::Window > window
std::function< void(uint32_t id)> KeyFn
std::unordered_map< int, KeyHandlerState > m_registered_keys
Context(const Context &)=delete
Context & operator=(Context &&)=delete
std::function< void(uint32_t id, uint32_t codepoint)> TextFn
std::shared_ptr< Layer > m_layer
std::optional< uint32_t > hovered() const
std::function< void(uint32_t id, glm::vec2 ndc)> MoveFn
std::function< void(uint32_t width, uint32_t height)> ResizeFn
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
std::function< void()> CloseFn
const std::shared_ptr< Layer > & layer() const noexcept
The Layer this Context hit-tests against.
Context & operator=(const Context &)=delete
std::optional< uint32_t > m_focused
Event wiring between a Layer and a window surface.
Awaitable stream of 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.
Axis-aligned bounding rectangle in a 2D coordinate space.
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