Plutonium framework API 0.3.0
UI framework libraries for libnx
elm_ProgressBar.hpp
Go to the documentation of this file.
1
2/*
3
4 Plutonium library
5
6 @file ProgressBar.hpp
7 @brief A ProgressBar is an Element which represents a progress (a percentage) by filling a bar.
8 @author XorTroll
9
10 @copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
11
12*/
13
14#pragma once
16
17namespace pu::ui::elm {
18
19 class ProgressBar : public Element {
20 public:
21 static constexpr Color DefaultProgressColor = { 139, 195, 74, 255 };
22 static constexpr Color DefaultBackgroundColor = { 140, 140, 140, 255 };
23
24 private:
25 i32 x;
26 i32 y;
27 i32 w;
28 i32 h;
29 double val;
30 double max_val;
31 Color progress_clr;
32 Color bg_clr;
33
34 public:
35 ProgressBar(const i32 x, const i32 y, const i32 width, const i32 height, const double max_val) : Element(), x(x), y(y), w(width), h(height), val(0), max_val(max_val), progress_clr(DefaultProgressColor), bg_clr(DefaultBackgroundColor) {}
37
38 inline i32 GetX() override {
39 return this->x;
40 }
41
42 inline void SetX(const i32 x) {
43 this->x = x;
44 }
45
46 inline i32 GetY() override {
47 return this->y;
48 }
49
50 inline void SetY(const i32 y) {
51 this->y = y;
52 }
53
54 inline i32 GetWidth() override {
55 return this->w;
56 }
57
58 inline void SetWidth(const i32 width) {
59 this->w = width;
60 }
61
62 inline i32 GetHeight() override {
63 return this->h;
64 }
65
66 inline void SetHeight(const i32 height) {
67 this->h = height;
68 }
69
71 return this->progress_clr;
72 }
73
74 inline void SetProgressColor(const Color progress_clr) {
75 this->progress_clr = progress_clr;
76 }
77
79 return this->bg_clr;
80 }
81
82 inline void SetBackgroundColor(const Color bg_clr) {
83 this->bg_clr = bg_clr;
84 }
85
86 inline double GetProgress() {
87 return this->val;
88 }
89
90 void SetProgress(const double progress);
91
92 inline void IncrementProgress(const double extra_progress) {
93 this->SetProgress(this->val + extra_progress);
94 }
95
96 inline void DecrementProgress(const double extra_progress) {
97 this->SetProgress(this->val - extra_progress);
98 }
99
100 inline void SetMaxProgress(const double max_progress) {
101 this->max_val = max_progress;
102 }
103
104 inline double GetMaxProgress() {
105 return this->max_val;
106 }
107
108 inline void FillProgress() {
109 this->SetProgress(this->max_val);
110 }
111
112 inline void ClearProgress() {
113 this->SetProgress(0);
114 }
115
116 inline bool IsCompleted() {
117 return this->val == this->max_val;
118 }
119
120 void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override;
121 void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override {}
122 };
123
124}
Definition: elm_Element.hpp:37
Definition: elm_ProgressBar.hpp:19
double GetMaxProgress()
Definition: elm_ProgressBar.hpp:104
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override
i32 GetX() override
Definition: elm_ProgressBar.hpp:38
i32 GetWidth() override
Definition: elm_ProgressBar.hpp:54
void SetHeight(const i32 height)
Definition: elm_ProgressBar.hpp:66
void SetMaxProgress(const double max_progress)
Definition: elm_ProgressBar.hpp:100
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override
Definition: elm_ProgressBar.hpp:121
void ClearProgress()
Definition: elm_ProgressBar.hpp:112
void SetProgressColor(const Color progress_clr)
Definition: elm_ProgressBar.hpp:74
void SetProgress(const double progress)
Color GetProgressColor()
Definition: elm_ProgressBar.hpp:70
ProgressBar(const i32 x, const i32 y, const i32 width, const i32 height, const double max_val)
Definition: elm_ProgressBar.hpp:35
void SetBackgroundColor(const Color bg_clr)
Definition: elm_ProgressBar.hpp:82
void IncrementProgress(const double extra_progress)
Definition: elm_ProgressBar.hpp:92
bool IsCompleted()
Definition: elm_ProgressBar.hpp:116
void DecrementProgress(const double extra_progress)
Definition: elm_ProgressBar.hpp:96
Color GetBackgroundColor()
Definition: elm_ProgressBar.hpp:78
static constexpr Color DefaultProgressColor
Definition: elm_ProgressBar.hpp:21
void FillProgress()
Definition: elm_ProgressBar.hpp:108
static constexpr Color DefaultBackgroundColor
Definition: elm_ProgressBar.hpp:22
void SetY(const i32 y)
Definition: elm_ProgressBar.hpp:50
void SetX(const i32 x)
Definition: elm_ProgressBar.hpp:42
double GetProgress()
Definition: elm_ProgressBar.hpp:86
i32 GetY() override
Definition: elm_ProgressBar.hpp:46
void SetWidth(const i32 width)
Definition: elm_ProgressBar.hpp:58
i32 GetHeight() override
Definition: elm_ProgressBar.hpp:62
Definition: elm_Button.hpp:18
s32 i32
Definition: pu_Include.hpp:28
#define PU_SMART_CTOR(type)
Definition: pu_Include.hpp:19
Definition: ui_Types.hpp:44
Definition: ui_Types.hpp:62