23#include "guillaume/entities/snackbar.hpp"
29#include "guillaume/entities/content_helpers.hpp"
30#include "guillaume/entities/builder_base.hpp"
32#include "guillaume/systems/snackbar.hpp"
33#include "guillaume/theme.hpp"
47 _variant, _message, _action);
48 entity->setDuration(_duration);
49 entity->setOnDismiss(_onDismiss);
50 entity->setOnAction(_onAction);
51 entity->setVisible(_visible);
58 _variant = Variant::SingleLine;
67 _config.mainAxisAlignment =
69 _config.crossAxisAlignment =
71 _config.padding = 16.0f;
72 _config.spacing = 8.0f;
73 _config.setFixedWidth(344.0f);
117 _onDismiss = std::move(onDismiss);
124 _onAction = std::move(onAction);
129 std::shared_ptr<ecs::Entity> parent,
Variant variant,
130 const std::string &message,
const std::string &action)
133 .withMessage(message)
135 .registerEntity(parent);
140 const std::string &message,
const std::string &action)
256 void Snackbar::build(
void)
262 void Snackbar::buildContent(
void)
265 if (weak_from_this().expired()) {
275 buildText(registry, *
this, shared_from_this(),
278 if (message !=
nullptr) {
279 snackbar.setMessageEntity(message->getIdentifier());
283 if (snackbar.getVariant() == Variant::WithAction
286 buildText(registry, *
this, shared_from_this(),
289 if (action !=
nullptr) {
290 snackbar.setActionEntity(action->getIdentifier());
296 std::vector<std::shared_ptr<ecs::Entity>> children;
298 children.push_back(std::move(message));
301 children.push_back(std::move(action));
@ Horizontal
Row: children placed left to right.
State of a snackbar: a short message at the bottom of the screen, with an optional action,...
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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
std::shared_ptr< EntityType > getEntity(Entity::Identifier identifier)
Find an entity owned directly by this registry, by identifier.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
ComponentRegistry & getComponentRegistry(void)
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Configures a Snackbar, then builds it and registers it in the entity registry given at construction.
Builder & withOnAction(std::function< void(void)> onAction)
Set the handler called when the action is pressed (Paper action.onPress).
Builder & withAction(const std::string &action)
Set the label of the action.
Builder & withVariant(Variant variant)
Set the snackbar variant.
Builder & withMessage(const std::string &message)
Set the message.
Builder & withDuration(float seconds)
Set how long the snackbar stays shown (Paper duration).
Builder & withPose(const utility::graphic::PoseF &pose)
Set the pose the snackbar is created with.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Builder & withOnDismiss(std::function< void(void)> onDismiss)
Set the handler called when the snackbar dismisses itself (see Snackbar::setOnDismiss()).
void reset(void) override
Restore the defaults: SingleLine variant, no message, no action label, shown, DurationMedium (7 secon...
std::shared_ptr< Snackbar > buildEntity(void) override
Build a snackbar and its children from the current configuration, without registering it or setting i...
std::shared_ptr< Snackbar > makeSnackbar(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &message, const std::string &action="")
Build a snackbar, register it under parent and reset the builder.
Builder & withVisible(bool visible)
Choose whether the snackbar is shown once built.
bool isVisible(void) const
Check whether the snackbar is shown.
float getDuration(void) const
Get how long the snackbar stays shown.
Snackbar & setVisible(bool visible)
Show or hide the snackbar (Paper visible).
Snackbar & show(void)
Show the snackbar; same as setVisible(true).
Snackbar & pressAction(void)
Activate the action as a press on its label would: call the action handler, then hide the snackbar an...
Snackbar & setDuration(float seconds)
Set how long the snackbar stays shown (Paper duration).
Snackbar & setOnAction(std::function< void(void)> onAction)
Set the handler called when the action is pressed (Paper action.onPress).
static std::shared_ptr< Snackbar > create(Arguments &&...arguments)
Create a snackbar and its children, without registering it in an entity registry.
components::Snackbar::Variant Variant
Look of the snackbar: SingleLine, MultiLine or WithAction.
Snackbar & hide(void)
Hide the snackbar without calling the dismiss handler; same as setVisible(false).
Snackbar & setMessage(const std::string &message)
Change the message text.
std::shared_ptr< Text > getActionEntity(void) const
Get the text entity that shows the action label.
Snackbar & setVariant(Variant variant)
Change the snackbar variant.
Variant getVariant(void) const
Get the snackbar variant.
Snackbar & setOnDismiss(std::function< void(void)> onDismiss)
Set the handler called when the snackbar dismisses itself (Paper onDismiss).
static constexpr float DurationMedium
Default display time: 7 seconds (Paper Snackbar.DURATION_MEDIUM).
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
static void pressAction(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Activate the action as a press on it would.
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().
Makes the color helpers callable from guillaume::entities without qualification.
State. Every class here is plain data attached to an entity.
Widgets: the classes used to create entities with the right components and children.
std::shared_ptr< Text > buildText(ecs::ComponentRegistry ®istry, ecs::EntityRegistry &entityRegistry, std::shared_ptr< ecs::Entity > parent, const std::string &content, float fontSize, const utility::graphic::Color32Bit &color)
Create a Text of a given font size as a child of a widget, or nothing when there is no content.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ LabelLarge
14 / 20, medium weight.
@ BodyMedium
14 / 20, regular.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...