guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
floating_action_button_menu.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 <functional>
26#include <memory>
27#include <string>
28#include <utility>
29#include <vector>
30
31#include "guillaume/ecs/component_registry.hpp"
32#include "guillaume/entities/builder_base.hpp"
33#include "guillaume/ecs/entity_builder.hpp"
34#include "guillaume/ecs/parent_entity_filler.hpp"
35
36#include "guillaume/components/transform.hpp"
37#include "guillaume/components/bound.hpp"
38#include "guillaume/components/floating_action_button_menu.hpp"
39#include "guillaume/components/layout.hpp"
40
41#include "guillaume/entities/button_base.hpp"
42
43namespace guillaume::entities
44{
45
87 class FloatingActionButtonMenu:
88 public std::enable_shared_from_this<FloatingActionButtonMenu>,
89 public ecs::ParentEntityFiller<components::Transform, components::Bound,
90 components::Layout,
91 components::FloatingActionButtonMenu>
92 {
93 public:
97
105 class Builder: public EntityBuilderBase<FloatingActionButtonMenu>
106 {
107 private:
108 std::string _iconGlyphName;
109 std::vector<Action>
110 _actions;
111 std::string _accessibilityLabel;
112
113 public:
122 Builder(ecs::ComponentRegistry &componentRegistry,
123 ecs::EntityRegistry &entityRegistry);
124
134 std::shared_ptr<FloatingActionButtonMenu>
135 buildEntity(void) override;
136
143 void reset(void) override;
144
151 Builder &withIcon(const std::string &iconGlyphName);
152
160 Builder &addAction(const std::string &iconGlyphName,
161 std::function<void(void)> onClick);
162
173 Builder &addAction(const std::string &iconGlyphName,
174 const std::string &label,
175 std::function<void(void)> onClick);
176
184 Builder &
185 withAccessibilityLabel(const std::string &accessibilityLabel);
186
196 std::shared_ptr<FloatingActionButtonMenu>
197 makeFloatingActionButtonMenu(std::shared_ptr<Entity> parent,
198 const std::string &iconGlyphName);
199 };
200
213 template<typename... Arguments>
214 static std::shared_ptr<FloatingActionButtonMenu>
215 create(Arguments &&...arguments)
216 {
217 std::shared_ptr<FloatingActionButtonMenu> entity(
218 new FloatingActionButtonMenu(
219 std::forward<Arguments>(arguments)...));
220 entity->build();
221 return entity;
222 }
223
228
238
248
257
263 bool isOpen(void) const;
264
276 setOnStateChange(std::function<void(bool)> onStateChange);
277
282 std::size_t getActionCount(void) const;
283
291
299 ecs::Entity::Identifier getActionIdentifier(std::size_t index) const;
300
301 private:
307
312 const components::FloatingActionButtonMenu &state(void) const;
313
314 private:
327 const std::string &iconGlyphName,
328 const std::vector<Action> &actions,
329 const std::string &accessibilityLabel);
330
341 void build(void);
342 };
343
344} // namespace guillaume::entities
State of a floating action button menu (speed dial): a trigger button that expands into a column of a...
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
The base class of a widget with children: an EntityFiller that is also a ParentEntity.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
Builder & withAccessibilityLabel(const std::string &accessibilityLabel)
Set the label of the trigger read by assistive technology.
std::shared_ptr< FloatingActionButtonMenu > buildEntity(void) override
Build a FloatingActionButtonMenu, with its trigger and action buttons, from the current configuration...
std::shared_ptr< FloatingActionButtonMenu > makeFloatingActionButtonMenu(std::shared_ptr< Entity > parent, const std::string &iconGlyphName)
Build a menu with the actions added so far, register it under parent and reset the builder.
Builder & withIcon(const std::string &iconGlyphName)
Set the icon of the trigger while the menu is closed.
Builder & addAction(const std::string &iconGlyphName, std::function< void(void)> onClick)
Add an action shown as a small icon-only FAB.
void reset(void) override
Restore the default configuration.
A floating action button menu (speed dial): a trigger FAB that shows a column of smaller action butto...
components::FloatingActionButtonMenu::Action Action
FloatingActionButtonMenu & toggle(void)
Open the menu when it is closed, close it when it is open.
ecs::Entity::Identifier getTriggerIdentifier(void) const
Get the identifier of the trigger button, a FloatingActionButton child of the menu.
std::size_t getActionCount(void) const
Get the number of actions.
FloatingActionButtonMenu & close(void)
Close the menu: hide the action buttons and restore the trigger icon, at once.
FloatingActionButtonMenu & setOnStateChange(std::function< void(bool)> onStateChange)
Set the handler called when the menu opens or closes (Paper onStateChange).
static std::shared_ptr< FloatingActionButtonMenu > create(Arguments &&...arguments)
Create a menu with its trigger and action buttons, without registering it in an entity registry.
FloatingActionButtonMenu & open(void)
Open the menu: show the action buttons and the close glyph on the trigger, at once.
ecs::Entity::Identifier getActionIdentifier(std::size_t index) const
Get the identifier of the button of one action.
bool isOpen(void) const
Get whether the menu is open.
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
One entry of the menu: what its button shows and does.