26#include "guillaume/entities/menu.hpp"
28#include "guillaume/components/borders.hpp"
29#include "guillaume/components/bound.hpp"
30#include "guillaume/components/color.hpp"
31#include "guillaume/components/layout.hpp"
32#include "guillaume/components/transform.hpp"
33#include "guillaume/ecs/parent_entity_filler.hpp"
34#include "guillaume/entities/builder_base.hpp"
35#include "guillaume/entities/content_helpers.hpp"
37#include "guillaume/systems/menu.hpp"
38#include "guillaume/theme.hpp"
45 constexpr float MenuIconSize = 24.0f;
54 public ecs::ParentEntityFiller<
55 components::Layout, components::Transform, components::Bound,
56 components::Color, components::Borders>
63 explicit MenuRow(ecs::ComponentRegistry ®istry)
64 : ecs::ParentEntityFiller<components::
Layout,
65 components::Transform,
66 components::Bound, components::Color,
67 components::Borders>(registry)
74 ~MenuRow(
void)
override =
default;
95 _variant = Variant::Dropdown;
99 _config.mainAxisAlignment =
101 _config.crossAxisAlignment =
103 _config.padding = 0.0f;
104 _config.spacing = 0.0f;
122 const std::string &leadingIcon)
127 _items.push_back(item);
133 _items.push_back(item);
137 std::shared_ptr<Menu>
139 Variant variant,
const std::vector<Item> &items)
143 for (
const auto &item: items) {
151 Variant variant,
const std::vector<Item> &items)
221 return index < rows.size() ? rows[index].view
268 .setOnDismissHandler(std::move(onDismiss));
312 void Menu::build(
void)
318 void Menu::buildItems(
void)
321 if (weak_from_this().expired()) {
328 if (!menu.isRowsDirty()) {
336 std::vector<components::Menu::Row> rows;
339 for (
const auto &item: menu.getItems()) {
340 const auto view = std::make_shared<MenuRow>(registry);
341 components::Menu::Row row;
343 view->setParent(shared_from_this());
345 row.view = view->getIdentifier();
348 registry, *
this, view, item.leadingIcon, MenuIconSize,
350 row.content.push_back(icon->getIdentifier());
351 row.icons.push_back(icon->getIdentifier());
353 if (
const auto label =
354 buildText(registry, *
this, view, item.label,
357 row.content.push_back(label->getIdentifier());
358 row.label = label->getIdentifier();
361 registry, *
this, view, item.trailingIcon, MenuIconSize,
363 row.content.push_back(icon->getIdentifier());
364 row.icons.push_back(icon->getIdentifier());
368 children.push_back(view);
371 menu.setRows(rows).setRowsDirty(
false);
372 for (std::size_t index = 0; index < rows.size(); ++index) {
@ Start
At the top (row) or left (column).
@ Start
Packed at the left (row) or top (column).
@ Vertical
Column: children placed top to bottom.
Marks an entity as something shown temporarily above the rest of the interface (a dialog,...
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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
void addEntity(std::shared_ptr< Entity > entity)
Make this registry own an entity, so that it stays alive and systems visit it.
void clearEntities(void)
Remove every entity owned by this registry, with everything they own and all their components.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
ComponentRegistry & getComponentRegistry(void)
std::shared_ptr< Menu > registerEntity(std::shared_ptr< ecs::Entity > parent)
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
std::vector< std::shared_ptr< ecs::Entity > > Children
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
Makes the color helpers callable from guillaume::entities without qualification.
State. Every class here is plain data attached to an entity.
Widgets: the classes used to create entities with the right components and children.
std::shared_ptr< Text > buildText(ecs::ComponentRegistry ®istry, ecs::EntityRegistry &entityRegistry, std::shared_ptr< ecs::Entity > parent, const std::string &content, float fontSize, const utility::graphic::Color32Bit &color)
Create a Text of a given font size as a child of a widget, or nothing when there is no content.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
std::shared_ptr< Icon > buildIcon(ecs::ComponentRegistry ®istry, ecs::EntityRegistry &entityRegistry, std::shared_ptr< ecs::Entity > parent, const std::string &glyphName, float fontSize, const utility::graphic::Color32Bit &color, components::Glyph::Style style=components::Glyph::Style::Outlined)
Create an Icon as a child of a widget, or nothing when there is no glyph to show.
@ BodyLarge
16 / 24, regular.
@ ExtraSmall
4 dp (text fields, menus, snackbars).
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...