|
guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
|
State of a segmented button: a row of joined toggle buttons of which one (or several) can be selected. More...
#include <headers/guillaume/components/segmented_button.hpp>


Classes | |
| struct | Segment |
| What one segment shows and whether it can be pressed. More... | |
Public Types | |
| enum class | SelectionMode { Single , Multi } |
| How many segments can be selected at once. More... | |
| using | ChangeHandler = std::function<void(std::size_t)> |
| Called with the index of the segment the user just pressed. | |
Public Member Functions | |
| SegmentedButton (void)=default | |
| Create the state of a single-selection segmented button with no segment. | |
| ~SegmentedButton (void)=default | |
| Default destructor. | |
| const std::vector< Segment > & | getSegments (void) const noexcept |
| Get the options of every segment. | |
| SegmentedButton & | setSegments (const std::vector< Segment > &segments) |
| Replace the options of every segment. | |
| SegmentedButton & | setSegmentDisabled (std::size_t index, bool disabled) |
| Record whether one segment is disabled. | |
| SelectionMode | getSelectionMode (void) const noexcept |
| Get the selection mode. | |
| SegmentedButton & | setSelectionMode (SelectionMode mode) |
| Choose how many segments can be selected at once. | |
| const std::vector< ecs::Entity::Identifier > & | getButtons (void) const noexcept |
| Get the toggle button child of each segment. | |
| SegmentedButton & | setButtons (const std::vector< ecs::Entity::Identifier > &buttons) |
| Record the toggle button child of each segment. | |
| const ChangeHandler & | getOnChange (void) const noexcept |
| Get the callback run when the user presses a segment. | |
| SegmentedButton & | setOnChange (ChangeHandler handler) |
| Set the callback run when the user presses a segment. | |
| 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 | MinSegmentWidth = 76.0f |
| Minimum width of a segment, in dp. | |
State of a segmented button: a row of joined toggle buttons of which one (or several) can be selected.
It holds the options of each segment, the selection mode, the press callback and the identifier of the toggle button child of each segment. The selection itself is not stored here: a segment is selected when its button child is (components::Button::isSelected).
Role in the frame:
To select a segment from code, call systems::SegmentedButton::select() or deselect(); to read the selection, isSelected() or selectedIndices().
Definition at line 60 of file segmented_button.hpp.
| using guillaume::components::SegmentedButton::ChangeHandler = std::function<void(std::size_t)> |
Called with the index of the segment the user just pressed.
Definition at line 94 of file segmented_button.hpp.
|
strong |
How many segments can be selected at once.
Single: selecting a segment deselects the others, and pressing the selected segment keeps it selected. Multi: each segment toggles on its own.
Definition at line 70 of file segmented_button.hpp.
|
noexcept |
Get the toggle button child of each segment.
Definition at line 71 of file segmented_button.cpp.

|
noexcept |
Get the callback run when the user presses a segment.
Definition at line 87 of file segmented_button.cpp.
|
noexcept |
Get the options of every segment.
Definition at line 30 of file segmented_button.cpp.
|
noexcept |
Get the selection mode.
Definition at line 56 of file segmented_button.cpp.
| SegmentedButton & guillaume::components::SegmentedButton::setButtons | ( | const std::vector< ecs::Entity::Identifier > & | buttons | ) |
Record the toggle button child of each segment.
Marks the component changed when the list differs.
| buttons | Their identifiers, in segment order. |
Definition at line 76 of file segmented_button.cpp.

| SegmentedButton & guillaume::components::SegmentedButton::setOnChange | ( | ChangeHandler | handler | ) |
Set the callback run when the user presses a segment.
It runs after the selection was updated, and not for a selection made from code. Does not mark the component changed.
| handler | The callback; it receives the index of the pressed segment. |
Definition at line 92 of file segmented_button.cpp.

| SegmentedButton & guillaume::components::SegmentedButton::setSegmentDisabled | ( | std::size_t | index, |
| bool | disabled ) |
Record whether one segment is disabled.
It only updates the stored option, and marks the component changed when it differs. Use systems::SegmentedButton::setSegmentDisabled() to also disable and restyle the segment's button.
| index | The segment index (ignored when out of range). |
| disabled | True when the segment cannot be pressed. |
Definition at line 45 of file segmented_button.cpp.

| SegmentedButton & guillaume::components::SegmentedButton::setSegments | ( | const std::vector< Segment > & | segments | ) |
Replace the options of every segment.
Marks the component changed when the list differs. The widget class creates one button child per entry.
| segments | The new options, in layout order. |
Definition at line 36 of file segmented_button.cpp.

| SegmentedButton & guillaume::components::SegmentedButton::setSelectionMode | ( | SelectionMode | mode | ) |
Choose how many segments can be selected at once.
Marks the component changed when the mode differs. It does not touch the current selection.
| mode | Single or Multi. |
Definition at line 61 of file segmented_button.cpp.

|
staticconstexpr |
Minimum width of a segment, in dp.
Definition at line 97 of file segmented_button.hpp.