|
| 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.
Subscribing to a built-in event
myRect.onClick([]{ std::cout << "clicked\n"; });
myRect.onUpdate([]{
Publishing a custom event
enum class MyEvent { GameStarted, ScoreChanged };
myRect.publish(MyEvent::GameStarted);
myRect.publish(MyEvent::ScoreChanged,
return c && zone.contains(c->getPosition());
});
Virtual base class for all Malena framework objects.
Base class for all event-receiving traits.
- See also
- Clickable, Hoverable, Updatable, Unsubscribable, EventManager
Definition at line 63 of file Subscribable.h.
| Core* ml::EventReceiver::_selfCore = nullptr |
|
inherited |
The owning Core, stamped by Core's constructor.
Traits subscribe from inside their OWN constructors (ml::TextInput calls onFocus(), ComponentCore subscribes to CLICK/HOVER/DRAG), at which point the derived type does not exist yet. Recovering the Core by dynamic_cast there is undefined: Clang returns something usable, MSVC throws "Access violation - no RTTI data!" and aborts the process. Core sets this on every one of its EventReceiver subobjects before any derived constructor runs, so no RTTI is ever needed.
Definition at line 93 of file EventReceiver.h.