23#include "guillaume/systems/dialog.hpp"
28#include "guillaume/components/accessibility.hpp"
29#include "guillaume/components/borders.hpp"
30#include "guillaume/components/bound.hpp"
31#include "guillaume/components/color.hpp"
32#include "guillaume/components/elevation.hpp"
33#include "guillaume/components/layout.hpp"
34#include "guillaume/components/overlay.hpp"
35#include "guillaume/components/text.hpp"
36#include "guillaume/components/transform.hpp"
38#include "guillaume/systems/backdrop.hpp"
39#include "guillaume/systems/layout.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 writeChild(ecs::ComponentRegistry ®istry,
71 const std::string &content)
120 apply(componentRegistry, entityIdentifier);
128 apply(componentRegistry, entityIdentifier);
134 if (!componentRegistry
139 hide(componentRegistry, entityIdentifier);
142 const auto onDismiss =
145 .getOnDismissHandler();
155 const auto &actions =
159 if (index >= actions.size()) {
164 const auto onPress = actions[index].onPress;
175 const bool fullScreen = dialog.
getVariant() == Variant::FullScreen;
176 const auto icon = dialog.getIconEntity();
177 const auto title = dialog.getTitleEntity();
178 const auto message = dialog.getMessageEntity();
181 std::vector<ecs::Entity::Identifier> children;
182 for (
const auto child:
183 { icon, title, message, dialog.getActionRow() }) {
185 children.push_back(child);
204 layout.clearFixedHeight();
217 .setLabel(dialog.getTitle());
225 colorChild(componentRegistry, icon,
227 writeChild(componentRegistry, title, dialog.getTitle());
228 colorChild(componentRegistry, title,
232 .setLabel(dialog.getTitle());
234 writeChild(componentRegistry, message, dialog.getMessage());
235 colorChild(componentRegistry, message,
238 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
241 const auto backdrop = dialog.getBackdrop();
245 overlay.isVisible() && !fullScreen);
250 componentRegistry, backdrop,
254 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.
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.
State of a dialog: a modal panel with an optional icon, a title, a message and a row of text buttons.
static constexpr float FullScreenHeight
Height of a full-screen dialog, in dp.
Variant getVariant(void) const noexcept
Get the kind of dialog.
static constexpr float Width
Width of the dialog panel, in dp.
ecs::Entity::Identifier getTitleEntity(void) const noexcept
Get the child that draws the title.
Soft shadow drawn around an elevated surface.
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 & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
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 & 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.
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.
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.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one dialog, arrange its children and place its backdrop.
static void dismiss(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Close the dialog as the user would with Escape or a click outside.
static void hide(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Hide the dialog and its backdrop without telling anyone.
static constexpr float Padding
Space between the edge of the panel and its content: 24 dp.
static void pressAction(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Activate an action as a press on its button would.
static void installTitle(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Expose the title child to assistive technology as a header.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Give a dialog panel its accessibility semantics.
static constexpr float Spacing
Gap between two stacked sections of the dialog: 16 dp.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one dialog; called by the frame loop.
static void show(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Show the dialog and its backdrop.
Dialog(void)
Create the system in the Layout phase.
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.
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.
@ Level3
Third raised level.
@ ExtraLarge
28 dp (dialogs, search bars, sheets).
@ None
0 dp: square corners.
utility::graphic::Color32Bit getElevatedSurfaceColor(theme::ElevationLevel level)
Get the background color of a surface raised to an elevation level.
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.