Loading...
Searching...
No Matches
ml::Unsubscribable Class Reference

Trait that gives components the ability to unsubscribe from events. More...

#include <Unsubscribable.h>

Inheritance diagram for ml::Unsubscribable:

Public Member Functions

virtual ~Unsubscribable ()=default
template<typename EnumType>
void unsubscribe (EnumType event)
 Unsubscribe from a single event by enum value.
void unsubscribeAll ()
 Remove all event subscriptions for this component.

Detailed Description

Trait that gives components the ability to unsubscribe from events.

Unsubscribable is a separate trait inherited by Core. It provides unsubscribe() and unsubscribeAll() without touching EventReceiver, avoiding the diamond ambiguity that would arise if unsubscribe logic lived in EventReceiver (which is multiply inherited through traits).

Both built-in ml::Event values and user-defined manifest event enums work identically — any enum value is converted to a size_t key via EnumKey::get().

Usage

// Unsubscribe from a built-in event
myRect.unsubscribe(ml::Event::CLICK);
myRect.unsubscribe(ml::Event::HOVER);
// Unsubscribe from a custom manifest event
myRect.unsubscribe(MyManifest::Event::SCORE_CHANGED);
// Remove all subscriptions
myRect.unsubscribeAll();
@ CLICK
Mouse button released over component.
Definition Event.h:36
@ HOVER
Mouse entered component bounds.
Definition Event.h:37
Note
unsubscribeAll() is called automatically by Core's destructor. Explicit calls are only needed for mid-lifecycle cleanup.
See also
Core, EventReceiver, _EventsManager, EnumKey, ml::Event

Definition at line 45 of file Unsubscribable.h.

Constructor & Destructor Documentation

◆ ~Unsubscribable()

virtual ml::Unsubscribable::~Unsubscribable ( )
virtualdefault

Member Function Documentation

◆ unsubscribe()

template<typename EnumType>
void ml::Unsubscribable::unsubscribe ( EnumType event)
inline

Unsubscribe from a single event by enum value.

Works with any enum type — ml::Event for built-in events, or a manifest Event enum for custom events.

If called during a _EventsManager::fire() iteration the removal is deferred until the iteration completes.

Template Parameters
EnumTypeAny enum type. Enforced at compile time.
Parameters
eventThe enum value identifying the event to remove.

Definition at line 61 of file Unsubscribable.h.

◆ unsubscribeAll()

void ml::Unsubscribable::unsubscribeAll ( )

Remove all event subscriptions for this component.

Removes every subscription registered across all event names. Called automatically by Core's destructor.

If called during a _EventsManager::fire() iteration the removal is deferred until the iteration completes.


The documentation for this class was generated from the following file: