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
23#pragma once
24
25#include <utility>
26#include <functional>
27#include <memory>
28#include <string>
29
30#include <utility/graphic/color.hpp>
31#include <utility/graphic/pose.hpp>
32
33#include "guillaume/ecs/component_registry.hpp"
34#include "guillaume/ecs/entity_builder.hpp"
35
36#include "guillaume/components/chip.hpp"
37#include "guillaume/components/elevation.hpp"
38#include "guillaume/components/selection.hpp"
39
40#include "guillaume/entities/icon.hpp"
41#include "guillaume/entities/builder_base.hpp"
42#include "guillaume/entities/surface.hpp"
43#include "guillaume/entities/text.hpp"
44
45namespace guillaume::entities
46{
47
94 class Chip:
95 public SurfaceBase<components::Selectable, components::Elevation,
96 components::Chip>
97 {
98 public:
102
105
112 class Builder: public EntityBuilderBase<Chip>
113 {
114 private:
115 SurfaceConfig _config;
116 Variant _variant { Variant::Assist };
117 std::string _label {};
118 std::string
119 _iconGlyph {};
120 bool _selected { false };
121
122 public:
131 Builder(ecs::ComponentRegistry &componentRegistry,
132 ecs::EntityRegistry &entityRegistry);
133
142 std::shared_ptr<Chip> buildEntity(void) override;
143
152 void reset(void) override;
153
160 Builder &withPose(const utility::graphic::PoseF &pose);
161
168 Builder &withVariant(Variant variant);
169
176 Builder &withLabel(const std::string &label);
177
185 Builder &withIcon(const std::string &iconGlyph);
186
192 Builder &withSelected(bool selected);
193
207 std::shared_ptr<Chip> makeChip(std::shared_ptr<ecs::Entity> parent,
208 Variant variant,
209 const std::string &label,
210 const std::string &iconGlyph,
211 bool selected);
212 };
213
226 template<typename... Arguments>
227 static std::shared_ptr<Chip> create(Arguments &&...arguments)
228 {
229 std::shared_ptr<Chip> entity(
230 new Chip(std::forward<Arguments>(arguments)...));
231 entity->build();
232 return entity;
233 }
234
238 ~Chip(void) override;
239
249 Chip &setVariant(Variant variant);
250
255 Variant getVariant(void) const;
256
263 Chip &setLabel(const std::string &label);
264
273 Chip &setSelected(bool selected);
274
279 bool isSelected(void) const;
280
287 Chip &setMode(Mode mode);
288
293 Mode getMode(void) const;
294
303 Chip &setDisabled(bool disabled);
304
309 bool isDisabled(void) const;
310
318 Chip &setCompact(bool compact);
319
327 Chip &setElevated(bool elevated);
328
336 Chip &setShowSelectedOverlay(bool show);
337
347 Chip &setShowSelectedCheck(bool show);
348
358 Chip &setOnPress(std::function<void(void)> onPress);
359
371 Chip &setOnClose(std::function<void(void)> onClose);
372
379
380 private:
394 Chip(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
395 Variant variant, const std::string &label,
396 const std::string &iconGlyph, bool selected);
397
405 void build(void);
406 };
407
408} // namespace guillaume::entities
Mode
Container style: Flat is filled with the secondary container color; Outlined is transparent with an o...
Definition chip.hpp:77
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
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
Builder & withLabel(const std::string &label)
Set the label text.
Definition chip.cpp:82
Builder & withIcon(const std::string &iconGlyph)
Set the leading icon.
Definition chip.cpp:88
Builder & withVariant(Variant variant)
Set the variant, which decides the children built and whether a press toggles the selection.
Definition chip.cpp:76
std::shared_ptr< Chip > makeChip(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &label, const std::string &iconGlyph, bool selected)
Build a chip, register it under parent and reset the builder.
Definition chip.cpp:101
Builder & withSelected(bool selected)
Choose whether the chip starts selected.
Definition chip.cpp:94
void reset(void) override
Restore the default configuration.
Definition chip.cpp:51
Builder & withPose(const utility::graphic::PoseF &pose)
Set the position and orientation of the chip.
Definition chip.cpp:70
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
Definition chip.cpp:37
std::shared_ptr< Chip > buildEntity(void) override
Build a Chip, with its icon and label children, from the current configuration, without registering i...
Definition chip.cpp:44
A compact, 32 dp high pill with a label and optional icons, used as an action, a filter,...
Definition chip.hpp:97
Chip & setSelected(bool selected)
Select or deselect the chip, whatever its variant. Restyles at once.
Definition chip.cpp:247
bool isSelected(void) const
Check whether the chip is selected.
Definition chip.cpp:254
Mode getMode(void) const
Get the mode.
Definition chip.cpp:143
Chip & setOnClose(std::function< void(void)> onClose)
Set the handler called when the user presses the trailing close icon (Paper onClose).
Definition chip.cpp:207
Variant getVariant(void) const
Get the variant.
Definition chip.cpp:231
Chip & setMode(Mode mode)
Set the mode. Restyles at once.
Definition chip.cpp:134
Chip & setShowSelectedCheck(bool show)
Show the check icon while the chip is selected (Paper showSelectedCheck). Restyles at once.
Definition chip.cpp:190
Chip & setCompact(bool compact)
Use the compact padding (Paper compact). Restyles at once.
Definition chip.cpp:163
~Chip(void) override
Destructor.
Definition chip.cpp:130
Chip & setShowSelectedOverlay(bool show)
Darken the chip with a pressed state layer while it is selected (Paper showSelectedOverlay)....
Definition chip.cpp:181
bool isDisabled(void) const
Check whether the chip is disabled.
Definition chip.cpp:157
Chip & setVariant(Variant variant)
Set the variant. Restyles at once.
Definition chip.cpp:222
Chip & setElevated(bool elevated)
Paint a level 1 shadow under the chip (Paper elevated). Restyles at once.
Definition chip.cpp:172
Chip & setOnPress(std::function< void(void)> onPress)
Set the handler called when the user presses the chip (Paper onPress).
Definition chip.cpp:199
ecs::Entity::Identifier getCloseIconIdentifier(void) const
Get the identifier of the trailing close icon child.
Definition chip.cpp:215
Chip & setLabel(const std::string &label)
Set the label text. Restyles at once.
Definition chip.cpp:238
components::Chip::Variant Variant
Definition chip.hpp:101
Chip & setDisabled(bool disabled)
Enable or disable the chip. Restyles at once.
Definition chip.cpp:150
static std::shared_ptr< Chip > create(Arguments &&...arguments)
Create a chip and its icon and label children, without registering it in an entity registry.
Definition chip.hpp:227
components::Chip::Mode Mode
Paper chip mode: Flat (tonal fill, the default) or Outlined.
Definition chip.hpp:104
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
Definition surface.hpp:71