|
guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
|
State shared by every pressable button, whatever its look. More...
#include <headers/guillaume/components/button.hpp>


Public Types | |
| using | Handler = std::function<void(void)> |
| Callback run when the button is clicked or long-pressed. | |
| using | TimePoint = std::chrono::steady_clock::time_point |
| Point in time on the clock used to measure how long a press lasts. | |
| using | OptionalColor = std::optional<utility::graphic::Color32Bit> |
| A color that replaces a themed one, or nothing to keep the theme. | |
| using | RestyleFunction |
Public Member Functions | |
| Button (void)=default | |
| Create the state of a plain button: no icon, no label, not a toggle, visible, no callback. | |
| ~Button (void)=default | |
| Default destructor. | |
| const std::string & | getIconGlyphName (void) const noexcept |
| Get the name of the icon glyph shown at rest. | |
| Button & | setIconGlyphName (const std::string &name) |
| Set the name of the icon glyph shown at rest. | |
| Glyph::Style | getIconStyle (void) const noexcept |
| Get the style the icon glyph is drawn in. | |
| Button & | setIconStyle (Glyph::Style style) |
| Set the style the icon glyph is drawn in. | |
| const std::string & | getSelectedIconGlyphName (void) const noexcept |
| Get the name of the icon glyph shown while selected. | |
| Button & | setSelectedIconGlyphName (const std::string &name) |
| Set the name of the icon glyph shown while selected. | |
| const std::string & | getLabelContent (void) const noexcept |
| Get the text of the label. | |
| Button & | setLabelContent (const std::string &content) |
| Set the text of the label. | |
| ecs::Entity::Identifier | getIcon (void) const noexcept |
| Get the child entity that draws the icon. | |
| Button & | setIcon (ecs::Entity::Identifier identifier) |
| Record which child entity draws the icon. | |
| ecs::Entity::Identifier | getLabel (void) const noexcept |
| Get the child entity that draws the label. | |
| Button & | setLabel (ecs::Entity::Identifier identifier) |
| Record which child entity draws the label. | |
| bool | isToggle (void) const noexcept |
| Check whether the button is a toggle. | |
| Button & | setToggle (bool toggle) |
| Make the button a toggle or a plain button. | |
| bool | isSelected (void) const noexcept |
| Check whether the button is selected. | |
| Button & | setSelected (bool selected) |
| Store the selection. | |
| bool | isMorph (void) const noexcept |
| Check whether the corner shape changes when selected. | |
| Button & | setMorph (bool morph) |
| Choose whether the corner shape changes when selected. | |
| bool | isTrailingIcon (void) const noexcept |
| Check on which side of the label the icon sits. | |
| Button & | setTrailingIcon (bool trailing) |
| Choose on which side of the label the icon sits. | |
| bool | isLoading (void) const noexcept |
| Check whether the button shows a progress glyph. | |
| Button & | setLoading (bool loading) |
| Show a progress glyph in place of the icon, or the icon again. | |
| bool | isVisible (void) const noexcept |
| Check whether the button is shown. | |
| Button & | setVisible (bool visible) |
| Show or hide the button. | |
| const Handler & | getOnClick (void) const noexcept |
| Get the click callback. | |
| Button & | setOnClick (Handler handler) |
| Set the callback run when the button is released. | |
| const Handler & | getOnLongPress (void) const noexcept |
| Get the long-press callback. | |
| Button & | setOnLongPress (Handler handler) |
| Set the callback run when the button is released after a long press. | |
| TimePoint | getPressStart (void) const noexcept |
| Get when the current press started. | |
| Button & | setPressStart (TimePoint time) |
| Record when the current press started. | |
| const OptionalColor & | getContainerColorOverride (void) const noexcept |
| Get the color that replaces the themed container color. | |
| Button & | setContainerColorOverride (const OptionalColor &color) |
| Replace the themed container (background) color. | |
| const OptionalColor & | getContentColorOverride (void) const noexcept |
| Get the color that replaces the themed content color. | |
| Button & | setContentColorOverride (const OptionalColor &color) |
| Replace the themed content (icon and label) color. | |
| RestyleFunction | getRestyle (void) const noexcept |
| Get the function that restyles this button at once. | |
| Button & | setRestyle (RestyleFunction function) |
| Register the function that restyles this button at once. | |
| 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. | |
State shared by every pressable button, whatever its look.
Holds what the button shows (icon glyph, label text, the identifiers of the icon and label child entities), how it reacts (toggle, click and long-press callbacks) and its transient state (selected, loading, visible, start of the current press).
Role in the frame:
Every setter except setOnClick() and setOnLongPress() compares before writing and marks the component changed only when the value differs. A setter stores the value and nothing else: the screen follows on the next frame, or at once if the caller then runs systems::Button::restyle().
Definition at line 76 of file button.hpp.
| using guillaume::components::Button::Handler = std::function<void(void)> |
Callback run when the button is clicked or long-pressed.
Definition at line 80 of file button.hpp.
| using guillaume::components::Button::OptionalColor = std::optional<utility::graphic::Color32Bit> |
A color that replaces a themed one, or nothing to keep the theme.
Definition at line 86 of file button.hpp.
Static function of a variant system that recomputes the colors and the geometry of one button at once, given the registry and the button's identifier.
Definition at line 91 of file button.hpp.
| using guillaume::components::Button::TimePoint = std::chrono::steady_clock::time_point |
Point in time on the clock used to measure how long a press lasts.
Definition at line 83 of file button.hpp.
|
noexcept |
Get the color that replaces the themed container color.
Definition at line 234 of file button.cpp.

