23#include "guillaume/systems/navigation_bar.hpp"
27#include "guillaume/components/accessibility.hpp"
28#include "guillaume/components/bound.hpp"
29#include "guillaume/components/color.hpp"
30#include "guillaume/components/layout.hpp"
31#include "guillaume/components/navigation_bar_destination.hpp"
32#include "guillaume/components/selection.hpp"
34#include "guillaume/systems/layout.hpp"
35#include "guillaume/systems/navigation_bar_destination.hpp"
36#include "guillaume/systems/selection.hpp"
37#include "guillaume/theme.hpp"
51 bool isDestination(
const ecs::ComponentRegistry ®istry,
54 return registry.hasComponent<components::NavigationBarDestination>(
71 .setAllowEmpty(
false);
82 const auto &destinations =
85 .getDestinationEntities();
87 for (std::size_t index = 0; index < destinations.size(); ++index) {
88 const auto destination = destinations[index];
89 if (!isDestination(componentRegistry, destination)) {
95 .setOnPress([registry, identifier, index]() {
96 press(*registry, identifier, index);
103 .setOnSelectionChangedHandler([registry, identifier,
104 index](
bool selected) {
117 const auto &destinations =
120 .getDestinationEntities();
122 for (std::size_t index = 0; index < destinations.size(); ++index) {
124 destinations[index])) {
139 if (index >= destinations.size()) {
145 bar.setUpdatingSelection(
true);
147 destinations[index]);
148 bar.setUpdatingSelection(
false);
150 apply(componentRegistry, entityIdentifier);
157 if (componentRegistry
159 .isUpdatingSelection()) {
163 select(componentRegistry, entityIdentifier, index);
173 .getDestinationEntities()
179 const auto onTabPress =
189 select(componentRegistry, entityIdentifier, index);
191 const auto onIndexChange =
195 if (changed && onIndexChange) {
196 onIndexChange(index);
203 std::size_t index,
const std::string &badge)
209 bar.setDestinationBadge(index, badge);
210 if (index < bar.getDestinations().size() && index < destinations.size()
211 && isDestination(componentRegistry, destinations[index])) {
213 destinations[index], badge);
224 const bool showAllLabels = bar.getVariant() == Variant::WithLabels;
233 const float width = layout.hasFixedWidth()
234 ? layout.getFixedWidth()
238 const float destinationWidth = destinations.empty()
241 (width - 2.0f * padding)
242 /
static_cast<float>(destinations.size()));
243 const float destinationHeight =
246 for (
const auto destination: destinations) {
247 if (!isDestination(componentRegistry, destination)) {
252 .setFixedWidth(destinationWidth)
257 .setShowLabel(showAllLabels
259 componentRegistry, destination));
265 layout.setChildren(destinations);
266 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
269 for (
const auto destination: destinations) {
270 if (isDestination(componentRegistry, destination)) {
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setFocusable(bool focusable)
Include the entity in the Tab traversal or leave it out.
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
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,...
float getPadding(void) const
Get the inset between the container's edges and its children.
Layout & setFixedHeight(float height)
Force the container height instead of wrapping the children.
State of one destination of a navigation bar: an icon in a pill, a label under it and an optional bad...
State of a navigation bar: the bottom strip of three to five destinations that switches between the t...
static constexpr float Height
Height of the bar, in dp.
Variant
Whether every destination shows its label (WithLabels) or only the selected one does (WithoutLabels).
const std::vector< ecs::Entity::Identifier > & getDestinationEntities(void) const noexcept
Get the destination children.
Selected/unselected flag of an entity, with a callback run when it changes.
Marks an entity whose Selectable children are mutually exclusive, and remembers which one is selected...
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.
ComponentType & addComponent(const Entity::Identifier &entityIdentifier, Args &&...args)
Construct a component for an entity, replacing the one it already has, if any.
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.
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 apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one destination from its selection and interaction state, then arrange it.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one navigation bar; called by the frame loop.
static void setBadge(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index, const std::string &badge)
Set the badge of a destination and restyle that destination.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Connect a navigation bar to its destinations.
static void press(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Activate a destination as a press on it would.
static std::size_t selectedIndex(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the index of the selected destination.
NavigationBar(void)
Create the system in the Layout phase.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Color the bar, size and style its destinations and place them in a row.
static void select(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Select a destination from code.
static void destinationSelected(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
React to a destination that became selected without going through the bar.
static ecs::Entity::Identifier select(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &groupIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, ecs::Entity::Identifier selectedIdentifier)
Select one child of a group, at once.
State. Every class here is plain data attached to an entity.
@ TabList
Group of navigation destinations.
The entity-component-system core, independent of any 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.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.