23#include "guillaume/systems/snackbar.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/elevation.hpp"
32#include "guillaume/components/layout.hpp"
33#include "guillaume/components/overlay.hpp"
34#include "guillaume/components/text.hpp"
35#include "guillaume/components/transform.hpp"
38#include "guillaume/systems/layout.hpp"
39#include "guillaume/theme.hpp"
50 constexpr float SingleLineHeight = 48.0f;
53 constexpr float MultiLineHeight = 68.0f;
61 void colorChild(ecs::ComponentRegistry ®istry,
63 const utility::graphic::Color32Bit &color)
65 if (registry.hasComponent<components::Color>(child)) {
66 registry.getComponent<components::Color>(child).setColor(color);
88 .setOnDismissHandler([registry, identifier]() {
101 const auto &snackbar =
111 [registry, identifier]() {
115 .setLabel(snackbar.getAction());
123 apply(componentRegistry, entityIdentifier);
131 apply(componentRegistry, entityIdentifier);
142 if (!snackbar.isVisible()) {
146 apply(componentRegistry, entityIdentifier);
149 const auto onDismiss = snackbar.getOnDismiss();
158 const auto &snackbar =
162 if (!snackbar.isVisible()) {
171 dismiss(componentRegistry, entityIdentifier);
177 const auto &snackbar =
180 const bool visible = snackbar.
isVisible();
181 const auto message = snackbar.getMessageEntity();
182 const auto action = snackbar.getActionEntity();
184 std::vector<ecs::Entity::Identifier> children;
186 children.push_back(message);
189 children.push_back(action);
209 .setColor(visible ?
schemeColor(SchemeColorRole::InverseSurface)
218 snackbar.getDuration());
219 if (overlay.isVisible() != visible) {
221 overlay.setElapsed(0.0f);
222 overlay.setVisible(visible);
227 .setLabel(snackbar.getMessage());
231 .setContent(snackbar.getMessage());
233 colorChild(componentRegistry, message,
234 visible ?
schemeColor(SchemeColorRole::InverseOnSurface)
236 colorChild(componentRegistry, action,
237 visible ?
schemeColor(SchemeColorRole::InversePrimary)
240 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setLiveRegion(LiveRegion liveRegion)
Set how urgently a change of the entity is announced.
Corner radii and outline stroke of a rectangular entity.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Soft shadow drawn around an elevated surface.
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 & 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.
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.
@ Horizontal
Row: children placed left to right.
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 & setAutoDismiss(float delay)
Set how long the overlay stays shown before it is dismissed by itself.
State of a snackbar: a short message at the bottom of the screen, with an optional action,...
const Handler & getOnAction(void) const noexcept
Get the callback run when the action is pressed.
ecs::Entity::Identifier getActionEntity(void) const noexcept
Get the pressable child that draws the action label.
bool isVisible(void) const noexcept
Tell whether the snackbar is shown.
Snackbar & setVisible(bool visible)
Record whether the snackbar is shown.
A run of text: its content, its font metrics and the position of the editing cursor.
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.
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 dismiss(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Close the snackbar as the timeout, Escape or its action would.
static void pressAction(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Activate the action as a press on it would.
Snackbar(void)
Create the system in the Layout phase.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Give a snackbar its accessibility semantics and connect its dismissal.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one snackbar and arrange its children.
static void show(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Show the snackbar and restart its auto-dismiss countdown.
static void hide(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Hide the snackbar without telling anyone.
static void installAction(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make the action child a button that calls pressAction().
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one snackbar; called by the frame loop.
State. Every class here is plain data attached to an entity.
@ Button
Pressable button.
@ Alert
Live announcement (snackbar).
@ Polite
Announced once the current speech is over.
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 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.
@ Level3
Third raised level.
@ Level0
Flat: no shadow, no tint.
@ ExtraSmall
4 dp (text fields, menus, snackbars).
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.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.