guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
card.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/card.hpp"
24
25#include <utility>
26
28{
29 Card::Variant Card::getVariant(void) const noexcept
30 {
31 return _variant;
32 }
33
35 {
36 if (_variant != variant) {
37 _variant = variant;
38 setHasChanged(true);
39 }
40 return *this;
41 }
42
43 bool Card::isInteractive(void) const noexcept
44 {
45 return _interactive;
46 }
47
48 Card &Card::setInteractive(bool interactive)
49 {
50 if (_interactive != interactive) {
51 _interactive = interactive;
52 setHasChanged(true);
53 }
54 return *this;
55 }
56
57 bool Card::isPressed(void) const noexcept
58 {
59 return _pressed;
60 }
61
62 Card &Card::setPressed(bool pressed)
63 {
64 if (_pressed != pressed) {
65 _pressed = pressed;
66 setHasChanged(true);
67 }
68 return *this;
69 }
70
71 float Card::getPressProgress(void) const noexcept
72 {
73 return _pressProgress;
74 }
75
76 Card &Card::setPressProgress(float pressProgress)
77 {
78 if (_pressProgress != pressProgress) {
79 _pressProgress = pressProgress;
80 setHasChanged(true);
81 }
82 return *this;
83 }
84
85 float Card::getPressFrom(void) const noexcept
86 {
87 return _pressFrom;
88 }
89
90 Card &Card::setPressFrom(float pressFrom)
91 {
92 if (_pressFrom != pressFrom) {
93 _pressFrom = pressFrom;
94 setHasChanged(true);
95 }
96 return *this;
97 }
98
99 const std::string &Card::getCoverPath(void) const noexcept
100 {
101 return _coverPath;
102 }
103
104 Card &Card::setCoverPath(const std::string &coverPath)
105 {
106 if (_coverPath != coverPath) {
107 _coverPath = coverPath;
108 setHasChanged(true);
109 }
110 return *this;
111 }
112
113 const std::string &Card::getTitle(void) const noexcept
114 {
115 return _title;
116 }
117
118 Card &Card::setTitle(const std::string &title)
119 {
120 if (_title != title) {
121 _title = title;
122 setHasChanged(true);
123 }
124 return *this;
125 }
126
127 const std::string &Card::getSubtitle(void) const noexcept
128 {
129 return _subtitle;
130 }
131
132 Card &Card::setSubtitle(const std::string &subtitle)
133 {
134 if (_subtitle != subtitle) {
135 _subtitle = subtitle;
136 setHasChanged(true);
137 }
138 return *this;
139 }
140
141 const std::string &Card::getContentText(void) const noexcept
142 {
143 return _contentText;
144 }
145
146 Card &Card::setContentText(const std::string &contentText)
147 {
148 if (_contentText != contentText) {
149 _contentText = contentText;
150 setHasChanged(true);
151 }
152 return *this;
153 }
154
156 {
157 return _cover;
158 }
159
161 {
162 if (_cover != identifier) {
163 _cover = identifier;
164 setHasChanged(true);
165 }
166 return *this;
167 }
168
170 {
171 return _titleSection;
172 }
173
175 {
176 if (_titleSection != identifier) {
177 _titleSection = identifier;
178 setHasChanged(true);
179 }
180 return *this;
181 }
182
184 {
185 return _titleText;
186 }
187
189 {
190 if (_titleText != identifier) {
191 _titleText = identifier;
192 setHasChanged(true);
193 }
194 return *this;
195 }
196
198 {
199 return _subtitleText;
200 }
201
203 {
204 if (_subtitleText != identifier) {
205 _subtitleText = identifier;
206 setHasChanged(true);
207 }
208 return *this;
209 }
210
212 {
213 return _contentEntity;
214 }
215
217 {
218 if (_contentEntity != identifier) {
219 _contentEntity = identifier;
220 setHasChanged(true);
221 }
222 return *this;
223 }
224
226 {
227 return _actionsSection;
228 }
229
231 {
232 if (_actionsSection != identifier) {
233 _actionsSection = identifier;
234 setHasChanged(true);
235 }
236 return *this;
237 }
238
239 const std::vector<Card::Action> &Card::getActions(void) const noexcept
240 {
241 return _actions;
242 }
243
245 {
246 _actions.push_back(std::move(action));
247 setHasChanged(true);
248 return *this;
249 }
250
251 const Card::Identifiers &Card::getActionButtons(void) const noexcept
252 {
253 return _actionButtons;
254 }
255
257 {
258 if (_actionButtons != identifiers) {
259 _actionButtons = identifiers;
260 setHasChanged(true);
261 }
262 return *this;
263 }
264
265 const Card::Handler &Card::getOnPress(void) const noexcept
266 {
267 return _onPress;
268 }
269
271 {
272 _onPress = std::move(handler);
273 return *this;
274 }
275} // namespace guillaume::components
const std::vector< Action > & getActions(void) const noexcept
Get the actions the card was asked to show.
Definition card.cpp:239
bool isInteractive(void) const noexcept
Check whether the card reacts to hover and press.
Definition card.cpp:43
Card & setPressed(bool pressed)
Record the pressed state the press motion heads to.
Definition card.cpp:62
const std::string & getCoverPath(void) const noexcept
Get the path of the cover texture.
Definition card.cpp:99
bool isPressed(void) const noexcept
Check whether the press motion is heading to the raised state.
Definition card.cpp:57
ecs::Entity::Identifier getActionsSection(void) const noexcept
Get the child entity that contains the action buttons.
Definition card.cpp:225
ecs::Entity::Identifier getCover(void) const noexcept
Get the child entity that draws the cover image.
Definition card.cpp:155
Card & setInteractive(bool interactive)
Record that the card reacts to hover and press.
Definition card.cpp:48
ecs::Entity::Identifier getTitleSection(void) const noexcept
Get the child entity that contains the title and the subtitle.
Definition card.cpp:169
const Identifiers & getActionButtons(void) const noexcept
Get the entities of the action buttons.
Definition card.cpp:251
Card & setSubtitle(const std::string &subtitle)
Set the subtitle text.
Definition card.cpp:132
float getPressFrom(void) const noexcept
Get the press progress at which the running motion began.
Definition card.cpp:85
Card(void)=default
Create the state of an empty, elevated card that cannot be pressed.
Card & setTitleText(ecs::Entity::Identifier identifier)
Record which entity draws the title text.
Definition card.cpp:188
std::function< void(void)> Handler
Callback run when the card is pressed.
Definition card.hpp:88
Card & setActionButtons(const Identifiers &identifiers)
Record which entities are the action buttons.
Definition card.cpp:256
const Handler & getOnPress(void) const noexcept
Get the callback run when the card is pressed.
Definition card.cpp:265
float getPressProgress(void) const noexcept
Get how far the card is raised by a press.
Definition card.cpp:71
Card & setContentText(const std::string &contentText)
Set the content text.
Definition card.cpp:146
Card & setPressProgress(float pressProgress)
Set how far the card is raised by a press.
Definition card.cpp:76
const std::string & getTitle(void) const noexcept
Get the title text.
Definition card.cpp:113
Card & setVariant(Variant variant)
Choose the look of the card surface.
Definition card.cpp:34
const std::string & getContentText(void) const noexcept
Get the content text.
Definition card.cpp:141
Card & setTitle(const std::string &title)
Set the title text.
Definition card.cpp:118
Card & setActionsSection(ecs::Entity::Identifier identifier)
Record which child entity contains the action buttons.
Definition card.cpp:230
Variant
Look of the card surface.
Definition card.hpp:70
Card & setCover(ecs::Entity::Identifier identifier)
Record which child entity draws the cover image.
Definition card.cpp:160
Card & setSubtitleText(ecs::Entity::Identifier identifier)
Record which entity draws the subtitle text.
Definition card.cpp:202
std::vector< ecs::Entity::Identifier > Identifiers
List of child entity identifiers.
Definition card.hpp:91
ecs::Entity::Identifier getTitleText(void) const noexcept
Get the entity that draws the title text.
Definition card.cpp:183
const std::string & getSubtitle(void) const noexcept
Get the subtitle text.
Definition card.cpp:127
Card & setOnPress(Handler handler)
Store the callback run when the card is pressed.
Definition card.cpp:270
ecs::Entity::Identifier getContentEntity(void) const noexcept
Get the child entity that draws the content text.
Definition card.cpp:211
Card & setTitleSection(ecs::Entity::Identifier identifier)
Record which child entity contains the title and the subtitle.
Definition card.cpp:174
Card & setCoverPath(const std::string &coverPath)
Set the path of the cover texture.
Definition card.cpp:104
ecs::Entity::Identifier getSubtitleText(void) const noexcept
Get the entity that draws the subtitle text.
Definition card.cpp:197
Card & addAction(Action action)
Append an action to the actions row.
Definition card.cpp:244
Card & setContentEntity(ecs::Entity::Identifier identifier)
Record which child entity draws the content text.
Definition card.cpp:216
Card & setPressFrom(float pressFrom)
Record the press progress at which a motion begins.
Definition card.cpp:90
Variant getVariant(void) const noexcept
Get the look of the card surface.
Definition card.cpp:29
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
State. Every class here is plain data attached to an entity.
One button of the actions row: its label and what it does.
Definition card.hpp:81