guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
loading_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
55 {
56 public:
60 enum class Variant {
63 };
64
66 static constexpr float LinearWidth = 200.0f;
67
69 static constexpr float LinearHeight = 4.0f;
70
73 static constexpr float LinearSegment = 0.4f;
74
76 static constexpr float DefaultSize = 48.0f;
77
80 static constexpr float StrokeRatio = 4.0f / 48.0f;
81
86 LoadingIndicator(void) = default;
87
91 ~LoadingIndicator(void) = default;
92
97 Variant getVariant(void) const noexcept;
98
109
114 float getSize(void) const noexcept;
115
125 LoadingIndicator &setSize(float size);
126
133 ecs::Entity::Identifier getIndicator(void) const noexcept;
134
144
151 bool isBuilt(void) const noexcept;
152
163 LoadingIndicator &setBuilt(bool built);
164
169 float getProgress(void) const noexcept;
170
180 LoadingIndicator &setProgress(float progress);
181
187 bool hidesWhenStopped(void) const noexcept;
188
199
204 float getOpacity(void) const noexcept;
205
215 LoadingIndicator &setOpacity(float opacity);
216
222 float getOpacityFrom(void) const noexcept;
223
231 LoadingIndicator &setOpacityFrom(float opacity);
232
238 float getOpacityTarget(void) const noexcept;
239
249 LoadingIndicator &setOpacityTarget(float opacity);
250
256 const std::optional<utility::graphic::Color32Bit> &
257 getIndicatorColor(void) const noexcept;
258
268 const std::optional<utility::graphic::Color32Bit> &color);
269
270 private:
271 Variant _variant { Variant::Circular };
272 float _size { DefaultSize };
273 ecs::Entity::Identifier _indicator {
275 };
276
277 bool _built { false };
278 float _progress { 0.0f };
279 bool _hidesWhenStopped { true };
280 float _opacity { 1.0f };
281 float _opacityFrom { 1.0f };
282 float _opacityTarget { 1.0f };
283 std::optional<utility::graphic::Color32Bit>
284 _indicatorColor {};
285 };
286
287} // namespace guillaume::components
@ Linear
Bar that slides along a 200 dp line.
LoadingIndicator & setOpacity(float opacity)
Store the opacity the indicator is drawn with.
static constexpr float LinearWidth
Length of the linear variant, in dp.
LoadingIndicator & setHidesWhenStopped(bool hides)
Choose whether the indicator fades out when it is stopped.
LoadingIndicator & setVariant(Variant variant)
Set the shape of the indicator.
~LoadingIndicator(void)=default
Default destructor.
float getOpacityFrom(void) const noexcept
Get the opacity the indicator had when the running fade began.
float getSize(void) const noexcept
Get the diameter of the circular variant.
LoadingIndicator & setOpacityTarget(float opacity)
Store the opacity a fade ends at.
float getOpacity(void) const noexcept
Get the opacity the indicator is drawn with.
LoadingIndicator & setOpacityFrom(float opacity)
Store the opacity at the start of a fade.
LoadingIndicator & setBuilt(bool built)
Record whether the animated child matches the current variant.
const std::optional< utility::graphic::Color32Bit > & getIndicatorColor(void) const noexcept
Get the color chosen for the indicator.
float getOpacityTarget(void) const noexcept
Get the opacity the running fade ends at.
static constexpr float LinearHeight
Thickness of the linear variant, in dp.
LoadingIndicator & setProgress(float progress)
Store how far the loop has advanced.
bool hidesWhenStopped(void) const noexcept
Tell whether the indicator fades out when it is stopped.
bool isBuilt(void) const noexcept
Tell whether the animated child matches the current variant.
float getProgress(void) const noexcept
Get how far the loop has advanced.
LoadingIndicator & setIndicatorColor(const std::optional< utility::graphic::Color32Bit > &color)
Choose the color of the indicator.
ecs::Entity::Identifier getIndicator(void) const noexcept
Get the child that draws the turning arc or the sliding bar.
LoadingIndicator & setIndicator(ecs::Entity::Identifier identifier)
Record the child that draws the turning arc or the sliding bar.
LoadingIndicator(void)=default
Create the state of a circular indicator of the default size, with no child, that hides when stopped.
LoadingIndicator & setSize(float size)
Set the diameter of the circular variant.
static constexpr float DefaultSize
Default diameter of the circular variant, in dp.
Variant getVariant(void) const noexcept
Get the shape of the indicator.
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.