guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
floating_action_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 <optional>
28#include <memory>
29#include <string>
30
31#include "guillaume/ecs/component_registry.hpp"
32#include "guillaume/entities/builder_base.hpp"
33#include "guillaume/ecs/entity_builder.hpp"
34
35#include "guillaume/components/floating_action_button.hpp"
36#include "guillaume/entities/button_base.hpp"
37
38namespace guillaume::entities
39{
40
79 class FloatingActionButton: public ButtonBase
80 {
81 public:
85
89
93
101 class Builder: public EntityBuilderBase<FloatingActionButton>
102 {
103 private:
104 std::string _iconGlyphName;
105 components::Glyph::Style _iconStyle;
106 std::string _labelContent;
107 std::function<void(void)>
108 _onClick;
109 Variant _variant;
110 Size _size;
111 bool _lowered;
112 bool _isDisabled;
113 std::string
114 _accessibilityLabel;
115
116 public:
125 Builder(ecs::ComponentRegistry &componentRegistry,
126 ecs::EntityRegistry &entityRegistry);
127
137 std::shared_ptr<FloatingActionButton> buildEntity(void) override;
138
146 void reset(void) override;
147
154 Builder &withIcon(const std::string &iconGlyphName);
155
163
170 Builder &withLabel(const std::string &labelContent);
171
178 Builder &withOnClick(std::function<void(void)> onClick);
179
185 Builder &withVariant(const Variant &variant);
186
192 Builder &withSize(const Size &size);
193
201 Builder &withLowered(const bool &lowered);
202
209 Builder &withDisabled(const bool &isDisabled);
210
217 Builder &
218 withAccessibilityLabel(const std::string &accessibilityLabel);
219
234 std::shared_ptr<FloatingActionButton>
235 makeFloatingActionButton(std::shared_ptr<Entity> parent,
236 const std::string &iconGlyphName,
237 std::function<void(void)> onClick,
238 Variant variant, Size size);
239 };
240
241 protected:
246 float getIconFontSize(void) const override;
247
253 bool usesLabel(void) const override
254 {
255 return true;
256 }
257
262 utility::graphic::Color32Bit
263 getInitialContentColor(void) const override;
264
265 public:
279 template<typename... Arguments>
280 static std::shared_ptr<FloatingActionButton>
281 create(Arguments &&...arguments)
282 {
283 std::shared_ptr<FloatingActionButton> entity(
284 new FloatingActionButton(
285 std::forward<Arguments>(arguments)...));
286 entity->build();
287 return entity;
288 }
289
293 ~FloatingActionButton(void) override = default;
294
300 FloatingActionButton &setVariant(const Variant &variant);
301
309 FloatingActionButton &setSize(const Size &size);
310
317 FloatingActionButton &setMode(Mode mode);
318
323 Mode getMode(void) const;
324
336 FloatingActionButton &setCustomSize(std::optional<float> size);
337
345 FloatingActionButton &setLowered(const bool &lowered);
346
351 Variant getVariant(void) const;
352
357 Size getSize(void) const;
358
363 bool isLowered(void) const;
364
365 private:
384 FloatingActionButton(ecs::ComponentRegistry &registry,
385 const std::string &iconGlyphName,
386 const components::Glyph::Style &iconStyle,
387 const std::string &labelContent, Variant variant,
388 Size size, bool lowered, bool isDisabled,
389 const std::string &accessibilityLabel,
390 std::function<void(void)> onClick);
391 };
392
393} // namespace guillaume::entities
Size
Size step: a 40, 56 or 96 dp square container around a 24, 24 or 36 dp icon.
Mode
Whether the button casts a shadow (Elevated) or not (Flat).
Variant
Which theme colors fill the container and the icon.
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...
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 & withDisabled(const bool &isDisabled)
Choose whether the FAB starts disabled.
std::shared_ptr< FloatingActionButton > buildEntity(void) override
Build a FloatingActionButton, with its icon and label children, from the current configuration,...
Builder & withOnClick(std::function< void(void)> onClick)
Set the click handler.
Builder & withVariant(const Variant &variant)
Set the color variant.
Builder & withSize(const Size &size)
Set the size.
Builder & withAccessibilityLabel(const std::string &accessibilityLabel)
Set the label read by assistive technology.
Builder & withIcon(const std::string &iconGlyphName)
Set the icon.
Builder & withLowered(const bool &lowered)
Choose the lowered style: a weaker shadow (elevation level 1 instead of 3) and, for Variant::Surface,...
std::shared_ptr< FloatingActionButton > makeFloatingActionButton(std::shared_ptr< Entity > parent, const std::string &iconGlyphName, std::function< void(void)> onClick, Variant variant, Size size)
Build a FAB, register it under parent and reset the builder.
Builder & withLabel(const std::string &labelContent)
Set the label text, shown after the icon.
Builder & withIconStyle(const components::Glyph::Style &iconStyle)
Set the glyph style of the icon.
void reset(void) override
Restore the default configuration.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
float getIconFontSize(void) const override
Get the font size of the icon child for the current size.
bool isLowered(void) const
Get whether the FAB uses the lowered style.
components::FloatingActionButton::Variant Variant
components::FloatingActionButton::Mode Mode
~FloatingActionButton(void) override=default
Default destructor.
Variant getVariant(void) const
Get the color variant.
FloatingActionButton & setCustomSize(std::optional< float > size)
Override the side of the square container (Paper customSize). Restyles at once.
FloatingActionButton & setVariant(const Variant &variant)
Set the color variant. Restyles at once.
static std::shared_ptr< FloatingActionButton > create(Arguments &&...arguments)
Create a FAB and its icon and label children, without registering it in an entity registry.
FloatingActionButton & setSize(const Size &size)
Set the size, which decides the container size, the corner radius and the icon size....
components::FloatingActionButton::Size Size
utility::graphic::Color32Bit getInitialContentColor(void) const override
Get the color the icon and label children are created with.
bool usesLabel(void) const override
Tell ButtonBase::build() that this variant has a label child.
Mode getMode(void) const
Get the shadow mode.
FloatingActionButton & setMode(Mode mode)
Set the shadow mode. Restyles at once.
FloatingActionButton & setLowered(const bool &lowered)
Choose the lowered style: a weaker shadow (elevation level 1 instead of 3) and, for Variant::Surface,...
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46