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.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/extended_floating_action_button.hpp"
36#include "guillaume/entities/button_base.hpp"
37
38namespace guillaume::entities
39{
40
80 class ExtendedFloatingActionButton: public ButtonBase
81 {
82 public:
86
90
94
102 class Builder: public EntityBuilderBase<ExtendedFloatingActionButton>
103 {
104 private:
105 std::string
106 _iconGlyphName;
107 components::Glyph::Style _iconStyle;
108 std::string _labelContent;
109 std::function<void(void)>
110 _onClick;
111 Variant _variant;
112 Size _size;
113 bool _lowered;
114 bool _isDisabled;
115 std::string
116 _accessibilityLabel;
117
118 public:
127 Builder(ecs::ComponentRegistry &componentRegistry,
128 ecs::EntityRegistry &entityRegistry);
129
139 std::shared_ptr<ExtendedFloatingActionButton>
140 buildEntity(void) override;
141
149 void reset(void) override;
150
157 Builder &withIcon(const std::string &iconGlyphName);
158
166
173 Builder &withLabel(const std::string &labelContent);
174
181 Builder &withOnClick(std::function<void(void)> onClick);
182
188 Builder &withVariant(const Variant &variant);
189
195 Builder &withSize(const Size &size);
196
203 Builder &withLowered(const bool &lowered);
204
211 Builder &withDisabled(const bool &isDisabled);
212
219 Builder &
220 withAccessibilityLabel(const std::string &accessibilityLabel);
221
235 std::shared_ptr<ExtendedFloatingActionButton>
237 std::shared_ptr<Entity> parent,
238 const std::string &labelContent,
239 std::function<void(void)> onClick);
240 };
241
242 protected:
247 float getIconFontSize(void) const override;
248
254 bool usesLabel(void) const override
255 {
256 return true;
257 }
258
263 utility::graphic::Color32Bit
264 getInitialContentColor(void) const override;
265
266 public:
280 template<typename... Arguments>
281 static std::shared_ptr<ExtendedFloatingActionButton>
282 create(Arguments &&...arguments)
283 {
284 std::shared_ptr<ExtendedFloatingActionButton> entity(
285 new ExtendedFloatingActionButton(
286 std::forward<Arguments>(arguments)...));
287 entity->build();
288 return entity;
289 }
290
294 ~ExtendedFloatingActionButton(void) override = default;
295
301 ExtendedFloatingActionButton &setVariant(const Variant &variant);
302
310 ExtendedFloatingActionButton &setSize(const Size &size);
311
318 ExtendedFloatingActionButton &setMode(Mode mode);
319
324 Mode getMode(void) const;
325
338 ExtendedFloatingActionButton &setCustomSize(std::optional<float> size);
339
347 ExtendedFloatingActionButton &setExtended(bool extended);
348
354 bool isExtended(void) const;
355
362 ExtendedFloatingActionButton &setLowered(const bool &lowered);
363
369 Variant getVariant(void) const;
370
375 Size getSize(void) const;
376
381 bool isLowered(void) const;
382
383 private:
403 ExtendedFloatingActionButton(ecs::ComponentRegistry &registry,
404 const std::string &iconGlyphName,
405 const components::Glyph::Style &iconStyle,
406 const std::string &labelContent,
407 Variant variant, Size size, bool lowered,
408 bool isDisabled,
409 const std::string &accessibilityLabel,
410 std::function<void(void)> onClick);
411 };
412
413} // namespace guillaume::entities
Mode
Whether the button casts a shadow (Elevated) or not (Flat).
Variant
Which theme colors fill the container, the icon and the label.
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< 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.
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.
~ExtendedFloatingActionButton(void) override=default
Default destructor.
bool usesLabel(void) const override
Tell ButtonBase::build() that this variant has a label child.
bool isExtended(void) const
Check whether the FAB is extended.
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46