|
guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
|
Configuration of a switch: its variant, its thumb icon, its label and the identifiers of its thumb, icon and label children. More...
#include <headers/guillaume/components/switch.hpp>


Public Types | |
| enum class | Variant { Enabled , Disabled , WithIcon } |
| Visual variant. More... | |
| using | ValueChangeHandler = std::function<void(bool)> |
Public Member Functions | |
| Switch (void)=default | |
| Create the configuration of an enabled switch with no icon and no label. | |
| ~Switch (void)=default | |
| Default destructor. | |
| Variant | getVariant (void) const noexcept |
| Get the visual variant. | |
| Switch & | setVariant (Variant variant) |
| Choose the visual variant. | |
| const std::string & | getIconGlyph (void) const noexcept |
| Get the name of the glyph drawn on the thumb. | |
| Switch & | setIconGlyph (const std::string &glyph) |
| Set the name of the glyph drawn on the thumb. | |
| const std::string & | getLabel (void) const noexcept |
| Get the label text. | |
| Switch & | setLabel (const std::string &label) |
| Set the label text. | |
| ecs::Entity::Identifier | getThumb (void) const noexcept |
| Get the child entity drawn as the thumb. | |
| Switch & | setThumb (ecs::Entity::Identifier identifier) |
| Record which child entity is the thumb. | |
| ecs::Entity::Identifier | getIcon (void) const noexcept |
| Get the child entity that draws the thumb icon. | |
| Switch & | setIcon (ecs::Entity::Identifier identifier) |
| Record which child entity draws the thumb icon. | |
| ecs::Entity::Identifier | getLabelEntity (void) const noexcept |
| Get the child entity that draws the label. | |
| Switch & | setLabelEntity (ecs::Entity::Identifier identifier) |
| Record which child entity draws the label. | |
| const ValueChangeHandler & | getOnValueChange (void) const noexcept |
| Get the callback run when the user toggles the switch. | |
| Switch & | setOnValueChange (ValueChangeHandler handler) |
| Set the callback run when the user toggles the switch. | |
| 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. | |
Static Public Attributes | |
| static constexpr float | ThumbSize = 24.0f |
| Diameter of the thumb, in dp. | |
| static constexpr float | ThumbInset = 4.0f |
| Inset of the thumb from the track ends, in dp. | |
| static constexpr float | LabelGap = 16.0f |
| Gap between the track and the label, in dp. | |
Configuration of a switch: its variant, its thumb icon, its label and the identifiers of its thumb, icon and label children.
Whether the switch is on is not stored here but in the components::Value of the same entity: 1 is on, 0 is off.
Role in the frame:
To switch from code call systems::Switch::setChecked(); a user press goes through systems::Switch::toggle(), which also runs the value-change callback.
Definition at line 55 of file switch.hpp.
| using guillaume::components::Switch::ValueChangeHandler = std::function<void(bool)> |
Called with the new value (true when on) when the user toggles the switch.
Definition at line 69 of file switch.hpp.
|
strong |
Visual variant.
Enabled is the regular look. Disabled greys the switch and makes it ignore presses. WithIcon is the variant of a switch whose thumb carries an icon; it is styled like Enabled.
Definition at line 65 of file switch.hpp.
|
noexcept |
Get the child entity that draws the thumb icon.
Definition at line 85 of file switch.cpp.
|
noexcept |
Get the name of the glyph drawn on the thumb.
Definition at line 43 of file switch.cpp.
|
noexcept |
Get the label text.
Definition at line 57 of file switch.cpp.
|
noexcept |
Get the child entity that draws the label.
Definition at line 99 of file switch.cpp.
|
noexcept |
Get the callback run when the user toggles the switch.
Definition at line 114 of file switch.cpp.
|
noexcept |
Get the child entity drawn as the thumb.
Definition at line 71 of file switch.cpp.
|
noexcept |
Get the visual variant.
Definition at line 29 of file switch.cpp.
| Switch & guillaume::components::Switch::setIcon | ( | ecs::Entity::Identifier | identifier | ) |
Record which child entity draws the thumb icon.
Marks the component changed when the identifier differs. The system keeps the icon centered on the thumb.
| identifier | The icon child. |
Definition at line 90 of file switch.cpp.

| Switch & guillaume::components::Switch::setIconGlyph | ( | const std::string & | glyph | ) |
Set the name of the glyph drawn on the thumb.
Marks the component changed when the name differs. The widget class reads it when it creates the icon child; an empty name creates none.
| glyph | The glyph name in the icon font. |
Definition at line 48 of file switch.cpp.

| Switch & guillaume::components::Switch::setLabel | ( | const std::string & | label | ) |
Set the label text.
Marks the component changed when the text differs. The system copies it to the switch's Accessibility label; the text drawn on screen is the one of the label child.
| label | The label text. |
Definition at line 62 of file switch.cpp.

| Switch & guillaume::components::Switch::setLabelEntity | ( | ecs::Entity::Identifier | identifier | ) |
Record which child entity draws the label.
Marks the component changed when the identifier differs.
| identifier | The label child. |
Definition at line 104 of file switch.cpp.

| Switch & guillaume::components::Switch::setOnValueChange | ( | ValueChangeHandler | handler | ) |
Set the callback run when the user toggles the switch.
It is not run when the value is set from code. Does not mark the component changed.
| handler | The callback; it receives true when the switch was just turned on. |
Definition at line 119 of file switch.cpp.

| Switch & guillaume::components::Switch::setThumb | ( | ecs::Entity::Identifier | identifier | ) |
Record which child entity is the thumb.
Marks the component changed when the identifier differs.
| identifier | The thumb child. |
Definition at line 76 of file switch.cpp.

Choose the visual variant.
Marks the component changed when the variant differs. The system enables or disables the entity's interaction to match.
| variant | Enabled, Disabled or WithIcon. |
Definition at line 34 of file switch.cpp.

|
staticconstexpr |
Gap between the track and the label, in dp.
Definition at line 78 of file switch.hpp.
|
staticconstexpr |
Inset of the thumb from the track ends, in dp.
Definition at line 75 of file switch.hpp.
|
staticconstexpr |
Diameter of the thumb, in dp.
Definition at line 72 of file switch.hpp.