|
noexcept |
Get the color that replaces the themed content color.
Definition at line 249 of file button.cpp.

|
noexcept |
Get the child entity that draws the icon.
Definition at line 85 of file button.cpp.

|
noexcept |
Get the name of the icon glyph shown at rest.
Definition at line 29 of file button.cpp.

|
noexcept |
Get the style the icon glyph is drawn in.
Definition at line 43 of file button.cpp.
|
noexcept |
Get the child entity that draws the label.
Definition at line 99 of file button.cpp.

|
noexcept |
Get the text of the label.
Definition at line 71 of file button.cpp.
|
noexcept |
Get the click callback.
Definition at line 197 of file button.cpp.
|
noexcept |
Get the long-press callback.
Definition at line 208 of file button.cpp.
|
noexcept |
Get when the current press started.
Definition at line 219 of file button.cpp.
|
noexcept |
Get the function that restyles this button at once.
Definition at line 263 of file button.cpp.
|
noexcept |
Get the name of the icon glyph shown while selected.
Definition at line 57 of file button.cpp.

|
noexcept |
Check whether the button shows a progress glyph.
Definition at line 169 of file button.cpp.

|
noexcept |
Check whether the corner shape changes when selected.
Definition at line 141 of file button.cpp.
|
noexcept |
Check whether the button is selected.
Definition at line 127 of file button.cpp.

|
noexcept |
Check whether the button is a toggle.
Definition at line 113 of file button.cpp.

|
noexcept |
Check on which side of the label the icon sits.
Definition at line 155 of file button.cpp.
|
noexcept |
Check whether the button is shown.
Definition at line 183 of file button.cpp.

| Button & guillaume::components::Button::setContainerColorOverride | ( | const OptionalColor & | color | ) |
Replace the themed container (background) color.
The variant system uses it as the resting color and still blends the hover and press layers over it. Disabled buttons keep the themed disabled color.
| color | The container color, or std::nullopt to follow the theme. |
Definition at line 239 of file button.cpp.


| Button & guillaume::components::Button::setContentColorOverride | ( | const OptionalColor & | color | ) |
Replace the themed content (icon and label) color.
| color | The content color, or std::nullopt to follow the theme. |
Definition at line 254 of file button.cpp.


| Button & guillaume::components::Button::setIcon | ( | ecs::Entity::Identifier | identifier | ) |
Record which child entity draws the icon.
The widget class calls it after creating the child; the component does not own the entity.
| identifier | The icon child, or ecs::Entity::InvalidIdentifier for none. |
Definition at line 90 of file button.cpp.


