guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
accessibility.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/accessibility.hpp"
24
25#include <stdexcept>
26
28{
29 const std::string &Accessibility::getLabel(void) const
30 {
31 return _label;
32 }
33
34 Accessibility &Accessibility::setLabel(const std::string &label)
35 {
36 if (_label != label) {
37 _label = label;
38 setHasChanged(true);
39 }
40 return *this;
41 }
42
43 const std::string &Accessibility::getHint(void) const
44 {
45 return _hint;
46 }
47
48 Accessibility &Accessibility::setHint(const std::string &hint)
49 {
50 if (_hint != hint) {
51 _hint = hint;
52 setHasChanged(true);
53 }
54 return *this;
55 }
56
58 {
59 return _role;
60 }
61
63 {
64 if (_role != role) {
65 _role = role;
66 setHasChanged(true);
67 }
68 return *this;
69 }
70
72 {
73 return _selected;
74 }
75
77 {
78 if (_selected != selected) {
79 _selected = selected;
80 setHasChanged(true);
81 }
82 return *this;
83 }
84
85 std::optional<CheckedState> Accessibility::getChecked(void) const
86 {
87 return _checked;
88 }
89
91 Accessibility::setChecked(std::optional<CheckedState> checked)
92 {
93 if (_checked != checked) {
94 _checked = checked;
95 setHasChanged(true);
96 }
97 return *this;
98 }
99
100 std::optional<bool> Accessibility::getExpanded(void) const
101 {
102 return _expanded;
103 }
104
105 Accessibility &Accessibility::setExpanded(std::optional<bool> expanded)
106 {
107 if (_expanded != expanded) {
108 _expanded = expanded;
109 setHasChanged(true);
110 }
111 return *this;
112 }
113
114 const std::optional<AccessibilityValue> &Accessibility::getValue(void) const
115 {
116 return _value;
117 }
118
120 Accessibility::setValue(std::optional<AccessibilityValue> value)
121 {
122 if (value.has_value()
123 && (value->min > value->max || value->now < value->min
124 || value->now > value->max)) {
125 throw std::invalid_argument(
126 "Accessibility value must satisfy min <= now <= max");
127 }
128 _value = value;
129 setHasChanged(true);
130 return *this;
131 }
132
134 {
135 return _liveRegion;
136 }
137
139 {
140 if (_liveRegion != liveRegion) {
141 _liveRegion = liveRegion;
142 setHasChanged(true);
143 }
144 return *this;
145 }
146
148 {
149 return _focusOrder;
150 }
151
153 {
154 if (focusOrder < 0) {
155 throw std::invalid_argument("Focus order must be non-negative");
156 }
157 if (_focusOrder != focusOrder) {
158 _focusOrder = focusOrder;
159 setHasChanged(true);
160 }
161 return *this;
162 }
163
165 {
166 return _focusable;
167 }
168
170 {
171 if (_focusable != focusable) {
172 _focusable = focusable;
173 setHasChanged(true);
174 }
175 return *this;
176 }
177
178} // namespace guillaume::components
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setLiveRegion(LiveRegion liveRegion)
Set how urgently a change of the entity is announced.
const std::string & getHint(void) const
Get the sentence describing what activating the entity does.
std::optional< CheckedState > getChecked(void) const
Get whether the entity is ticked.
std::optional< bool > getExpanded(void) const
Get whether the entity shows the content it controls (an open menu, an unfolded section).
AccessibilityRole getRole(void) const
Get what kind of control the entity is.
LiveRegion getLiveRegion(void) const
Get how urgently a change of the entity is announced.
Accessibility & setHint(const std::string &hint)
Set the sentence describing what activating the entity does, such as "Closes the dialog".
const std::string & getLabel(void) const
Get the name announced for the entity.
Accessibility & setExpanded(std::optional< bool > expanded)
Set whether the entity shows the content it controls.
Accessibility & setFocusOrder(int focusOrder)
Set the rank of the entity in the Tab traversal.
Accessibility(void)=default
Construct a description with no label, no role, no state, a focus order of 0 and the focusable flag s...
int getFocusOrder(void) const
Get the rank of the entity in the Tab traversal.
Accessibility & setFocusable(bool focusable)
Include the entity in the Tab traversal or leave it out.
Accessibility & setRole(AccessibilityRole role)
Set what kind of control the entity is.
bool isSelected(void) const
Check whether the entity is the selected one of its group (the active navigation destination,...
Accessibility & setSelected(bool selected)
Set whether the entity is the selected one of its group.
const std::optional< AccessibilityValue > & getValue(void) const
Get the position of the entity within its range.
bool isFocusable(void) const
Check whether the Tab traversal stops on the entity.
Accessibility & setLabel(const std::string &label)
Set the name announced for the entity, such as "Close".
Accessibility & setChecked(std::optional< CheckedState > checked)
Set whether the entity is ticked.
Accessibility & setValue(std::optional< AccessibilityValue > value)
Set the position of the entity within its range.
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.
AccessibilityRole
What an entity is for a screen reader or another assistive technology. The values mirror react-native...
LiveRegion
How urgently a change of the entity is announced to the user.