guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
card.hpp
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#pragma once
23
24#include <functional>
25#include <string>
26#include <vector>
27
28#include "guillaume/ecs/component.hpp"
29#include "guillaume/ecs/entity.hpp"
30
32{
33
64 class Card: public ecs::Component
65 {
66 public:
77
81 struct Action {
82 std::string label;
83 std::function<void(void)>
85 };
86
88 using Handler = std::function<void(void)>;
89
91 using Identifiers = std::vector<ecs::Entity::Identifier>;
92
96 static constexpr float CoverHeight = 195.0f;
97
101 static constexpr float TitleMinHeight = 72.0f;
102
103 private:
104 Variant _variant { Variant::Elevated };
105 bool _interactive { false };
106 bool _pressed { false };
107 float _pressProgress { 0.0f };
108 float _pressFrom { 0.0f };
109 std::string _coverPath {};
110 std::string _title {};
111 std::string _subtitle {};
112 std::string _contentText {};
115 };
116
117 ecs::Entity::Identifier _titleSection {
119 };
120
121 ecs::Entity::Identifier _titleText {
123 };
124
125 ecs::Entity::Identifier _subtitleText {
127 };
128
129 ecs::Entity::Identifier _contentEntity {
131 };
132
133 ecs::Entity::Identifier _actionsSection {
135 };
136
137 std::vector<Action> _actions {};
138 Identifiers _actionButtons {};
139 Handler _onPress {};
140
141 public:
146 Card(void) = default;
147
151 ~Card(void) = default;
152
157 Variant getVariant(void) const noexcept;
158
164 Card &setVariant(Variant variant);
165
170 bool isInteractive(void) const noexcept;
171
181 Card &setInteractive(bool interactive);
182
188 bool isPressed(void) const noexcept;
189
198 Card &setPressed(bool pressed);
199
204 float getPressProgress(void) const noexcept;
205
215 Card &setPressProgress(float pressProgress);
216
221 float getPressFrom(void) const noexcept;
222
231 Card &setPressFrom(float pressFrom);
232
237 const std::string &getCoverPath(void) const noexcept;
238
246 Card &setCoverPath(const std::string &coverPath);
247
252 const std::string &getTitle(void) const noexcept;
253
262 Card &setTitle(const std::string &title);
263
268 const std::string &getSubtitle(void) const noexcept;
269
277 Card &setSubtitle(const std::string &subtitle);
278
283 const std::string &getContentText(void) const noexcept;
284
292 Card &setContentText(const std::string &contentText);
293
299 ecs::Entity::Identifier getCover(void) const noexcept;
300
308
315 ecs::Entity::Identifier getTitleSection(void) const noexcept;
316
325
331 ecs::Entity::Identifier getTitleText(void) const noexcept;
332
340
346 ecs::Entity::Identifier getSubtitleText(void) const noexcept;
347
355
361 ecs::Entity::Identifier getContentEntity(void) const noexcept;
362
370
376 ecs::Entity::Identifier getActionsSection(void) const noexcept;
377
385
390 const std::vector<Action> &getActions(void) const noexcept;
391
400 Card &addAction(Action action);
401
406 const Identifiers &getActionButtons(void) const noexcept;
407
415 Card &setActionButtons(const Identifiers &identifiers);
416
421 const Handler &getOnPress(void) const noexcept;
422
432 Card &setOnPress(Handler handler);
433 };
434
435} // 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
static constexpr float CoverHeight
Height of the cover image, in dp.
Definition card.hpp:96
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
static constexpr float TitleMinHeight
Minimum height of the title section, in dp.
Definition card.hpp:101
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(void)=default
Default destructor.
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
@ Outlined
Surface fill with a 1 dp outline-variant stroke.
Definition card.hpp:75
@ Filled
Surface-variant fill, no shadow, no outline.
Definition card.hpp:74
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
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
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
std::function< void(void)> onPress
Called when the button is clicked.
Definition card.hpp:84
std::string label
Button label.
Definition card.hpp:82