4#include "TinyGPU/Color/RGB565.h"
5#include "TinyGPU/Color/RGB666.h"
6#include "TinyGPU/Color/RGB888.h"
7#include "TinyMaterialDesign/Core/Widget.h"
18 : value_(clamp01(value)), indeterminate_(indeterminate) {
19 this->bounds = bounds;
22 float value()
const {
return value_; }
23 void setValue(
float value) { value_ = clamp01(value); }
26 void draw(tinygpu::ISurface<RGB_T>& target)
override {
27 RGB_T trackColor =
this->theme().colors.surfaceVariant;
28 RGB_T activeColor =
this->enabled ?
this->theme().colors.primary
29 : blend(
this->theme().colors.primary,
this->theme().colors.surface, 0.5f);
30 const size_t radius = toPx(
this->bounds.h / 2);
32 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
33 toPx(
this->bounds.h), radius, trackColor);
36 constexpr float kSegmentFraction = 0.35f;
37 float start = phase_ * (1.0f + kSegmentFraction) - kSegmentFraction;
38 float end = start + kSegmentFraction;
39 start = std::max(0.0f, start);
40 end = std::min(1.0f, end);
42 const int32_t x0 =
this->bounds.x +
static_cast<int32_t>(start *
this->bounds.w);
43 const int32_t x1 =
this->bounds.x +
static_cast<int32_t>(end *
this->bounds.w);
44 target.fillRoundRect(toPx(x0), toPx(
this->bounds.y), toPx(x1 - x0), toPx(
this->bounds.h),
47 }
else if (value_ > 0.0f) {
48 const int32_t width =
static_cast<int32_t>(value_ *
this->bounds.w);
49 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(width),
50 toPx(
this->bounds.h), radius, activeColor);
54 bool update(uint32_t nowMs)
override {
55 if (!indeterminate_)
return false;
60 const uint32_t elapsed = (nowMs - startMs_) % kCycleMs;
61 phase_ =
static_cast<
float>(elapsed) /
static_cast<
float>(kCycleMs);
66 static constexpr uint32_t kCycleMs = 1200;
69 bool indeterminate_ =
false;
70 bool started_ =
false;
71 uint32_t startMs_ = 0;
74 static float clamp01(
float value) {
return std::min(1.0f, std::max(0.0f, value)); }
85 : value_(clamp01(value)), indeterminate_(indeterminate) {
86 this->bounds = bounds;
89 float value()
const {
return value_; }
90 void setValue(
float value) { value_ = clamp01(value); }
94 void draw(tinygpu::ISurface<RGB_T>& target)
override {
95 RGB_T trackColor =
this->theme().colors.surfaceVariant;
96 RGB_T activeColor =
this->enabled ?
this->theme().colors.primary
97 : blend(
this->theme().colors.primary,
this->theme().colors.surface, 0.5f);
99 const int32_t diameter =
this->bounds.w <
this->bounds.h ?
this->bounds.w :
this->bounds.h;
100 const size_t radius = toPx(diameter / 2 - thickness_ / 2);
101 const size_t cx = toPx(
this->bounds.centerX());
102 const size_t cy = toPx(
this->bounds.centerY());
104 target.drawArc(cx, cy, radius, 0.0f, 359.9f, trackColor, thickness_);
106 constexpr float kStartDeg = -90.0f;
107 if (indeterminate_) {
108 constexpr float kSweepDeg = 110.0f;
109 const float start = kStartDeg + phase_ * 360.0f;
110 target.drawArc(cx, cy, radius, start, start + kSweepDeg, activeColor, thickness_);
111 }
else if (value_ > 0.0f) {
112 target.drawArc(cx, cy, radius, kStartDeg, kStartDeg + value_ * 360.0f, activeColor,
118 if (!indeterminate_)
return false;
123 const uint32_t elapsed = (nowMs - startMs_) % kCycleMs;
124 phase_ =
static_cast<
float>(elapsed) /
static_cast<
float>(kCycleMs);
129 static constexpr uint32_t kCycleMs = 900;
132 bool indeterminate_ =
false;
133 uint8_t thickness_ = 4;
134 bool started_ =
false;
135 uint32_t startMs_ = 0;
138 static float clamp01(
float value) {
return std::min(1.0f, std::max(0.0f, value)); }
Circular "spinner" ring. Determinate (value in [0,1], drawn as a sweep starting at 12 o'clock) or ind...
Definition: ProgressIndicator.h:81
void setThickness(uint8_t thickness)
Definition: ProgressIndicator.h:92
CircularProgressIndicator(Bounds bounds, float value=0.0f, bool indeterminate=false)
Definition: ProgressIndicator.h:84
CircularProgressIndicator()=default
void setValue(float value)
Definition: ProgressIndicator.h:90
void setIndeterminate(bool indeterminate)
Definition: ProgressIndicator.h:91
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: ProgressIndicator.h:94
float value() const
Definition: ProgressIndicator.h:89
bool update(uint32_t nowMs) override
Definition: ProgressIndicator.h:117
Horizontal progress bar. Determinate (value in [0,1]) or indeterminate (a segment sweeps back and for...
Definition: ProgressIndicator.h:14
void setValue(float value)
Definition: ProgressIndicator.h:23
LinearProgressIndicator()=default
void setIndeterminate(bool indeterminate)
Definition: ProgressIndicator.h:24
LinearProgressIndicator(Bounds bounds, float value=0.0f, bool indeterminate=false)
Definition: ProgressIndicator.h:17
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: ProgressIndicator.h:26
float value() const
Definition: ProgressIndicator.h:22
bool update(uint32_t nowMs) override
Definition: ProgressIndicator.h:54
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21