guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
chip.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
27#include "guillaume/ecs/component.hpp"
28#include "guillaume/ecs/entity.hpp"
29
31{
32
59 class Chip: public ecs::Component
60 {
61 public:
70 enum class Variant { Assist, Filter, Input, Suggestion };
71
77 enum class Mode { Flat, Outlined };
78
80 using Handler = std::function<void(void)>;
81
83 static constexpr const char *DefaultAssistGlyph = "event";
84
86 static constexpr const char *CheckGlyph = "check";
87
89 static constexpr const char *CloseGlyph = "close";
90
92 static constexpr float IconSize = 18.0f;
93
95 static constexpr float Padding = 12.0f;
96
98 static constexpr float CompactPadding = 8.0f;
99
100 private:
101 Variant _variant { Variant::Assist };
102 Mode _mode { Mode::Flat };
103 std::string _label {};
104 std::string _iconGlyph {};
105 ecs::Entity::Identifier _leadingIcon {
107 };
108
109 ecs::Entity::Identifier _trailingIcon {
111 };
112
113 ecs::Entity::Identifier _labelEntity {
115 };
116
117 ecs::Entity::Identifier _checkIcon {
119 };
120
121 bool _compact { false };
122 bool _elevated { false };
123 bool _showSelectedOverlay { false };
124 bool _showSelectedCheck { true };
125 Handler _onPress {};
126 Handler _onClose {};
127
128 public:
133 Chip(void) = default;
134
138 ~Chip(void) = default;
139
144 Variant getVariant(void) const noexcept;
145
152 Chip &setVariant(Variant variant);
153
158 Mode getMode(void) const noexcept;
159
166 Chip &setMode(Mode mode);
167
172 const std::string &getLabel(void) const noexcept;
173
182 Chip &setLabel(const std::string &label);
183
189 const std::string &getIconGlyph(void) const noexcept;
190
197 Chip &setIconGlyph(const std::string &iconGlyph);
198
204 ecs::Entity::Identifier getLeadingIcon(void) const noexcept;
205
213
219 ecs::Entity::Identifier getTrailingIcon(void) const noexcept;
220
231
237 ecs::Entity::Identifier getLabelEntity(void) const noexcept;
238
246
252 ecs::Entity::Identifier getCheckIcon(void) const noexcept;
253
261
267 bool isCompact(void) const noexcept;
268
275 Chip &setCompact(bool compact);
276
281 bool isElevated(void) const noexcept;
282
289 Chip &setElevated(bool elevated);
290
295 bool isShowSelectedOverlay(void) const noexcept;
296
304 Chip &setShowSelectedOverlay(bool show);
305
311 bool isShowSelectedCheck(void) const noexcept;
312
319 Chip &setShowSelectedCheck(bool show);
320
325 const Handler &getOnPress(void) const noexcept;
326
335 Chip &setOnPress(Handler handler);
336
341 const Handler &getOnClose(void) const noexcept;
342
352 Chip &setOnClose(Handler handler);
353 };
354
355} // namespace guillaume::components
Chip & setCompact(bool compact)
Choose between the regular and the compact padding.
Definition chip.cpp:146
static constexpr float Padding
Padding around the content, in dp.
Definition chip.hpp:95
Chip & setShowSelectedOverlay(bool show)
Choose whether a selected chip is darkened by a state layer.
Definition chip.cpp:174
ecs::Entity::Identifier getCheckIcon(void) const noexcept
Get the child entity that draws the selected check.
Definition chip.cpp:127
Chip & setShowSelectedCheck(bool show)
Choose whether a selected chip shows its check.
Definition chip.cpp:188
static constexpr const char * DefaultAssistGlyph
Glyph of the leading icon of an Assist chip without one.
Definition chip.hpp:83
const std::string & getLabel(void) const noexcept
Get the label text.
Definition chip.cpp:57
ecs::Entity::Identifier getLeadingIcon(void) const noexcept
Get the child entity that draws the leading icon.
Definition chip.cpp:85
Variant getVariant(void) const noexcept
Get the kind of chip.
Definition chip.cpp:29
Chip & setMode(Mode mode)
Choose the container style.
Definition chip.cpp:48
const std::string & getIconGlyph(void) const noexcept
Get the name of the leading icon glyph.
Definition chip.cpp:71
Mode
Container style: Flat is filled with the secondary container color; Outlined is transparent with an o...
Definition chip.hpp:77
bool isShowSelectedCheck(void) const noexcept
Check whether a selected chip shows its check.
Definition chip.cpp:183
Chip & setOnPress(Handler handler)
Set the callback run when the chip is pressed.
Definition chip.cpp:202
static constexpr float IconSize
Font size of the icons, in dp.
Definition chip.hpp:92
ecs::Entity::Identifier getLabelEntity(void) const noexcept
Get the child entity that draws the label.
Definition chip.cpp:113
Chip & setCheckIcon(ecs::Entity::Identifier identifier)
Record which child entity draws the selected check.
Definition chip.cpp:132
Chip & setLeadingIcon(ecs::Entity::Identifier identifier)
Record which child entity draws the leading icon.
Definition chip.cpp:90
bool isElevated(void) const noexcept
Check whether the chip casts a shadow.
Definition chip.cpp:155
~Chip(void)=default
Default destructor.
static constexpr const char * CloseGlyph
Glyph of the trailing close icon.
Definition chip.hpp:89
Chip & setLabelEntity(ecs::Entity::Identifier identifier)
Record which child entity draws the label.
Definition chip.cpp:118
Chip & setOnClose(Handler handler)
Set the callback run when the close icon is pressed.
Definition chip.cpp:213
Chip & setLabel(const std::string &label)
Set the label text.
Definition chip.cpp:62
const Handler & getOnPress(void) const noexcept
Get the callback run when the chip is pressed.
Definition chip.cpp:197
bool isCompact(void) const noexcept
Check whether the chip uses the compact padding.
Definition chip.cpp:141
Chip & setTrailingIcon(ecs::Entity::Identifier identifier)
Record which child entity draws the trailing close icon.
Definition chip.cpp:104
const Handler & getOnClose(void) const noexcept
Get the callback run when the close icon is pressed.
Definition chip.cpp:208
Mode getMode(void) const noexcept
Get the container style.
Definition chip.cpp:43
static constexpr float CompactPadding
Padding around the content of a compact chip, in dp.
Definition chip.hpp:98
Chip & setElevated(bool elevated)
Choose whether the chip casts a shadow.
Definition chip.cpp:160
std::function< void(void)> Handler
Callback run when the chip, or its close icon, is activated.
Definition chip.hpp:80
ecs::Entity::Identifier getTrailingIcon(void) const noexcept
Get the child entity that draws the trailing close icon.
Definition chip.cpp:99
Chip & setVariant(Variant variant)
Choose the kind of chip.
Definition chip.cpp:34
bool isShowSelectedOverlay(void) const noexcept
Check whether a selected chip is darkened by a state layer.
Definition chip.cpp:169
Chip(void)=default
Create the configuration of a flat Assist chip with no label.
static constexpr const char * CheckGlyph
Glyph of the selected check.
Definition chip.hpp:86
Chip & setIconGlyph(const std::string &iconGlyph)
Set the name of the leading icon glyph.
Definition chip.cpp:76
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.