23#include "guillaume/systems/progress_indicator.hpp"
29#include "guillaume/components/accessibility.hpp"
30#include "guillaume/components/animation.hpp"
31#include "guillaume/components/arc.hpp"
32#include "guillaume/components/borders.hpp"
33#include "guillaume/components/bound.hpp"
34#include "guillaume/components/color.hpp"
35#include "guillaume/components/layout.hpp"
36#include "guillaume/components/ring.hpp"
37#include "guillaume/components/value.hpp"
40#include "guillaume/motion/easing.hpp"
41#include "guillaume/systems/layout.hpp"
42#include "guillaume/theme.hpp"
48 constexpr float TwoPi = 6.28318530717958647692f;
49 constexpr float HalfPi = 1.57079632679489661923f;
60 void shape(ecs::ComponentRegistry ®istry,
62 float height,
float radius, std::uint32_t layer)
65 registry.getComponent<components::Layout>(identifier);
67 layout.setPadding(0.0f)
70 .setFixedHeight(height);
71 registry.getComponent<components::Borders>(identifier)
72 .setBorderRadius(radius);
73 registry.getComponent<components::Color>(identifier)
75 Layout::apply(registry, identifier, layout.getChildren(), layer);
87 void publish(ecs::ComponentRegistry ®istry,
89 const std::optional<components::AccessibilityValue> &value)
92 registry.getComponent<components::Accessibility>(identifier);
93 const auto ¤t = accessibility.getValue();
95 if (current.has_value() == value.has_value()
96 && (!value.has_value()
97 || (current->min == value->min && current->max == value->max
98 && current->now == value->now))) {
101 accessibility.setValue(value);
110 utility::graphic::Color32Bit
111 faded(
const utility::graphic::Color32Bit &color,
float opacity)
115 static_cast<std::uint8_t
>(
116 static_cast<float>(color.getAlpha()) * opacity + 0.5f));
137 value.setMin(0.0f).setMax(1.0f).setStep(0.0f);
141 value.setOnChangedHandler([registry, identifier](
float) {
155 const float opacityTarget = current.isVisible() ? 1.0f : 0.0f;
158 .setDisplayed(current.getValueFrom()
159 + (target - current.getValueFrom())
161 .setOpacity(current.getOpacityFrom()
162 + (opacityTarget - current.getOpacityFrom())
164 apply(*registry, identifier);
180 const auto fill = state.
getFill();
182 if (!state.isIndeterminate()
194 apply(*registry, identifier);
206 const auto layer =
Layout::layerOf(componentRegistry, entityIdentifier);
207 const bool circular = state.isCircular();
208 const bool indeterminate = state.isIndeterminate();
209 const float diameter = state.getDiameter();
210 const float length = state.getTrackLength();
213 const float normalized = std::clamp(state.getDisplayed(), 0.0f, 1.0f);
214 const auto track = state.getTrack();
215 const auto fill = state.getFill();
216 const utility::graphic::PositionF origin(0.0f, 0.0f, 0.0f);
219 shape(componentRegistry, entityIdentifier, diameter, diameter,
220 diameter * 0.5f, layer);
222 shape(componentRegistry, entityIdentifier, length, height, full,
227 publish(componentRegistry, entityIdentifier, std::nullopt);
229 publish(componentRegistry, entityIdentifier,
232 std::clamp(componentRegistry
249 state.getOpacity()));
252 state.getOpacity()));
257 const auto fillLayer = layer + 1;
280 arc.setStartAngle(HalfPi - state.getCycle() * TwoPi)
281 .setSweepAngle(-TwoPi
285 arc.setStartAngle(HalfPi).setSweepAngle(-normalized
297 .setBorderRadius(full);
300 const float segment =
304 componentRegistry, entityIdentifier, fill,
305 utility::graphic::PositionF(
306 state.getCycle() * (length - segment), 0.0f, 0.0f),
315 .setWidth(length * normalized)
325 .setNormalizedValue(std::clamp(value, 0.0f, 1.0f));
336 if (state.isVisible() == visible) {
355 apply(componentRegistry, entityIdentifier);
362 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.
A portion of a ring: the moving part of a circular progress or loading indicator.
Arc & setThickness(float thickness)
Set the thickness of the arc.
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 progress indicator: a bar or a ring that fills up with a value from 0 to 1,...
ProgressIndicator & setDisplayed(float displayed)
Store the value currently drawn.
static constexpr float LinearHeight
Thickness of the linear track, in dp.
static constexpr float IndeterminateSegment
static constexpr float RingThickness
Stroke width of the circular track and fill, in dp.
ProgressIndicator & setOpacityFrom(float opacity)
Store the opacity at the start of a fade.
ProgressIndicator & setVisible(bool visible)
Record whether the indicator is meant to be visible.
ProgressIndicator & setValueFrom(float value)
Store the value drawn at the start of a transition.
ecs::Entity::Identifier getFill(void) const noexcept
Get the child that draws the fill: the part of the bar or ring that shows the progress.
A full ring: the outline of a radio button, the track of a circular progress indicator.
A number kept inside a range, with a callback run when it changes.
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.
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...
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 setVisible(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
Show or hide the indicator with a fade.
static void startTransition(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Start moving the drawn value and opacity towards their targets.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Prepare the value, the transition and the accessibility role of a progress indicator.
static void setValue(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, float value)
Set the target value.
ProgressIndicator(void)
Create the system in the Layout phase.
static void installChildren(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Wire the looping animation of an indeterminate indicator and start it.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one progress indicator; called by the frame loop.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Size one progress indicator and draw its track and fill from the displayed value, the cycle position ...
static utility::graphic::Color32Bit indicatorColor(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the color of the fill at full 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.
Position of a control within a range, such as a slider or a progress bar. Accessibility::setValue req...
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.