23#include "guillaume/entities/progress_indicator.hpp"
30#include "guillaume/ecs/entity_filler.hpp"
32#include "guillaume/components/animation.hpp"
33#include "guillaume/components/arc.hpp"
34#include "guillaume/components/borders.hpp"
35#include "guillaume/components/bound.hpp"
36#include "guillaume/components/color.hpp"
37#include "guillaume/components/ring.hpp"
38#include "guillaume/components/transform.hpp"
40#include "guillaume/components/accessibility.hpp"
41#include "guillaume/entities/builder_base.hpp"
43#include "guillaume/systems/progress_indicator.hpp"
44#include "guillaume/theme.hpp"
50 constexpr float LinearHeight =
53 constexpr float CircularSize =
55 constexpr float TrackLength =
62 public ecs::EntityFiller<components::Transform, components::Bound,
63 components::Color, components::Borders>
70 explicit LinearTrack(ecs::ComponentRegistry ®istry)
71 : ecs::EntityFiller<components::Transform, components::Bound,
72 components::Color, components::Borders>(
80 ~LinearTrack(
void)
override =
default;
87 public ecs::EntityFiller<components::Transform, components::Bound,
88 components::Color, components::Borders,
89 components::Animation>
96 explicit LinearFill(ecs::ComponentRegistry ®istry)
97 : ecs::EntityFiller<components::Transform, components::Bound,
98 components::Color, components::Borders,
99 components::Animation>(registry)
106 ~LinearFill(
void)
override =
default;
113 public ecs::EntityFiller<components::Transform, components::Bound,
114 components::Color, components::Ring>
121 explicit CircularTrack(ecs::ComponentRegistry ®istry)
122 : ecs::EntityFiller<components::Transform, components::Bound,
123 components::Color, components::Ring>(
131 ~CircularTrack(
void)
override =
default;
138 public ecs::EntityFiller<components::Transform, components::Bound,
139 components::Color, components::Arc,
140 components::Animation>
147 explicit CircularFill(ecs::ComponentRegistry ®istry)
148 : ecs::EntityFiller<components::Transform, components::Bound,
149 components::Color, components::Arc,
150 components::Animation>(registry)
157 ~CircularFill(
void)
override =
default;
170 std::shared_ptr<ProgressIndicator>
173 if (_variant == Variant::CircularDeterminate
174 || _variant == Variant::CircularIndeterminate) {
175 _config.setFixedWidth(_size).setFixedHeight(_size);
176 _config.borderRadius = _size * 0.5f;
178 _config.setFixedWidth(_width).setFixedHeight(LinearHeight);
179 _config.borderRadius = LinearRadius;
183 _config, _variant, _value);
190 _variant = Variant::LinearDeterminate;
192 _width = TrackLength;
193 _size = CircularSize;
195 _config.borderRadius = LinearRadius;
197 _config.mainAxisAlignment =
199 _config.crossAxisAlignment =
201 _config.padding = 0.0f;
202 _config.spacing = 0.0f;
203 _config.setFixedWidth(_width);
204 _config.setFixedHeight(LinearHeight);
208 const utility::graphic::PoseF &pose)
224 _value = std::clamp(value, 0.0f, 1.0f);
241 std::shared_ptr<ProgressIndicator>
243 std::shared_ptr<ecs::Entity> parent,
Variant variant,
float value)
245 return withVariant(variant).withValue(value).registerEntity(parent);
271 .
setValue(std::clamp(value, 0.0f, 1.0f));
307 const utility::graphic::Color32Bit &color)
317 utility::graphic::Color32Bit
328 void ProgressIndicator::buildChildren(
void)
334 if (state.isBuilt()) {
347 std::shared_ptr<ecs::Entity> track;
348 std::shared_ptr<ecs::Entity> fill;
349 if (state.isCircular()) {
350 track = std::make_shared<CircularTrack>(registry);
351 fill = std::make_shared<CircularFill>(registry);
353 track = std::make_shared<LinearTrack>(registry);
354 fill = std::make_shared<LinearFill>(registry);
356 track->setParent(shared_from_this());
358 fill->setParent(shared_from_this());
360 state.setTrack(track->getIdentifier())
361 .setFill(fill->getIdentifier())
377 if (state.getVariant() == variant) {
412 void ProgressIndicator::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 progress indicator: a bar or a ring that fills up with a value from 0 to 1,...
static constexpr float DefaultTrackLength
Default length of the linear track, in dp.
static constexpr float LinearHeight
Thickness of the linear track, in dp.
static constexpr float DefaultDiameter
Default diameter of the circular variants, in dp.
ProgressIndicator & setTrackLength(float length)
Set the length of the track of the linear variants.
ProgressIndicator & setDiameter(float diameter)
Set the diameter of the circular variants.
ProgressIndicator & setVariant(Variant variant)
Set the shape of the indicator and whether it shows a value.
ProgressIndicator & setBuilt(bool built)
Record whether the track and fill children match the current variant.
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.
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 ProgressIndicator, then builds it and registers it in the entity registry given at const...
std::shared_ptr< ProgressIndicator > makeProgressIndicator(std::shared_ptr< ecs::Entity > parent, Variant variant, float value)
Build a progress indicator, register it under parent and reset the builder.
Builder & withValue(float value)
Set the progress the indicator starts with.
Builder & withWidth(float width)
Set the length of the bar of the linear variants.
Builder & withSize(float size)
Set the diameter of the ring of the circular variants.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Builder & withPose(const utility::graphic::PoseF &pose)
Set the pose the indicator is created with.
Builder & withVariant(Variant variant)
Set the indicator variant.
std::shared_ptr< ProgressIndicator > buildEntity(void) override
Build a progress indicator and its track and fill children from the current configuration,...
void reset(void) override
Restore the defaults: LinearDeterminate variant, value 0, a 200 dp long bar, a 48 dp wide ring and a ...
Variant getVariant(void) const
Get the indicator variant.
ProgressIndicator & setVariant(Variant variant)
Change the indicator variant.
ProgressIndicator & setVisible(bool visible)
Show or hide the indicator with a 200 ms fade (Paper visible).
bool isVisible(void) const
Check whether the indicator is meant to be visible.
ProgressIndicator & setValue(float value)
Set the progress.
float getOpacity(void) const
Get the opacity of the fade.
float getValue(void) const
Get the progress last set.
components::ProgressIndicator::Variant Variant
static std::shared_ptr< ProgressIndicator > create(Arguments &&...arguments)
Create a progress indicator and its track and fill children, without registering it in an entity regi...
ProgressIndicator & setIndicatorColor(const utility::graphic::Color32Bit &color)
Set the color of the fill. Redraws at once.
utility::graphic::Color32Bit getIndicatorColor(void) const
Get the color of the fill.
float getDisplayedValue(void) const
Get the progress drawn at the moment.
~ProgressIndicator(void) override
Default destructor.
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
static void setVisible(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
Show or hide the indicator with a fade.
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.
static void installChildren(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Wire the looping animation of an indeterminate indicator and start it.
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.
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 hasFixedWidth
True when fixedWidth replaces the content width.
float fixedWidth
Width in dp, used only when hasFixedWidth.
bool hasFixedHeight
True when fixedHeight replaces the content height.
float fixedHeight
Height in dp, used only when hasFixedHeight.