23#include "guillaume/systems/navigation_drawer.hpp"
25#include "guillaume/components/accessibility.hpp"
26#include "guillaume/components/borders.hpp"
27#include "guillaume/components/bound.hpp"
28#include "guillaume/components/color.hpp"
29#include "guillaume/components/layout.hpp"
30#include "guillaume/components/navigation_drawer_destination.hpp"
31#include "guillaume/components/overlay.hpp"
32#include "guillaume/components/selection.hpp"
33#include "guillaume/components/transform.hpp"
35#include "guillaume/systems/backdrop.hpp"
36#include "guillaume/systems/layout.hpp"
37#include "guillaume/systems/navigation_drawer_destination.hpp"
38#include "guillaume/systems/selection.hpp"
55 bool isDestination(
const ecs::ComponentRegistry ®istry,
59 .hasComponent<components::NavigationDrawerDestination>(
72 return variant == Variant::Collapsed
85 .setAllowEmpty(
false);
91 const auto §ions = drawer.getSectionEntities();
93 for (std::size_t index = 0; index < destinations.size(); ++index) {
94 const auto destination = destinations[index];
95 if (!isDestination(componentRegistry, destination)) {
102 .setOnPress([registry, identifier, index]() {
103 press(*registry, identifier, index);
110 .setOnSelectionChangedHandler([registry, identifier,
111 index](
bool selected) {
120 std::size_t section = 0;
121 for (
const auto &entry: drawer.getEntries()) {
122 if (section >= sections.size()) {
125 if (entry.kind != EntryKind::Section || entry.label.empty()) {
129 const auto header = sections[section++];
146 const auto &destinations =
149 .getDestinationEntities();
151 for (std::size_t index = 0; index < destinations.size(); ++index) {
153 destinations[index])) {
169 if (index >= destinations.size()) {
175 drawer.setUpdatingSelection(
true);
177 destinations[index]);
178 drawer.setUpdatingSelection(
false);
180 apply(componentRegistry, entityIdentifier);
187 const auto &destinations =
190 .getDestinationEntities();
192 for (std::size_t index = 0; index < destinations.size(); ++index) {
193 if (isDestination(componentRegistry, destinations[index])
195 componentRegistry, destinations[index])) {
196 select(componentRegistry, entityIdentifier, index);
201 apply(componentRegistry, entityIdentifier);
208 if (componentRegistry
210 .isUpdatingSelection()) {
214 select(componentRegistry, entityIdentifier, index);
222 const auto &destinations =
225 .getDestinationEntities();
227 if (index >= destinations.size()
228 || !isDestination(componentRegistry, destinations[index])
230 destinations[index])) {
236 select(componentRegistry, entityIdentifier, index);
239 const auto onIndexChange =
243 if (changed && onIndexChange) {
244 onIndexChange(index);
258 drawer.setDestinationDisabled(index, disabled);
259 if (index < destinations.size()
260 && isDestination(componentRegistry, destinations[index])) {
262 componentRegistry, destinations[index], disabled);
271 apply(componentRegistry, entityIdentifier);
279 apply(componentRegistry, entityIdentifier);
290 const bool collapsed = variant == Variant::Collapsed;
291 const bool modal = variant == Variant::Modal;
292 const float width =
widthOf(variant);
293 const auto &destinations = drawer.getDestinationEntities();
312 .setTopLeftRadius(0.0f)
318 .setColor(
schemeColor(modal ? SchemeColorRole::SurfaceContainerLow
319 : SchemeColorRole::Surface));
321 for (
const auto destination: destinations) {
322 if (!isDestination(componentRegistry, destination)) {
327 .setFixedWidth(width - 2.0f *
Padding);
333 layout.setChildren(drawer.getEntryEntities());
334 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
337 for (
const auto destination: destinations) {
338 if (isDestination(componentRegistry, destination)) {
350 const auto backdrop = drawer.getBackdrop();
354 modal && overlay.isVisible());
359 componentRegistry, backdrop,
363 bound.getWidth(), bound.getHeight());
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.
Accessibility & setLabel(const std::string &label)
Set the name announced for the entity, such as "Close".
Corner radii and outline stroke of a rectangular entity.
Borders & setBottomLeftRadius(BorderRadius radius)
Set the radius of the bottom-left corner.
Borders & setTopRightRadius(BorderRadius radius)
Set the radius of the top-right corner.
Borders & setBottomRightRadius(BorderRadius radius)
Set the radius of the bottom-right corner.
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,...
Layout & setFixedWidth(float width)
Force the container width instead of wrapping the children.
Layout & setAxis(Axis axis)
Choose between a row and a column.
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.
@ Start
At the top (row) or left (column).
Layout & setFixedHeight(float height)
Force the container height instead of wrapping the children.
Layout & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set where each child goes along the cross axis.
@ Start
Packed at the left (row) or top (column).
@ 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 drawer: an icon, a label and an optional text at the trailin...
State of a navigation drawer: the side sheet that lists the destinations of an app,...
Variant
How the drawer is presented.
static constexpr float Width
Width of a standard or modal drawer, in dp.
static constexpr float CollapsedWidth
Width of a collapsed drawer (rail), in dp.
Variant getVariant(void) const noexcept
Get how the drawer is presented.
const std::vector< ecs::Entity::Identifier > & getDestinationEntities(void) const noexcept
Get the destination children.
static constexpr float Height
Height of the drawer, in dp.
EntryKind
What a drawer entry is.
Marks an entity as something shown temporarily above the rest of the interface (a dialog,...
Overlay & setModal(bool modal)
Declare the overlay modal (it must be answered before the rest of the interface is used) or not.
Overlay & setDismissOnOutsideClick(bool dismiss)
Choose whether a click outside the overlay dismisses it.
Overlay & setDismissOnEscape(bool dismiss)
Choose whether the Escape key dismisses the overlay.
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...
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 follow(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, const utility::graphic::PoseF &ownerPose, float ownerWidth, float ownerHeight)
Center a backdrop on its owner and place it half a layer behind it.
static void setVisible(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
Show or hide a backdrop.
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 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.
static void setDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool disabled)
Enable or disable the destination and restyle it.
static bool isSelected(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination is the selected one.
static float widthOf(components::NavigationDrawer::Variant variant)
Get the drawer width of a variant, in dp.
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 drawer.
static constexpr float Spacing
Gap between two stacked entries: 4 dp.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Shape and color the drawer, style its destinations, stack its entries and place its backdrop.
static void select(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Select a destination from code.
NavigationDrawer(void)
Create the system in the Layout phase.
static void hide(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Hide the drawer and its backdrop.
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 void setDestinationDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index, bool disabled)
Enable or disable one destination and restyle it.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one navigation drawer; called by the frame loop.
static void show(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Show the drawer, and its backdrop when it is modal.
static void selectFirstEnabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Select the first destination that is not disabled, then restyle.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Connect a navigation drawer to its destinations and section headers.
static constexpr float Padding
Space between the edge of the drawer and its entries: 12 dp.
static std::size_t selectedIndex(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the index of the selected destination.
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.
@ Header
Heading (app bar title, list subheader).
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.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ Large
16 dp (FABs, drawers).
@ None
0 dp: square corners.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.