23#include "guillaume/systems/navigation_bar_destination.hpp"
27#include "guillaume/components/accessibility.hpp"
28#include "guillaume/components/badge.hpp"
29#include "guillaume/components/borders.hpp"
30#include "guillaume/components/bound.hpp"
31#include "guillaume/components/color.hpp"
32#include "guillaume/components/glyph.hpp"
33#include "guillaume/components/layout.hpp"
34#include "guillaume/components/selection.hpp"
35#include "guillaume/components/transform.hpp"
39#include "guillaume/systems/badge.hpp"
40#include "guillaume/systems/layout.hpp"
41#include "guillaume/theme.hpp"
56 void colorChild(ecs::ComponentRegistry ®istry,
58 const utility::graphic::Color32Bit &color)
60 if (registry.hasComponent<components::Color>(child)) {
61 registry.getComponent<components::Color>(child).setColor(color);
71 void arrangeGroup(ecs::ComponentRegistry ®istry,
74 if (!registry.hasComponent<components::Layout>(group)
75 || !registry.hasComponent<components::Transform>(group)
76 || !registry.hasComponent<components::Bound>(group)) {
82 registry.getComponent<components::Layout>(group).getChildren(),
93 void styleBadge(ecs::ComponentRegistry ®istry,
96 if (!registry.hasComponent<components::Badge>(badge)) {
100 auto &config = registry.getComponent<components::Badge>(badge);
101 const auto variant = label.empty()
105 if (config.getVariant() == variant && config.getLabel() == label) {
111 config.setVariant(variant).setLabel(label);
131 [registry, identifier]() {
132 press(*registry, identifier);
134 [registry, identifier]() {
135 apply(*registry, identifier);
169 const std::string &badge)
175 apply(componentRegistry, entityIdentifier);
182 const auto &destination =
186 const bool selected =
isSelected(componentRegistry, entityIdentifier);
201 const auto pillColor = selected
204 const auto iconColor = selected
205 ?
schemeColor(SchemeColorRole::OnSecondaryContainer)
207 const auto labelColor = selected
212 colorChild(componentRegistry, destination.getIndicator(),
214 entityIdentifier, pillColor,
217 const auto icon = destination.getIconEntity();
220 selected && !destination.getFocusedIcon().empty()
221 ? destination.getFocusedIcon()
222 : destination.getIcon());
224 colorChild(componentRegistry, icon, iconColor);
227 colorChild(componentRegistry, destination.getLabelEntity(),
228 destination.isLabelShown() ? labelColor
231 styleBadge(componentRegistry, destination.getBadgeEntity(),
232 destination.getBadge());
238 .setLabel(destination.getLabel())
242 arrange(componentRegistry, entityIdentifier);
249 const auto &destination =
254 const auto badge = destination.getBadgeEntity();
255 std::vector<ecs::Entity::Identifier> children;
257 for (
const auto child: { indicator, destination.
getLabelEntity() }) {
259 children.push_back(child);
268 arrangeGroup(componentRegistry, indicator);
269 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
271 arrangeGroup(componentRegistry, indicator);
277 componentRegistry, indicator, badge,
278 utility::graphic::PositionF(
283 arrangeGroup(componentRegistry, badge);
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.
@ Large
20 dp high badge with a label (the default).
@ Dot
6 dp dot without label.
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.
An icon: one glyph of the Material Symbols font, chosen by name, at a given size.
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.
@ Center
Packed in the middle.
@ Vertical
Column: children placed top to bottom.
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
State of one destination of a navigation bar: an icon in a pill, a label under it and an optional bad...
ecs::Entity::Identifier getIndicator(void) const noexcept
Get the pill drawn behind the icon of the selected destination.
static constexpr float BadgeOffsetY
Vertical offset of the badge from the indicator origin, in dp.
static constexpr float BadgeOffsetX
ecs::Entity::Identifier getLabelEntity(void) const noexcept
Get the child that draws the label.
Selected/unselected flag of an entity, with a callback run when it changes.
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...
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Size and color one badge and its label.
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 bool isSelected(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination is the selected one.
static void arrange(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Place the children of one destination without restyling it.
static void setBadge(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, const std::string &badge)
Set the badge label and restyle the destination.
static void press(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Activate the destination as a press on it would.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one destination from its selection and interaction state, then arrange it.
NavigationBarDestination(void)
Create the system in the Layout phase.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one destination; called by the frame loop.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make a destination pressable.
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.
@ Tab
Navigation destination.
The entity-component-system core, independent of any widget.
void placeChild(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const ecs::Entity::Identifier &childIdentifier, const utility::graphic::PositionF &offset, std::uint32_t parentLayer)
Place a child at an offset from the position of its parent.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
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 schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ None
0 dp: square corners.
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,...
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.
Placement helpers for the children systems::Layout does not arrange.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.