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 <string>
27#include <vector>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
61 {
62 public:
66 struct Action {
69 std::string label;
70 std::string iconGlyphName;
71 std::function<void(void)>
73 };
74
77 using StateChangeHandler = std::function<void(bool)>;
78
80 static constexpr float Spacing = 16.0f;
81
82 private:
83 std::string _iconGlyphName {};
84 std::vector<Action> _actions {};
85 std::string _accessibilityLabel {};
86 bool _open { false };
87 StateChangeHandler _onStateChange {};
90 };
91
92 std::vector<ecs::Entity::Identifier>
93 _actionButtons {};
94
95 public:
99 FloatingActionButtonMenu(void) = default;
100
105
110 const std::string &getIconGlyphName(void) const noexcept;
111
121 FloatingActionButtonMenu &setIconGlyphName(const std::string &name);
122
127 const std::vector<Action> &getActions(void) const noexcept;
128
138 FloatingActionButtonMenu &setActions(std::vector<Action> actions);
139
144 const std::string &getAccessibilityLabel(void) const noexcept;
145
156 setAccessibilityLabel(const std::string &label);
157
162 bool isOpen(void) const noexcept;
163
174
179 const StateChangeHandler &getOnStateChange(void) const noexcept;
180
190
196 ecs::Entity::Identifier getTrigger(void) const noexcept;
197
207
213 const std::vector<ecs::Entity::Identifier> &
214 getActionButtons(void) const noexcept;
215
224 const std::vector<ecs::Entity::Identifier> &buttons);
225 };
226
227} // namespace guillaume::components
FloatingActionButtonMenu & setActions(std::vector< Action > actions)
Replace the actions of the menu.
const std::vector< Action > & getActions(void) const noexcept
Get the actions of the menu.
static constexpr float Spacing
Gap between the buttons of the column, in dp.
const std::vector< ecs::Entity::Identifier > & getActionButtons(void) const noexcept
Get the child entities of the action buttons.
bool isOpen(void) const noexcept
Check whether the menu is open.
FloatingActionButtonMenu & setOpen(bool open)
Store whether the menu is open.
FloatingActionButtonMenu & setAccessibilityLabel(const std::string &label)
Set the accessibility label of the trigger button.
const StateChangeHandler & getOnStateChange(void) const noexcept
Get the callback run when the menu opens or closes.
FloatingActionButtonMenu(void)=default
Create the state of a closed menu with no action.
~FloatingActionButtonMenu(void)=default
Default destructor.
ecs::Entity::Identifier getTrigger(void) const noexcept
Get the child entity of the trigger button.
const std::string & getIconGlyphName(void) const noexcept
Get the icon the trigger shows while the menu is closed.
FloatingActionButtonMenu & setTrigger(ecs::Entity::Identifier identifier)
Record which child entity is the trigger button.
FloatingActionButtonMenu & setActionButtons(const std::vector< ecs::Entity::Identifier > &buttons)
Record which child entities are the action buttons.
FloatingActionButtonMenu & setIconGlyphName(const std::string &name)
Set the icon the trigger shows while the menu is closed.
FloatingActionButtonMenu & setOnStateChange(StateChangeHandler handler)
Set the callback run when the menu opens or closes.
const std::string & getAccessibilityLabel(void) const noexcept
Get the accessibility label of the trigger button.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.
One entry of the menu: what its button shows and does.
std::function< void(void)> onClick
Called when the action button is clicked.