14#include <lagrange/ui/components/EventEmitter.h>
23inline EventEmitter& get_event_emitter(Registry& r)
25 return r.ctx().emplace<EventEmitter>(EventEmitter());
33template <
typename Event>
34void on(Registry& r, std::function<
void(Event&)> listener)
36 get_event_emitter(r).on<Event>(
45template <
typename Event,
typename...
Args>
48 get_event_emitter(r).publish<Event>(Event{std::forward<Args>(args)...});
52template <
typename Event>
55 ui::publish<Event>(r, e);
60template <
typename Component,
typename ConstructEvent,
typename DestroyEvent>
63 if (get_event_emitter(r).contains<ConstructEvent>()) {
64 r.on_construct<Component>().
template connect<&forward_entity_event<ConstructEvent>>();
66 r.on_construct<Component>().
template disconnect<&forward_entity_event<ConstructEvent>>();
69 if (get_event_emitter(r).contains<DestroyEvent>()) {
70 r.on_destroy<Component>().
template connect<&forward_entity_event<DestroyEvent>>();
72 r.on_destroy<Component>().
template disconnect<&forward_entity_event<DestroyEvent>>();
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
void on(Registry &r, std::function< void(Event &)> listener)
Register a listener for Event.
Definition: events.h:34
void publish(Registry &r, Args &&... args)
Trigger an event of type Event.
Definition: events.h:46
void forward_entity_event(Registry &r, Entity e)
Utility function for forwarding events that contain only an entity identifier.
Definition: events.h:53
void toggle_component_event(Registry &r)
Enable/Disable on_construct and on_destroy events depending on whether ConstructEvent and DestroyEven...
Definition: events.h:61
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: project.cpp:27
Definition: EventEmitter.h:21