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

Trait that adds selection and deselection callbacks to any Core object. More...

#include <Malena/Traits/Interaction/Selectable.h>

Inheritance diagram for ml::Selectable:
[legend]

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.

Detailed Description

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.

Usage

class MyItem : public ml::ComponentWith<MyManifest>, public ml::Selectable
{
public:
MyItem()
{
onSelected([this]{ setFillColor(sf::Color::Blue); });
onDeselected([this]{ setFillColor(sf::Color::White); });
}
};
// Programmatic selection — fires the callbacks
item.select();
item.deselect();
Trait that adds selection and deselection callbacks to any Core object.
Definition Selectable.h:62
void onDeselected(std::function< void()> callback)
Register a no-argument callback invoked when this component is deselected.
void onSelected(std::function< void()> callback)
Register a no-argument callback invoked when this component is selected.
void select()
Fire the onSelected callbacks on this component.
static const Color White
static const Color Blue
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Definition Component.h:299

To unsubscribe:

item.unsubscribe(ml::Event::SELECTED);
item.unsubscribe(ml::Event::DESELECTED);
@ SELECTED
Component was programmatically selected.
Definition Event.h:60
@ DESELECTED
Component was programmatically deselected.
Definition Event.h:61
See also
RadioButton, ml::Event::SELECTED, ml::Event::DESELECTED, Clickable

Definition at line 61 of file Selectable.h.

Member Function Documentation

◆ deselect()

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.

◆ onDeselected() [1/2]

void ml::Selectable::onDeselected ( std::function< void()> callback)

Register a no-argument callback invoked when this component is deselected.

Parameters
callbackFunction invoked with no arguments on deselection.

◆ onDeselected() [2/2]

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).

Parameters
callbackFunction invoked with the SFML event on deselection.

◆ onSelected() [1/2]

void ml::Selectable::onSelected ( std::function< void()> callback)

Register a no-argument callback invoked when this component is selected.

Parameters
callbackFunction invoked with no arguments on selection.

◆ onSelected() [2/2]

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).

Parameters
callbackFunction invoked with the SFML event on selection.

◆ process() [1/2]

virtual void ml::EventReceiver::process ( const std::string & key,
const std::optional< sf::Event > & event )
virtualinherited

Invoke all callbacks registered for key.

Called by framework dispatchers. key is the string produced by EnumKey::get(eventEnum).

Parameters
keyString key identifying the event.
eventSFML event forwarded to each callback.

◆ process() [2/2]

template<typename ENUM_TYPE>
void ml::EventReceiver::process ( ENUM_TYPE eventName,
const std::optional< sf::Event > & event )
inherited

Invoke all callbacks registered for eventName.

Template overload that accepts any enum value directly, converting to a string key via EnumKey::get() internally.

Template Parameters
ENUM_TYPEAny enum type.
Parameters
eventNameThe enum value identifying the event.
eventSFML event forwarded to each callback.

◆ select()

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.


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