23#include "guillaume/systems/loading_indicator.hpp"
27#include "guillaume/components/accessibility.hpp"
28#include "guillaume/components/animation.hpp"
29#include "guillaume/components/arc.hpp"
30#include "guillaume/components/borders.hpp"
31#include "guillaume/components/bound.hpp"
32#include "guillaume/components/color.hpp"
33#include "guillaume/components/layout.hpp"
36#include "guillaume/motion/easing.hpp"
37#include "guillaume/systems/layout.hpp"
38#include "guillaume/theme.hpp"
46 constexpr float TwoPi = 6.28318530717958647692f;
47 constexpr float HalfPi = 1.57079632679489661923f;
48 constexpr float ArcSweep = 4.71238898038468985769f;
59 void shape(ecs::ComponentRegistry ®istry,
61 float height,
float radius, std::uint32_t layer)
64 registry.getComponent<components::Layout>(identifier);
66 layout.setPadding(0.0f)
69 .setFixedHeight(height);
70 registry.getComponent<components::Borders>(identifier)
71 .setBorderRadius(radius);
72 registry.getComponent<components::Color>(identifier)
74 Layout::apply(registry, identifier, layout.getChildren(), layer);
100 state.getOpacityFrom()
101 + (state.getOpacityTarget() - state.getOpacityFrom())
103 apply(*registry, identifier);
127 .setProgress(progress);
128 apply(*registry, identifier);
140 const auto layer =
Layout::layerOf(componentRegistry, entityIdentifier);
141 const bool circular = state.getVariant() == Variant::Circular;
142 const float size = state.getSize();
144 const auto child = state.getIndicator();
147 shape(componentRegistry, entityIdentifier, size, size, size * 0.5f,
150 shape(componentRegistry, entityIdentifier,
160 const auto color =
indicatorColor(componentRegistry, entityIdentifier);
164 static_cast<std::uint8_t
>(
static_cast<float>(color.getAlpha())
179 utility::graphic::PositionF(0.0f, 0.0f, 0.0f),
192 .setBorderRadius(full);
195 componentRegistry, entityIdentifier, child,
196 utility::graphic::PositionF(
218 startFade(componentRegistry, entityIdentifier);
232 startFade(componentRegistry, entityIdentifier);
256 const float target = (
isRunning(componentRegistry, entityIdentifier)
257 || !state.hidesWhenStopped())
261 if (target == state.getOpacityTarget()
262 && target == state.getOpacity()) {
265 state.setOpacityFrom(state.getOpacity()).setOpacityTarget(target);
274 return componentRegistry
284 return componentRegistry
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
A timer that runs from 0 to a duration and reports its eased progress, from 0 to 1,...
Animation & setEasing(motion::Easing easing)
Set the curve that turns the linear progress into the value passed to the sample handler.
Animation & setOnSampleHandler(const SampleHandler &handler)
Store the callback that applies the animation.
Animation & setLooping(bool looping)
Set whether the animation starts again when it completes.
bool isPlaying(void) const
Check whether the animation is running.
A portion of a ring: the moving part of a circular progress or loading indicator.
Arc & setStartAngle(float startAngle)
Set the angle the arc starts at.
Arc & setSweepAngle(float sweepAngle)
Set the angle the arc covers from its start angle.
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...
Bound & setHeight(float height) noexcept
Set the height.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
State of a loading indicator: an arc that turns, or a bar that slides, in a loop while something is i...
Variant
Shape of the indicator.
LoadingIndicator & setOpacity(float opacity)
Store the opacity the indicator is drawn with.
static constexpr float LinearWidth
Length of the linear variant, in dp.
static constexpr float LinearHeight
Thickness of the linear variant, in dp.
static constexpr float StrokeRatio
static constexpr float LinearSegment
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...
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 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.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one loading indicator; called by the frame loop.
LoadingIndicator(void)
Create the system in the Layout phase.
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.
static constexpr float IndeterminateCycle
Duration of one cycle of an indeterminate progress or loading indicator, in seconds (1....
static constexpr motion::Easing standard(void)
Get the easing for elements that move or change while staying on screen.
State. Every class here is plain data attached to an entity.
@ ProgressBar
Determinate or indeterminate progress.
The entity-component-system core, independent of any widget.
void placeChild(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const ecs::Entity::Identifier &childIdentifier, const utility::graphic::PositionF &offset, std::uint32_t parentLayer)
Place a child at an offset from the position of its parent.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit withAlpha(const utility::graphic::Color32Bit &color, std::uint8_t alpha)
Copy a color with another alpha channel.
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.
@ Full
Fully rounded (buttons, icon buttons, badges).
float getMotionDuration(theme::MotionDuration duration)
Get the length the active theme gives to a duration token.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Placement helpers for the children systems::Layout does not arrange.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.