guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
extended_floating_action_button.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 <memory>
24#include <stdexcept>
25#include <utility>
26
27#include "guillaume/entities/extended_floating_action_button.hpp"
28#include "guillaume/entities/builder_base.hpp"
30#include "guillaume/components/elevation.hpp"
32#include "guillaume/theme.hpp"
33#include "guillaume/systems/extended_floating_action_button.hpp"
34
35namespace guillaume::entities
36{
38 ecs::ComponentRegistry &componentRegistry,
39 ecs::EntityRegistry &entityRegistry)
40 : EntityBuilderBase<ExtendedFloatingActionButton>(componentRegistry,
41 entityRegistry)
42 {
43 reset();
44 }
45
46 std::shared_ptr<ExtendedFloatingActionButton>
48 {
50 this->getComponentRegistry(), _iconGlyphName, _iconStyle,
51 _labelContent, _variant, _size, _lowered, _isDisabled,
52 _accessibilityLabel, _onClick);
53 return entity;
54 }
55
57 {
58 _iconGlyphName.clear();
59 _iconStyle = components::Glyph::Style::Outlined;
60 _labelContent.clear();
61 _variant = Variant::Primary;
62 _size = Size::Medium;
63 _lowered = false;
64 _isDisabled = false;
65 _accessibilityLabel.clear();
66 _onClick = {};
67 }
68
71 const std::string &iconGlyphName)
72 {
73 _iconGlyphName = iconGlyphName;
74 return *this;
75 }
76
79 const components::Glyph::Style &iconStyle)
80 {
81 _iconStyle = iconStyle;
82 return *this;
83 }
84
87 const std::string &labelContent)
88 {
89 _labelContent = labelContent;
90 return *this;
91 }
92
95 std::function<void(void)> onClick)
96 {
97 _onClick = std::move(onClick);
98 return *this;
99 }
100
103 const Variant &variant)
104 {
105 _variant = variant;
106 return *this;
107 }
108
111 {
112 _size = size;
113 return *this;
114 }
115
118 {
119 _lowered = lowered;
120 return *this;
121 }
122
125 const bool &isDisabled)
126 {
127 _isDisabled = isDisabled;
128 return *this;
129 }
130
133 const std::string &accessibilityLabel)
134 {
135 _accessibilityLabel = accessibilityLabel;
136 return *this;
137 }
138
139 std::shared_ptr<ExtendedFloatingActionButton>
141 std::shared_ptr<Entity> parent, const std::string &labelContent,
142 std::function<void(void)> onClick)
143 {
144 return withLabel(labelContent)
145 .withOnClick(onClick)
146 .registerEntity(parent);
147 }
148
149 ExtendedFloatingActionButton::ExtendedFloatingActionButton(
150 ecs::ComponentRegistry &registry, const std::string &iconGlyphName,
151 const components::Glyph::Style &iconStyle,
152 const std::string &labelContent, Variant variant, Size size,
153 bool lowered, bool isDisabled, const std::string &accessibilityLabel,
154 std::function<void(void)> onClick)
155 : ButtonBase(registry, iconGlyphName, iconStyle, labelContent, false,
156 false, isDisabled, false, accessibilityLabel,
157 std::move(onClick))
158 {
162 .setVariant(variant)
163 .setSize(size)
164 .setLowered(lowered);
169 getIdentifier());
170 }
171
177
178 utility::graphic::Color32Bit
184
195
198 {
199 if (size.has_value() && *size <= 0.0f) {
200 throw std::invalid_argument("FAB custom size must be positive");
201 }
205 .setCustomSize(size);
206 restyle();
207 return *this;
208 }
209
220
231
234 {
238 .setLowered(lowered);
239 restyle();
240 return *this;
241 }
242
253
262
271
280
288
296
297} // namespace guillaume::entities
Look of a Material 3 extended floating action button: a FAB that shows a label next to its icon and c...
Style
Family of the Material Symbols font the icon belongs to.
Definition glyph.hpp:66
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
ComponentType & addComponent(const Entity::Identifier &entityIdentifier, Args &&...args)
Construct a component for an entity, replacing the one it already has, if any.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
Entity::Signature getSignature(void) const noexcept
Get the set of component types the entity declares.
Definition entity.cpp:99
static Signature getSignatureFromTypes(void)
Build the signature that has exactly the bits of the given component types.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
Definition entity.cpp:94
void setSignature(void)
Replace the signature by the one made of the given component types.
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,...
void restyle(void)
Recompute colors and geometry now.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Configures, creates and registers ExtendedFloatingActionButton widgets.
Builder & withDisabled(const bool &isDisabled)
Choose whether the FAB starts disabled.
std::shared_ptr< ExtendedFloatingActionButton > makeExtendedFloatingActionButton(std::shared_ptr< Entity > parent, const std::string &labelContent, std::function< void(void)> onClick)
Build an extended FAB, register it under parent and reset the builder.
Builder & withVariant(const Variant &variant)
Set the color variant.
Builder & withLabel(const std::string &labelContent)
Set the label text.
Builder & withIconStyle(const components::Glyph::Style &iconStyle)
Set the glyph style of the icon.
void reset(void) override
Restore the default configuration.
std::shared_ptr< ExtendedFloatingActionButton > buildEntity(void) override
Build an ExtendedFloatingActionButton, with its icon and label children, from the current configurati...
Builder & withAccessibilityLabel(const std::string &accessibilityLabel)
Set the label read by assistive technology.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
Builder & withOnClick(std::function< void(void)> onClick)
Set the click handler.
Builder & withLowered(const bool &lowered)
Choose the lowered style: a weaker shadow (elevation level 1 instead of 3).
Builder & withIcon(const std::string &iconGlyphName)
Set the icon shown before the label.
A Material 3 extended floating action button: a wide, raised button with a text label and an optional...
static std::shared_ptr< ExtendedFloatingActionButton > create(Arguments &&...arguments)
Create an extended FAB and its icon and label children, without registering it in an entity registry.
utility::graphic::Color32Bit getInitialContentColor(void) const override
Get the color the icon and label children are created with.
ExtendedFloatingActionButton & setLowered(const bool &lowered)
Choose the lowered style: a weaker shadow (elevation level 1 instead of 3). Restyles at once.
ExtendedFloatingActionButton & setExtended(bool extended)
Expand (icon and label) or collapse (icon only) the FAB. Restyles at once.
components::ExtendedFloatingActionButton::Variant Variant
ExtendedFloatingActionButton & setVariant(const Variant &variant)
Set the color variant. Restyles at once.
ExtendedFloatingActionButton & setMode(Mode mode)
Set the shadow mode. Restyles at once.
components::ExtendedFloatingActionButton::Mode Mode
components::ExtendedFloatingActionButton::Size Size
bool isLowered(void) const
Get whether the FAB uses the lowered style.
ExtendedFloatingActionButton & setCustomSize(std::optional< float > size)
Override the container height (Paper customSize). Restyles at once.
ExtendedFloatingActionButton & setSize(const Size &size)
Set the size, which decides the container height, the corner radius and the icon size....
float getIconFontSize(void) const override
Get the font size the icon child is created with.
bool isExtended(void) const
Check whether the FAB is extended.
static utility::graphic::Color32Bit contentColor(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Get the color of the icon and label of the button when it is enabled and visible.
static float iconFontSize(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Get the font size of the icon for the configured size.
static void install(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Make an entity behave as an extended floating action button.
Makes the floating action button style tables reachable as guillaume::entities::fab_style.
Makes the color helpers callable from guillaume::entities without qualification.
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46