23#include "guillaume/systems/navigation_drawer_destination.hpp"
27#include "guillaume/components/accessibility.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/selection.hpp"
33#include "guillaume/components/style_state.hpp"
34#include "guillaume/components/transform.hpp"
37#include "guillaume/systems/layout.hpp"
38#include "guillaume/theme.hpp"
54 void colorChild(ecs::ComponentRegistry ®istry,
56 const utility::graphic::Color32Bit &color)
58 if (registry.hasComponent<components::Color>(child)) {
59 registry.getComponent<components::Color>(child).setColor(color);
69 void arrangeGroup(ecs::ComponentRegistry ®istry,
72 if (!registry.hasComponent<components::Layout>(group)
73 || !registry.hasComponent<components::Transform>(group)
74 || !registry.hasComponent<components::Bound>(group)) {
80 registry.getComponent<components::Layout>(group).getChildren(),
99 componentRegistry, identifier,
101 [registry, identifier]() {
102 press(*registry, identifier);
104 [registry, identifier]() {
105 apply(*registry, identifier);
124 return componentRegistry
139 apply(componentRegistry, entityIdentifier);
146 if (
isDisabled(componentRegistry, entityIdentifier)) {
166 const auto &destination =
178 .setMainAxisAlignment(
180 .setCrossAxisAlignment(
188 .setMainAxisAlignment(
189 destination.getRight().empty()
192 .setCrossAxisAlignment(
208 .setEnabled(!destination.isDisabled());
211 const bool selected =
isSelected(componentRegistry, entityIdentifier);
212 const bool disabled =
isDisabled(componentRegistry, entityIdentifier);
213 const auto pill = selected && !disabled
216 const auto content = disabled
218 : (selected ?
schemeColor(SchemeColorRole::OnSecondaryContainer)
221 componentRegistry, entityIdentifier, pill, content);
227 colorChild(componentRegistry, destination.getLead(),
230 colorChild(componentRegistry, destination.getIconEntity(), content);
231 colorChild(componentRegistry, destination.getLabelEntity(), content);
232 colorChild(componentRegistry, destination.getRightEntity(), content);
238 .setLabel(destination.getLabel())
242 arrange(componentRegistry, entityIdentifier);
249 const auto &destination =
253 const auto lead = destination.
getLead();
254 std::vector<ecs::Entity::Identifier> children;
258 children.push_back(lead);
260 if (destination.isCollapsed()
262 children.push_back(destination.getLabelEntity());
265 children.push_back(destination.getRightEntity());
273 arrangeGroup(componentRegistry, lead);
274 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
276 arrangeGroup(componentRegistry, lead);
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setSelected(bool selected)
Set whether the entity is the selected one of its group.
Corner radii and outline stroke of a rectangular entity.
Borders & setColor(const utility::graphic::Color32Bit &color)
Set the color of the stroke.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
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.
@ Center
Packed in the middle.
@ Start
Packed at the left (row) or top (column).
@ Vertical
Column: children placed top to bottom.
@ Horizontal
Row: children placed left to right.
State of one destination of a navigation drawer: an icon, a label and an optional text at the trailin...
ecs::Entity::Identifier getLead(void) const noexcept
Get the leading child of the destination.
static constexpr float Height
Height of a regular destination, in dp.
bool isCollapsed(void) const noexcept
Tell which rendering the destination uses.
Selected/unselected flag of an entity, with a callback run when it changes.
The interaction state of an entity in one place: enabled or disabled, and whether it is hovered,...
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...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
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.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make a destination pressable.
static void press(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Activate the destination as a press on it would.
static bool isDisabled(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination ignores input.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one destination from its selection, enabled and interaction state, then arrange it.
static void arrange(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Place the children of one destination without restyling it.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one destination; called by the frame loop.
static void setDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool disabled)
Enable or disable the destination and restyle it.
NavigationDrawerDestination(void)
Create the system in the Layout phase.
static bool isSelected(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination is the selected one.
static constexpr float get(unsigned int steps)
Get a spacing as a number of grid units.
State. Every class here is plain data attached to an entity.
@ Button
Pressable button.
The entity-component-system core, independent of any widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
Rules. Every class here runs each frame on the entities that have the components it declares.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ Full
Fully rounded (buttons, icon buttons, badges).
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Helpers of the namespace systems::interaction: what "pressable" means for a widget,...
bool isEnabled(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier)
Whether an entity accepts input.
void makeInteractive(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier, components::AccessibilityRole role, std::function< void(void)> onPress, std::function< void(void)> onStateChange={})
Make an entity hoverable, pressable and focusable.
utility::graphic::Color32Bit stateLayerColor(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier, const utility::graphic::Color32Bit &base, const utility::graphic::Color32Bit &content)
Container color of a widget in its current input state.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.