Trait that allows a component to subscribe to and publish framework events. More...
#include <Subscribable.h>
Public Member Functions | |
| virtual void | process (const std::string &key, const std::optional< sf::Event > &event) |
Invoke all callbacks registered for key. | |
| template<typename ENUM_TYPE> | |
| void | process (ENUM_TYPE eventName, const std::optional< sf::Event > &event) |
Invoke all callbacks registered for eventName. | |
| template<typename ENUM_TYPE> | |
| void | publish (ENUM_TYPE event, FilterCallback filter=[](EventReceiver &){ return true;}, SystemCallback resolve=nullptr, SystemCallback reject=nullptr) |
| Fire an enum-keyed event to all matching subscribers. | |
| template<typename ENUM_TYPE> | |
| void | subscribe (ENUM_TYPE event, Callback callback) |
| Subscribe to an enum-keyed event with a no-argument callback. | |
| template<typename ENUM_TYPE> | |
| void | subscribe (ENUM_TYPE event, EventCallback callback) |
| Subscribe to an enum-keyed event with a full SFML event callback. | |
Trait that allows a component to subscribe to and publish framework events.
Subscribable is one of the three core traits automatically included in every ml::Core object (Subscribable, Flaggable, Positionable). It is the low-level event subscription layer — most user code will interact with the higher-level trait convenience methods (onClick, onHover, onUpdate, etc.) rather than calling subscribe and publish directly.
Both ml::Event built-in values and user-defined manifest event enums work identically — any enum value is accepted.
Definition at line 58 of file Subscribable.h.
|
virtualinherited |
Invoke all callbacks registered for key.
Called by framework dispatchers. key is the string produced by EnumKey::get(eventEnum).
| key | String key identifying the event. |
| event | SFML event forwarded to each callback. |
|
inherited |
Invoke all callbacks registered for eventName.
Template overload that accepts any enum value directly, converting to a string key via EnumKey::get() internally.
| ENUM_TYPE | Any enum type. |
| eventName | The enum value identifying the event. |
| event | SFML event forwarded to each callback. |
| void ml::Subscribable::publish | ( | ENUM_TYPE | event, |
| FilterCallback | filter = [](EventReceiver &){ return true;}, | ||
| SystemCallback | resolve = nullptr, | ||
| SystemCallback | reject = nullptr ) |
Fire an enum-keyed event to all matching subscribers.
Iterates all subscribers registered for event and invokes their callbacks for each subscriber that passes the optional filter. Optional resolve and reject system callbacks are called after each component passes or fails the filter respectively.
| ENUM_TYPE | Any enum type. |
| event | The enum value identifying the event to fire. |
| filter | Optional predicate; only subscribers for which this returns true receive the event. Defaults to accepting all subscribers. |
| resolve | Optional callback invoked for each subscriber that passes the filter. |
| reject | Optional callback invoked for each subscriber that fails the filter. |
| void ml::Subscribable::subscribe | ( | ENUM_TYPE | event, |
| Callback | callback ) |
Subscribe to an enum-keyed event with a no-argument callback.
Convenience overload for callbacks that do not need access to the raw SFML event.
| ENUM_TYPE | Any enum type. |
| event | The enum value identifying the event to subscribe to. |
| callback | Function invoked with no arguments when the event fires. |
| void ml::Subscribable::subscribe | ( | ENUM_TYPE | event, |
| EventCallback | callback ) |
Subscribe to an enum-keyed event with a full SFML event callback.
The callback is invoked each time the event fires and the framework's filter (defined by the associated EventDispatcher) passes this component. The std::optional<sf::Event> parameter carries the raw SFML event when one is available, or std::nullopt for frame events.
| ENUM_TYPE | Any enum type — ml::Event for built-in events, or a manifest event enum for custom events. |
| event | The enum value identifying the event to subscribe to. |
| callback | Function invoked with the SFML event when the event fires. |