| Button & guillaume::components::Button::setIconGlyphName | ( | const std::string & | name | ) |
Set the name of the icon glyph shown at rest.
systems::Button copies it to the icon child's Glyph, unless the button is loading or selected with a selected glyph.
| name | The glyph name in the icon font, for example "add". |
Definition at line 34 of file button.cpp.


| Button & guillaume::components::Button::setIconStyle | ( | Glyph::Style | style | ) |
Set the style the icon glyph is drawn in.
| style | The glyph style, copied to the icon child's Glyph by systems::Button. |
Definition at line 48 of file button.cpp.


| Button & guillaume::components::Button::setLabel | ( | ecs::Entity::Identifier | identifier | ) |
Record which child entity draws the label.
| identifier | The label child, or ecs::Entity::InvalidIdentifier for none. |
Definition at line 104 of file button.cpp.


| Button & guillaume::components::Button::setLabelContent | ( | const std::string & | content | ) |
Set the text of the label.
The variant system writes it to the label child's Text.
| content | The label text. |
Definition at line 76 of file button.cpp.


| Button & guillaume::components::Button::setLoading | ( | bool | loading | ) |
Show a progress glyph in place of the icon, or the icon again.
While loading, systems::Button gives the icon child the glyph systems::Button::LoadingGlyph. The button still reacts to input.
| loading | True to show the progress glyph. |
Definition at line 174 of file button.cpp.


| Button & guillaume::components::Button::setMorph | ( | bool | morph | ) |
Choose whether the corner shape changes when selected.
Read by systems::CommonButton only: a selected toggle with morph draws the opposite of its configured shape (round becomes square and the reverse).
| morph | True to swap the shape while selected. |
Definition at line 146 of file button.cpp.


Set the callback run when the button is released.
It is not run when the release counts as a long press and a long-press callback is set. Does not mark the component changed.
| handler | The callback, or an empty one to remove it. |
Definition at line 202 of file button.cpp.


Set the callback run when the button is released after a long press.
A press held for at least systems::Button::LongPressDuration runs it instead of the click callback. Does not mark the component changed.
| handler | The callback, or an empty one so that every release is a click. |
Definition at line 213 of file button.cpp.


Record when the current press started.
Written by systems::Button: the time on press, a default-constructed TimePoint on release.
| time | The start of the press, or TimePoint {} for none. |
Definition at line 224 of file button.cpp.


| Button & guillaume::components::Button::setRestyle | ( | RestyleFunction | function | ) |
Register the function that restyles this button at once.
Each variant system's install() passes its static apply. systems::Button::restyle() calls it after every hover, press, release and selection change.
| function | The restyle function, or nullptr for none. |
Definition at line 268 of file button.cpp.

| Button & guillaume::components::Button::setSelected | ( | bool | selected | ) |
Store the selection.
It only stores the flag, even when the button is not a toggle. Use systems::Button::setSelected() to also update the icon and restyle.
| selected | True to select the button. |
Definition at line 132 of file button.cpp.


| Button & guillaume::components::Button::setSelectedIconGlyphName | ( | const std::string & | name | ) |
Set the name of the icon glyph shown while selected.
| name | The glyph name, or an empty string to keep the regular glyph when selected. |
Definition at line 62 of file button.cpp.


| Button & guillaume::components::Button::setToggle | ( | bool | toggle | ) |
Make the button a toggle or a plain button.
| toggle | True so that each release flips the selection; false so that a release only runs the callback. |
Definition at line 118 of file button.cpp.


| Button & guillaume::components::Button::setTrailingIcon | ( | bool | trailing | ) |
Choose on which side of the label the icon sits.
Read by systems::CommonButton only.
| trailing | True to place the icon after the label, false to place it before. |
Definition at line 160 of file button.cpp.


| Button & guillaume::components::Button::setVisible | ( | bool | visible | ) |
Show or hide the button.
A hidden button ignores press and release. Only the floating action button systems also draw it transparent and without shadow; the other variants keep drawing it.
| visible | False to hide the button. |
Definition at line 188 of file button.cpp.

