23#include "guillaume/entities/loading_indicator.hpp"
29#include "guillaume/ecs/entity_filler.hpp"
31#include "guillaume/components/animation.hpp"
32#include "guillaume/components/arc.hpp"
33#include "guillaume/components/borders.hpp"
34#include "guillaume/components/bound.hpp"
35#include "guillaume/components/color.hpp"
36#include "guillaume/components/transform.hpp"
38#include "guillaume/entities/builder_base.hpp"
40#include "guillaume/systems/loading_indicator.hpp"
41#include "guillaume/theme.hpp"
47 constexpr float LinearHeight =
51 constexpr float CircularSize =
58 public ecs::EntityFiller<components::Transform, components::Bound,
59 components::Color, components::Borders,
60 components::Animation>
67 explicit LinearBar(ecs::ComponentRegistry ®istry)
68 : ecs::EntityFiller<components::Transform, components::Bound,
69 components::Color, components::Borders,
70 components::Animation>(registry)
77 ~LinearBar(
void)
override =
default;
84 public ecs::EntityFiller<components::Transform, components::Bound,
85 components::Color, components::Arc,
86 components::Animation>
93 explicit RotatingArc(ecs::ComponentRegistry ®istry)
94 : ecs::EntityFiller<components::Transform, components::Bound,
95 components::Color, components::Arc,
96 components::Animation>(registry)
103 ~RotatingArc(
void)
override =
default;
115 std::shared_ptr<LoadingIndicator>
118 if (_variant == Variant::Circular) {
119 _config.setFixedWidth(_size).setFixedHeight(_size);
120 _config.borderRadius = _size * 0.5f;
122 _config.setFixedWidth(LinearWidth).setFixedHeight(LinearHeight);
123 _config.borderRadius = LinearRadius;
134 _variant = Variant::Circular;
135 _size = CircularSize;
137 _config.borderRadius = LinearRadius;
139 _config.mainAxisAlignment =
141 _config.crossAxisAlignment =
143 _config.padding = 0.0f;
144 _config.spacing = 0.0f;
145 _config.setFixedWidth(LinearWidth);
146 _config.setFixedHeight(LinearHeight);
169 std::shared_ptr<LoadingIndicator>
171 std::shared_ptr<ecs::Entity> parent,
Variant variant)
173 return withVariant(variant).registerEntity(parent);
180 components::LoadingIndicator>(registry, config)
219 const utility::graphic::Color32Bit &color)
238 throw std::invalid_argument(
239 "Loading indicator size must be positive");
247 if (state.getVariant() == Variant::Circular) {
248 state.setBuilt(
false);
273 void LoadingIndicator::buildChild(
void)
279 if (state.isBuilt()) {
287 state.getIndicator())) {
294 std::shared_ptr<ecs::Entity> child;
295 if (state.getVariant() == Variant::Circular) {
296 child = std::make_shared<RotatingArc>(registry);
298 child = std::make_shared<LinearBar>(registry);
300 child->setParent(shared_from_this());
302 state.setIndicator(child->getIdentifier()).setBuilt(
true);
316 if (state.getVariant() == variant) {
357 void LoadingIndicator::build(
void)
A timer that runs from 0 to a duration and reports its eased progress, from 0 to 1,...
Animation & setOnSampleHandler(const SampleHandler &handler)
Store the callback that applies the animation.
std::function< void(float)> SampleHandler
Receives the eased progress.
@ Start
Packed at the left (row) or top (column).
@ Horizontal
Row: children placed left to right.
State of a loading indicator: an arc that turns, or a bar that slides, in a loop while something is i...
static constexpr float LinearWidth
Length of the linear variant, in dp.
LoadingIndicator & setVariant(Variant variant)
Set the shape of the indicator.
LoadingIndicator & setBuilt(bool built)
Record whether the animated child matches the current variant.
static constexpr float LinearHeight
Thickness of the linear variant, in dp.
LoadingIndicator & setSize(float size)
Set the diameter of the circular variant.
static constexpr float DefaultSize
Default diameter of the circular variant, in dp.
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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
void addEntity(std::shared_ptr< Entity > entity)
Make this registry own an entity, so that it stays alive and systems visit it.
void clearEntities(void)
Remove every entity owned by this registry, with everything they own and all their components.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
ComponentRegistry & getComponentRegistry(void)
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Configures a LoadingIndicator, then builds it and registers it in the entity registry given at constr...
void reset(void) override
Restore the defaults: Circular variant, a 48 dp diameter and a default pose.
std::shared_ptr< LoadingIndicator > makeLoadingIndicator(std::shared_ptr< ecs::Entity > parent, Variant variant)
Build a loading indicator, register it under parent and reset the builder.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Builder & withVariant(Variant variant)
Set the indicator variant.
Builder & withPose(const utility::graphic::PoseF &pose)
Set the pose the indicator is created with.
std::shared_ptr< LoadingIndicator > buildEntity(void) override
Build a loading indicator and its animated child from the current configuration, without registering ...
Builder & withSize(float size)
Set the diameter of the Circular variant.
float getSize(void) const
Get the diameter of the Circular variant.
float getStrokeWidth(void) const
Get the thickness of the arc of the Circular variant.
Variant getVariant(void) const
Get the indicator variant.
utility::graphic::Color32Bit getIndicatorColor(void) const
Get the color of the arc or bar.
float getOpacity(void) const
Get the opacity of the fade.
static std::shared_ptr< LoadingIndicator > create(Arguments &&...arguments)
Create a loading indicator and its animated child, without registering it in an entity registry.
LoadingIndicator & stop(void)
Stop the looping animation.
LoadingIndicator & start(void)
Start the looping animation and fade the indicator in over 200 ms.
components::LoadingIndicator::Variant Variant
LoadingIndicator & setIndicatorColor(const utility::graphic::Color32Bit &color)
Set the color of the arc or bar. Redraws at once.
LoadingIndicator & setSize(float size)
Set the diameter of the Circular variant (Paper size).
~LoadingIndicator(void) override
Default destructor.
bool hidesWhenStopped(void) const
Check whether a stopped indicator is hidden.
LoadingIndicator & setVariant(Variant variant)
Change the indicator variant.
bool isRunning(void) const
Check whether the looping animation is playing.
LoadingIndicator & setHidesWhenStopped(bool hides)
Choose whether a stopped indicator is hidden (Paper hidesWhenStopped).
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
static void installChildren(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Wire the looping animation of the animated child and start it.
static void startFade(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Start fading towards the opacity the running state calls for.
static bool isRunning(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the looping animation is running.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Give a loading indicator its accessibility role and its fade.
static float strokeWidth(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the stroke width of the circular arc, in dp.
static utility::graphic::Color32Bit indicatorColor(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the color of the arc or bar at full opacity.
static void stop(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Stop the looping animation.
static void start(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Start the looping animation and fade the indicator in.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Size one loading indicator and draw its animated child at the current loop progress and opacity.
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.
@ Full
Fully rounded (buttons, icon buttons, badges).
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
bool hasFixedHeight
True when fixedHeight replaces the content height.
float fixedHeight
Height in dp, used only when hasFixedHeight.