23#include "guillaume/systems/floating_action_button_menu.hpp"
28#include "guillaume/components/accessibility.hpp"
29#include "guillaume/components/button.hpp"
30#include "guillaume/components/layout.hpp"
31#include "guillaume/systems/button.hpp"
32#include "guillaume/systems/layout.hpp"
44 bool isButton(
const ecs::ComponentRegistry ®istry,
77 if (isButton(componentRegistry, trigger)) {
79 .setOnClick([registry, identifier]() {
80 toggle(*registry, identifier);
86 .setLabel(menu.getAccessibilityLabel());
89 const auto &actions = menu.getActions();
90 const auto &buttons = menu.getActionButtons();
91 for (std::size_t index = 0;
92 index < buttons.size() && index < actions.size(); ++index) {
93 if (isButton(componentRegistry, buttons[index])) {
96 .setOnClick(actions[index].onClick);
101 void FloatingActionButtonMenu::setOpen(
105 auto &menu = componentRegistry
109 if (menu.isOpen() ==
open) {
113 apply(componentRegistry, entityIdentifier);
116 const auto onStateChange = menu.getOnStateChange();
126 setOpen(componentRegistry, entityIdentifier,
true);
133 setOpen(componentRegistry, entityIdentifier,
false);
140 setOpen(componentRegistry, entityIdentifier,
155 const bool open = menu.isOpen();
156 const auto trigger = menu.getTrigger();
157 std::vector<ecs::Entity::Identifier> children;
161 for (
const auto action: menu.getActionButtons()) {
162 if (!isButton(componentRegistry, action)) {
174 if (button.isVisible() !=
open) {
175 button.setVisible(
open);
179 children.push_back(action);
183 if (isButton(componentRegistry, trigger)) {
186 const std::string icon =
191 if (button.getIconGlyphName() != icon) {
192 button.setIconGlyphName(icon);
195 children.push_back(trigger);
203 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
How a container arranges its children: in a row or a column, with which alignment,...
Layout & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
Layout & setPadding(float padding)
Set the inset between the container's edges and its children.
Layout & setMainAxisAlignment(MainAxisAlignment alignment)
Set where the children go along the main axis.
Layout & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set where each child goes along the cross axis.
@ End
Packed at the right (row) or bottom (column).
@ Vertical
Column: children placed top to bottom.
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
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.
bool hasComponent(const Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component of a given type.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
SystemFiller(Phase phase)
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
Arranges the children of a container in a row or a column and sizes the container around them.
static void apply(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, std::uint32_t layer=0)
Arrange children inside a container and size the container.
static std::uint32_t layerOf(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &identifier)
Get the layer of an entity: its depth in the entity tree.
State. Every class here is plain data attached to an entity.
@ Button
Pressable button.
The entity-component-system core, independent of any widget.
Rules. Every class here runs each frame on the entities that have the components it declares.