guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
icon_button.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 "guillaume/ecs/component_registry.hpp"
31#include "guillaume/entities/builder_base.hpp"
32#include "guillaume/ecs/entity_builder.hpp"
33
34#include "guillaume/components/icon_button.hpp"
35#include "guillaume/entities/button_base.hpp"
36
37namespace guillaume::entities
38{
39
76 class IconButton: public ButtonBase
77 {
78 public:
82
85
92 class Builder: public EntityBuilderBase<IconButton>
93 {
94 private:
95 std::string _iconGlyphName;
96 std::string _selectedIconGlyphName;
98 components::Glyph::Style _iconStyle;
99 std::function<void(void)>
100 _onClick;
101 bool _isToggle;
102 Variant _variant;
103 Size _size;
104 bool _isDisabled;
105 std::string
106 _accessibilityLabel;
107
108 public:
117 Builder(ecs::ComponentRegistry &componentRegistry,
118 ecs::EntityRegistry &entityRegistry);
119
128 std::shared_ptr<IconButton> buildEntity(void) override;
129
137 void reset(void) override;
138
145 Builder &withIcon(const std::string &iconGlyphName);
146
153 Builder &withSelectedIcon(const std::string &selectedIconGlyphName);
154
162
169 Builder &withOnClick(std::function<void(void)> onClick);
170
177 Builder &withToggle(const bool &isToggle);
178
184 Builder &withVariant(const Variant &variant);
185
191 Builder &withSize(const Size &size);
192
199 Builder &withDisabled(const bool &isDisabled);
200
207 Builder &
208 withAccessibilityLabel(const std::string &accessibilityLabel);
209
224 std::shared_ptr<IconButton>
225 makeIconButton(std::shared_ptr<Entity> parent,
226 const std::string &iconGlyphName,
227 std::function<void(void)> onClick,
228 Variant variant, Size size);
229 };
230
231 protected:
236 float getIconFontSize(void) const override;
237
243 bool usesLabel(void) const override
244 {
245 return false;
246 }
247
252 utility::graphic::Color32Bit
253 getInitialContentColor(void) const override;
254
255 public:
269 template<typename... Arguments>
270 static std::shared_ptr<IconButton> create(Arguments &&...arguments)
271 {
272 std::shared_ptr<IconButton> entity(
273 new IconButton(std::forward<Arguments>(arguments)...));
274 entity->build();
275 return entity;
276 }
277
281 ~IconButton(void) override = default;
282
288 IconButton &setVariant(const Variant &variant);
289
296 IconButton &setSize(const Size &size);
297
302 Variant getVariant(void) const;
303
308 Size getSize(void) const;
309
310 private:
329 IconButton(ecs::ComponentRegistry &registry,
330 const std::string &iconGlyphName,
331 const std::string &selectedIconGlyphName,
332 const components::Glyph::Style &iconStyle, bool isToggle,
333 Variant variant, Size size, bool isDisabled,
334 const std::string &accessibilityLabel,
335 std::function<void(void)> onClick);
336 };
337
338} // namespace guillaume::entities
Style
Family of the Material Symbols font the icon belongs to.
Definition glyph.hpp:66
Variant
Which theme colors fill the container and the icon.
Size
Size step: a 32, 40 or 48 dp container around an 18, 24 or 30 dp icon.
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.
bool isDisabled(void) const
Tell whether the button is disabled.
ButtonBase(ecs::ComponentRegistry &registry, const std::string &iconGlyphName, const components::Glyph::Style &iconStyle, const std::string &labelContent, bool isToggle, bool isMorph, bool isDisabled, bool isTrailingIcon, const std::string &accessibilityLabel, std::function< void(void)> onClick)
Create the entity with its components and store the initial state. The children are created later,...
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
Builder & withSelectedIcon(const std::string &selectedIconGlyphName)
Set the icon shown while a toggle button is selected.
std::shared_ptr< IconButton > makeIconButton(std::shared_ptr< Entity > parent, const std::string &iconGlyphName, std::function< void(void)> onClick, Variant variant, Size size)
Build an icon button, register it under parent and reset the builder.
Builder & withOnClick(std::function< void(void)> onClick)
Set the click handler.
Builder & withIconStyle(const components::Glyph::Style &iconStyle)
Set the glyph style of the icon.
std::shared_ptr< IconButton > buildEntity(void) override
Build an IconButton, with its icon child, from the current configuration, without registering it.
Builder & withToggle(const bool &isToggle)
Make the button a toggle: each click flips its selected state.
Builder & withDisabled(const bool &isDisabled)
Choose whether the button starts disabled.
Builder & withIcon(const std::string &iconGlyphName)
Set the icon.
void reset(void) override
Restore the default configuration.
Builder & withAccessibilityLabel(const std::string &accessibilityLabel)
Set the label read by assistive technology.
Builder & withVariant(const Variant &variant)
Set the color variant.
Builder & withSize(const Size &size)
Set the size.
IconButton & setSize(const Size &size)
Set the size, which decides the container and icon sizes. Restyles at once.
Variant getVariant(void) const
Get the color variant.
components::IconButton::Size Size
Size: Small, Medium or Large (see components::IconButton::Size).
utility::graphic::Color32Bit getInitialContentColor(void) const override
Get the color the icon child is created with.
IconButton & setVariant(const Variant &variant)
Set the color variant. Restyles at once.
float getIconFontSize(void) const override
Get the font size of the icon child for the current size.
bool usesLabel(void) const override
Tell ButtonBase::build() that this variant has no label child.
Size getSize(void) const
Get the size.
components::IconButton::Variant Variant
~IconButton(void) override=default
Default destructor.
static std::shared_ptr< IconButton > create(Arguments &&...arguments)
Create an icon button and its icon child, without registering it in an entity registry.
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46