guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
chip.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/chip.hpp"
24
25#include <utility>
26
28{
29 Chip::Variant Chip::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 Chip::Mode Chip::getMode(void) const noexcept
44 {
45 return _mode;
46 }
47
49 {
50 if (_mode != mode) {
51 _mode = mode;
52 setHasChanged(true);
53 }
54 return *this;
55 }
56
57 const std::string &Chip::getLabel(void) const noexcept
58 {
59 return _label;
60 }
61
62 Chip &Chip::setLabel(const std::string &label)
63 {
64 if (_label != label) {
65 _label = label;
66 setHasChanged(true);
67 }
68 return *this;
69 }
70
71 const std::string &Chip::getIconGlyph(void) const noexcept
72 {
73 return _iconGlyph;
74 }
75
76 Chip &Chip::setIconGlyph(const std::string &iconGlyph)
77 {
78 if (_iconGlyph != iconGlyph) {
79 _iconGlyph = iconGlyph;
80 setHasChanged(true);
81 }
82 return *this;
83 }
84
86 {
87 return _leadingIcon;
88 }
89
91 {
92 if (_leadingIcon != identifier) {
93 _leadingIcon = identifier;
94 setHasChanged(true);
95 }
96 return *this;
97 }
98
100 {
101 return _trailingIcon;
102 }
103
105 {
106 if (_trailingIcon != identifier) {
107 _trailingIcon = identifier;
108 setHasChanged(true);
109 }
110 return *this;
111 }
112
114 {
115 return _labelEntity;
116 }
117
119 {
120 if (_labelEntity != identifier) {
121 _labelEntity = identifier;
122 setHasChanged(true);
123 }
124 return *this;
125 }
126
128 {
129 return _checkIcon;
130 }
131
133 {
134 if (_checkIcon != identifier) {
135 _checkIcon = identifier;
136 setHasChanged(true);
137 }
138 return *this;
139 }
140
141 bool Chip::isCompact(void) const noexcept
142 {
143 return _compact;
144 }
145
146 Chip &Chip::setCompact(bool compact)
147 {
148 if (_compact != compact) {
149 _compact = compact;
150 setHasChanged(true);
151 }
152 return *this;
153 }
154
155 bool Chip::isElevated(void) const noexcept
156 {
157 return _elevated;
158 }
159
160 Chip &Chip::setElevated(bool elevated)
161 {
162 if (_elevated != elevated) {
163 _elevated = elevated;
164 setHasChanged(true);
165 }
166 return *this;
167 }
168
169 bool Chip::isShowSelectedOverlay(void) const noexcept
170 {
171 return _showSelectedOverlay;
172 }
173
175 {
176 if (_showSelectedOverlay != show) {
177 _showSelectedOverlay = show;
178 setHasChanged(true);
179 }
180 return *this;
181 }
182
183 bool Chip::isShowSelectedCheck(void) const noexcept
184 {
185 return _showSelectedCheck;
186 }
187
189 {
190 if (_showSelectedCheck != show) {
191 _showSelectedCheck = show;
192 setHasChanged(true);
193 }
194 return *this;
195 }
196
197 const Chip::Handler &Chip::getOnPress(void) const noexcept
198 {
199 return _onPress;
200 }
201
203 {
204 _onPress = std::move(handler);
205 return *this;
206 }
207
208 const Chip::Handler &Chip::getOnClose(void) const noexcept
209 {
210 return _onClose;
211 }
212
214 {
215 _onClose = std::move(handler);
216 return *this;
217 }
218} // namespace guillaume::components
Chip & setCompact(bool compact)
Choose between the regular and the compact padding.
Definition chip.cpp:146
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
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
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 & 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
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.
Chip & setIconGlyph(const std::string &iconGlyph)
Set the name of the leading icon glyph.
Definition chip.cpp:76
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.