guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
segmented_button.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/components/segmented_button.hpp"
24
25#include <utility>
26
28{
29 const std::vector<SegmentedButton::Segment> &
30 SegmentedButton::getSegments(void) const noexcept
31 {
32 return _segments;
33 }
34
36 SegmentedButton::setSegments(const std::vector<Segment> &segments)
37 {
38 if (_segments != segments) {
39 _segments = segments;
40 setHasChanged(true);
41 }
42 return *this;
43 }
44
46 bool disabled)
47 {
48 if (index < _segments.size() && _segments[index].disabled != disabled) {
49 _segments[index].disabled = disabled;
50 setHasChanged(true);
51 }
52 return *this;
53 }
54
57 {
58 return _selectionMode;
59 }
60
62 {
63 if (_selectionMode != mode) {
64 _selectionMode = mode;
65 setHasChanged(true);
66 }
67 return *this;
68 }
69
70 const std::vector<ecs::Entity::Identifier> &
71 SegmentedButton::getButtons(void) const noexcept
72 {
73 return _buttons;
74 }
75
77 const std::vector<ecs::Entity::Identifier> &buttons)
78 {
79 if (_buttons != buttons) {
80 _buttons = buttons;
81 setHasChanged(true);
82 }
83 return *this;
84 }
85
87 SegmentedButton::getOnChange(void) const noexcept
88 {
89 return _onChange;
90 }
91
93 {
94 _onChange = std::move(handler);
95 return *this;
96 }
97} // namespace guillaume::components
State of a segmented button: a row of joined toggle buttons of which one (or several) can be selected...
SelectionMode
How many segments can be selected at once.
const ChangeHandler & getOnChange(void) const noexcept
Get the callback run when the user presses a segment.
SegmentedButton & setSegments(const std::vector< Segment > &segments)
Replace the options of every segment.
std::function< void(std::size_t)> ChangeHandler
Called with the index of the segment the user just pressed.
const std::vector< Segment > & getSegments(void) const noexcept
Get 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(void)=default
Create the state of a single-selection segmented button with no segment.
SegmentedButton & setButtons(const std::vector< ecs::Entity::Identifier > &buttons)
Record the toggle button child of each segment.
SegmentedButton & setOnChange(ChangeHandler handler)
Set the callback run when the user presses a segment.
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.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.