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
15#include <pu/ui/elm/elm_Element.hpp>
16
17 namespace 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) {}
36 PU_SMART_CTOR(ProgressBar)
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
70 inline Color GetProgressColor() {
71 return this->progress_clr;
72 }
73
74 inline void SetProgressColor(const Color progress_clr) {
75 this->progress_clr = progress_clr;
76 }
77
78 inline Color GetBackgroundColor() {
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}
pu::ui::elm::Element
Definition: elm_Element.hpp:37
pu::ui::elm::ProgressBar
Definition: elm_ProgressBar.hpp:19
pu::ui::elm::ProgressBar::GetMaxProgress
double GetMaxProgress()
Definition: elm_ProgressBar.hpp:104
pu::ui::elm::ProgressBar::OnRender
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override
pu::ui::elm::ProgressBar::GetX
i32 GetX() override
Definition: elm_ProgressBar.hpp:38
pu::ui::elm::ProgressBar::GetWidth
i32 GetWidth() override
Definition: elm_ProgressBar.hpp:54
pu::ui::elm::ProgressBar::SetHeight
void SetHeight(const i32 height)
Definition: elm_ProgressBar.hpp:66
pu::ui::elm::ProgressBar::SetMaxProgress
void SetMaxProgress(const double max_progress)
Definition: elm_ProgressBar.hpp:100
pu::ui::elm::ProgressBar::OnInput
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override
Definition: elm_ProgressBar.hpp:121
pu::ui::elm::ProgressBar::ClearProgress
void ClearProgress()
Definition: elm_ProgressBar.hpp:112
pu::ui::elm::ProgressBar::SetProgressColor
void SetProgressColor(const Color progress_clr)
Definition: elm_ProgressBar.hpp:74
pu::ui::elm::ProgressBar::SetProgress
void SetProgress(const double progress)
pu::ui::elm::ProgressBar::GetProgressColor
Color GetProgressColor()
Definition: elm_ProgressBar.hpp:70
pu::ui::elm::ProgressBar::ProgressBar
ProgressBar(const i32 x, const i32 y, const i32 width, const i32 height, const double max_val)
Definition: elm_ProgressBar.hpp:35
pu::ui::elm::ProgressBar::SetBackgroundColor
void SetBackgroundColor(const Color bg_clr)
Definition: elm_ProgressBar.hpp:82
pu::ui::elm::ProgressBar::IncrementProgress
void IncrementProgress(const double extra_progress)
Definition: elm_ProgressBar.hpp:92
pu::ui::elm::ProgressBar::IsCompleted
bool IsCompleted()
Definition: elm_ProgressBar.hpp:116
pu::ui::elm::ProgressBar::DecrementProgress
void DecrementProgress(const double extra_progress)
Definition: elm_ProgressBar.hpp:96
pu::ui::elm::ProgressBar::GetBackgroundColor
Color GetBackgroundColor()
Definition: elm_ProgressBar.hpp:78
pu::ui::elm::ProgressBar::DefaultProgressColor
static constexpr Color DefaultProgressColor
Definition: elm_ProgressBar.hpp:21
pu::ui::elm::ProgressBar::FillProgress
void FillProgress()
Definition: elm_ProgressBar.hpp:108
pu::ui::elm::ProgressBar::DefaultBackgroundColor
static constexpr Color DefaultBackgroundColor
Definition: elm_ProgressBar.hpp:22
pu::ui::elm::ProgressBar::SetY
void SetY(const i32 y)
Definition: elm_ProgressBar.hpp:50
pu::ui::elm::ProgressBar::SetX
void SetX(const i32 x)
Definition: elm_ProgressBar.hpp:42
pu::ui::elm::ProgressBar::GetProgress
double GetProgress()
Definition: elm_ProgressBar.hpp:86
pu::ui::elm::ProgressBar::GetY
i32 GetY() override
Definition: elm_ProgressBar.hpp:46
pu::ui::elm::ProgressBar::SetWidth
void SetWidth(const i32 width)
Definition: elm_ProgressBar.hpp:58
pu::ui::elm::ProgressBar::GetHeight
i32 GetHeight() override
Definition: elm_ProgressBar.hpp:62
elm_Element.hpp
pu::ui::elm
Definition: elm_Button.hpp:18
pu::i32
s32 i32
Definition: pu_Include.hpp:28
PU_SMART_CTOR
#define PU_SMART_CTOR(type)
Definition: pu_Include.hpp:19
pu::ui::Color
Definition: ui_Types.hpp:44
pu::ui::TouchPoint
Definition: ui_Types.hpp:62