Trait that adds selection and deselection callbacks to any Core object.
More...
#include <Malena/Traits/Interaction/Selectable.h>
Public Member Functions | |
| void | deselect () |
Fire the onDeselected callbacks on this component. | |
| void | onDeselected (std::function< void()> callback) |
| Register a no-argument callback invoked when this component is deselected. | |
| void | onDeselected (std::function< void(const std::optional< sf::Event > &)> callback) |
Register a callback invoked when this component is deselected, receiving the raw SFML event (always std::nullopt for programmatic deselection). | |
| void | onSelected (std::function< void()> callback) |
| Register a no-argument callback invoked when this component is selected. | |
| void | onSelected (std::function< void(const std::optional< sf::Event > &)> callback) |
Register a callback invoked when this component is selected, receiving the raw SFML event (always std::nullopt for programmatic selection). | |
| 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. | |
| void | select () |
Fire the onSelected callbacks on this component. | |
Trait that adds selection and deselection callbacks to any Core object.
Selectable is an opt-in trait for components that represent a choosable option — radio buttons, dropdown items, list items, tab headers, and similar controls. It provides onSelected and onDeselected callback hooks that fire when the component is programmatically selected or deselected.
Unlike Clickable, Selectable does not react to SFML events directly. Selection is always triggered programmatically — typically by a container such as RadioGroup or Dropdown calling select() or deselect() on a specific component instance. The dispatcher exists only to register the event keys with the framework; it never fires on its own.
To unsubscribe:
Definition at line 61 of file Selectable.h.
| void ml::Selectable::deselect | ( | ) |
Fire the onDeselected callbacks on this component.
Called by container types to notify the component that it is no longer the chosen option.
| void ml::Selectable::onDeselected | ( | std::function< void()> | callback | ) |
Register a no-argument callback invoked when this component is deselected.
| callback | Function invoked with no arguments on deselection. |
| void ml::Selectable::onDeselected | ( | std::function< void(const std::optional< sf::Event > &)> | callback | ) |
Register a callback invoked when this component is deselected, receiving the raw SFML event (always std::nullopt for programmatic deselection).
| callback | Function invoked with the SFML event on deselection. |
| void ml::Selectable::onSelected | ( | std::function< void()> | callback | ) |
Register a no-argument callback invoked when this component is selected.
| callback | Function invoked with no arguments on selection. |
| void ml::Selectable::onSelected | ( | std::function< void(const std::optional< sf::Event > &)> | callback | ) |
Register a callback invoked when this component is selected, receiving the raw SFML event (always std::nullopt for programmatic selection).
| callback | Function invoked with the SFML event on selection. |
|
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::Selectable::select | ( | ) |
Fire the onSelected callbacks on this component.
Called by container types (RadioGroup, Dropdown, etc.) to notify the component that it has been chosen. Does not interact with the Flag or State system — that remains the responsibility of the concrete component class.