guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::Selectable Class Reference

Selected/unselected flag of an entity, with a callback run when it changes. More...

#include <headers/guillaume/components/selection.hpp>

Inheritance diagram for guillaume::components::Selectable:
Collaboration diagram for guillaume::components::Selectable:

Public Types

using Handler = std::function<void(bool)>
 Callback receiving the new state: true when just selected.

Public Member Functions

 Selectable (void)=default
 Create an unselected flag with no handler.
 ~Selectable (void)=default
 Default destructor for the Selectable component.
bool isSelected (void) const
 Check whether the entity is selected.
Selectable & setSelected (bool selected)
 Select or deselect the entity.
Selectable & setOnSelectionChangedHandler (const Handler &handler)
 Set the callback run when the selection changes.
Handler getOnSelectionChangedHandler (void) const
 Get the callback run when the selection changes.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

Selected/unselected flag of an entity, with a callback run when it changes.

Widget systems write it and read it as the selection of their widget: radio buttons, checkboxes, chips and navigation destinations all have one. When the parent entity has a components::SelectionGroup, systems::Selection (Event phase) keeps at most one Selectable child selected.

registry.getComponent<components::Selectable>(identifier)
.setOnSelectionChangedHandler([](bool selected) { ... })
.setSelected(true); // runs the handler with true
Selected/unselected flag of an entity, with a callback run when it changes.
Definition selection.hpp:57
Selectable & setSelected(bool selected)
Select or deselect the entity.
Definition selection.cpp:32
Selectable & setOnSelectionChangedHandler(const Handler &handler)
Set the callback run when the selection changes.
Definition selection.cpp:45

The handler runs inside setSelected(), synchronously. The widget systems install their own handler here to restyle the widget, so replacing it on a widget's entity removes that behaviour.

See also
components::SelectionGroup
systems::Selection

Definition at line 56 of file selection.hpp.

Member Typedef Documentation

◆ Handler

using guillaume::components::Selectable::Handler = std::function<void(bool)>

Callback receiving the new state: true when just selected.

Definition at line 60 of file selection.hpp.

Member Function Documentation

◆ getOnSelectionChangedHandler()

Selectable::Handler guillaume::components::Selectable::getOnSelectionChangedHandler ( void ) const

Get the callback run when the selection changes.

Returns
A copy of the callback, empty when none is set.

Definition at line 51 of file selection.cpp.

◆ isSelected()

bool guillaume::components::Selectable::isSelected ( void ) const

Check whether the entity is selected.

Returns
True when selected.

Definition at line 27 of file selection.cpp.

◆ setOnSelectionChangedHandler()

Selectable & guillaume::components::Selectable::setOnSelectionChangedHandler ( const Handler & handler)

Set the callback run when the selection changes.

Replaces the previous handler. Does not mark the component changed.

Parameters
handlerThe callback, or an empty one to remove it.
Returns
This component, for chaining.

Definition at line 45 of file selection.cpp.

Here is the call graph for this function:

◆ setSelected()

Selectable & guillaume::components::Selectable::setSelected ( bool selected)

Select or deselect the entity.

When the state differs from the stored one, stores it, marks the component changed and calls the handler with the new state. Does nothing otherwise.

Parameters
selectedTrue to select the entity.
Returns
This component, for chaining.

Definition at line 32 of file selection.cpp.

Here is the call graph for this function:

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