guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
progress_indicator.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <optional>
26
27#include <utility/graphic/color.hpp>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
56 {
57 public:
69
71 static constexpr float DefaultTrackLength = 200.0f;
72
74 static constexpr float LinearHeight = 4.0f;
75
77 static constexpr float DefaultDiameter = 48.0f;
78
80 static constexpr float RingThickness = 4.0f;
81
84 static constexpr float IndeterminateSegment = 0.6f;
85
88 static constexpr float IndeterminateSweep = 0.25f;
89
94 ProgressIndicator(void) = default;
95
99 ~ProgressIndicator(void) = default;
100
106 Variant getVariant(void) const noexcept;
107
119
124 bool isCircular(void) const noexcept;
125
131 bool isIndeterminate(void) const noexcept;
132
137 float getTrackLength(void) const noexcept;
138
147 ProgressIndicator &setTrackLength(float length);
148
153 float getDiameter(void) const noexcept;
154
163 ProgressIndicator &setDiameter(float diameter);
164
171 ecs::Entity::Identifier getTrack(void) const noexcept;
172
181
188 ecs::Entity::Identifier getFill(void) const noexcept;
189
198
205 bool isBuilt(void) const noexcept;
206
217 ProgressIndicator &setBuilt(bool built);
218
224 float getDisplayed(void) const noexcept;
225
235 ProgressIndicator &setDisplayed(float displayed);
236
242 float getValueFrom(void) const noexcept;
243
252 ProgressIndicator &setValueFrom(float value);
253
259 bool isVisible(void) const noexcept;
260
270 ProgressIndicator &setVisible(bool visible);
271
276 float getOpacity(void) const noexcept;
277
287 ProgressIndicator &setOpacity(float opacity);
288
294 float getOpacityFrom(void) const noexcept;
295
305 ProgressIndicator &setOpacityFrom(float opacity);
306
312 float getCycle(void) const noexcept;
313
325 ProgressIndicator &setCycle(float cycle);
326
332 const std::optional<utility::graphic::Color32Bit> &
333 getIndicatorColor(void) const noexcept;
334
344 const std::optional<utility::graphic::Color32Bit> &color);
345
346 private:
348 float _trackLength { DefaultTrackLength };
349 float _diameter { DefaultDiameter };
352 };
353
356 };
357
358 bool _built { false };
359 float _displayed { 0.0f };
360 float _valueFrom { 0.0f };
361 bool _visible { true };
362 float _opacity { 1.0f };
363 float _opacityFrom { 1.0f };
364 float _cycle { 0.0f };
365 std::optional<utility::graphic::Color32Bit>
366 _indicatorColor {};
367 };
368
369} // namespace guillaume::components
float getDiameter(void) const noexcept
Get the diameter of the circular variants.
ProgressIndicator & setIndicatorColor(const std::optional< utility::graphic::Color32Bit > &color)
Choose the color of the fill.
static constexpr float DefaultTrackLength
Default length of the linear track, in dp.
ProgressIndicator & setDisplayed(float displayed)
Store the value currently drawn.
bool isCircular(void) const noexcept
Tell whether the indicator is a ring.
float getValueFrom(void) const noexcept
Get the value that was drawn when the running transition began.
bool isVisible(void) const noexcept
Tell whether the indicator is meant to be visible.
float getOpacity(void) const noexcept
Get the opacity the indicator is drawn with.
static constexpr float LinearHeight
Thickness of the linear track, in dp.
static constexpr float DefaultDiameter
Default diameter of the circular variants, in dp.
ProgressIndicator & setOpacity(float opacity)
Store the opacity the indicator is drawn with.
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.
static constexpr float RingThickness
Stroke width of the circular track and fill, in dp.
~ProgressIndicator(void)=default
Default destructor.
ProgressIndicator(void)=default
Create the state of a visible linear determinate indicator with the default sizes and no child.
const std::optional< utility::graphic::Color32Bit > & getIndicatorColor(void) const noexcept
Get the color chosen for the fill.
ProgressIndicator & setVariant(Variant variant)
Set the shape of the indicator and whether it shows a value.
ProgressIndicator & setOpacityFrom(float opacity)
Store the opacity at the start of a fade.
ProgressIndicator & setCycle(float cycle)
Store how far the loop of an indeterminate variant has advanced.
ProgressIndicator & setBuilt(bool built)
Record whether the track and fill children match the current variant.
Variant
Shape of the indicator and whether it shows a value.
Variant getVariant(void) const noexcept
Get the shape of the indicator and whether it shows a value.
float getTrackLength(void) const noexcept
Get the length of the track of the linear variants.
float getCycle(void) const noexcept
Get how far the loop of an indeterminate variant has advanced.
ecs::Entity::Identifier getTrack(void) const noexcept
Get the child that draws the track: the full bar or ring behind the fill.
bool isIndeterminate(void) const noexcept
Tell whether the indicator loops instead of showing a value.
ProgressIndicator & setVisible(bool visible)
Record whether the indicator is meant to be visible.
ProgressIndicator & setFill(ecs::Entity::Identifier identifier)
Record the child that draws the fill.
ProgressIndicator & setTrack(ecs::Entity::Identifier identifier)
Record the child that draws the track.
float getOpacityFrom(void) const noexcept
Get the opacity the indicator had when the running fade began.
float getDisplayed(void) const noexcept
Get the value currently drawn.
bool isBuilt(void) const noexcept
Tell whether the track and fill children match the current variant.
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.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.