Plutonium framework API 0.3.0
UI framework libraries for libnx
Loading...
Searching...
No Matches
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
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 static constexpr double DefaultHeightRadiusFactor = 0.333;
25
26 private:
27 i32 x;
28 i32 y;
29 i32 w;
30 i32 h;
31 double val;
32 double max_val;
33 u32 radius;
34 Color progress_clr;
35 Color bg_clr;
36
37 public:
38 ProgressBar(const i32 x, const i32 y, const i32 width, const i32 height, const double max_val);
40
41 inline i32 GetX() override {
42 return this->x;
43 }
44
45 inline void SetX(const i32 x) {
46 this->x = x;
47 }
48
49 inline i32 GetY() override {
50 return this->y;
51 }
52
53 inline void SetY(const i32 y) {
54 this->y = y;
55 }
56
57 inline i32 GetWidth() override {
58 return this->w;
59 }
60
61 inline void SetWidth(const i32 width) {
62 this->w = width;
63 }
64
65 inline i32 GetHeight() override {
66 return this->h;
67 }
68
69 inline void SetHeight(const i32 height) {
70 this->h = height;
71 }
72
73 PU_CLASS_POD_GETSET(Radius, radius, u32)
74 PU_CLASS_POD_GETSET(ProgressColor, progress_clr, Color)
75 PU_CLASS_POD_GETSET(BackgroundColor, bg_clr, Color)
76
77 PU_CLASS_POD_GET(Progress, val, double)
78
79 void SetProgress(const double progress);
80
81 inline void IncrementProgress(const double extra_progress) {
82 this->SetProgress(this->val + extra_progress);
83 }
84
85 inline void DecrementProgress(const double extra_progress) {
86 this->SetProgress(this->val - extra_progress);
87 }
88
89 PU_CLASS_POD_GETSET(MaxProgress, max_val, double)
90
91 inline void FillProgress() {
92 this->SetProgress(this->max_val);
93 }
94
95 inline void ClearProgress() {
96 this->SetProgress(0);
97 }
98
99 inline bool IsCompleted() {
100 return this->val == this->max_val;
101 }
102
103 void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override;
104 void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override {}
105 };
106
107}
Definition elm_Element.hpp:37
Definition elm_ProgressBar.hpp:19
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override
i32 GetX() override
Definition elm_ProgressBar.hpp:41
i32 GetWidth() override
Definition elm_ProgressBar.hpp:57
void SetHeight(const i32 height)
Definition elm_ProgressBar.hpp:69
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override
Definition elm_ProgressBar.hpp:104
void ClearProgress()
Definition elm_ProgressBar.hpp:95
static constexpr double DefaultHeightRadiusFactor
Definition elm_ProgressBar.hpp:24
void SetProgress(const double progress)
ProgressBar(const i32 x, const i32 y, const i32 width, const i32 height, const double max_val)
void IncrementProgress(const double extra_progress)
Definition elm_ProgressBar.hpp:81
bool IsCompleted()
Definition elm_ProgressBar.hpp:99
void DecrementProgress(const double extra_progress)
Definition elm_ProgressBar.hpp:85
static constexpr Color DefaultProgressColor
Definition elm_ProgressBar.hpp:21
void FillProgress()
Definition elm_ProgressBar.hpp:91
static constexpr Color DefaultBackgroundColor
Definition elm_ProgressBar.hpp:22
void SetY(const i32 y)
Definition elm_ProgressBar.hpp:53
void SetX(const i32 x)
Definition elm_ProgressBar.hpp:45
i32 GetY() override
Definition elm_ProgressBar.hpp:49
void SetWidth(const i32 width)
Definition elm_ProgressBar.hpp:61
i32 GetHeight() override
Definition elm_ProgressBar.hpp:65
Definition render_Renderer.hpp:127
Definition render_Renderer.hpp:20
Definition elm_Button.hpp:18
#define PU_SMART_CTOR(type)
Definition pu_Include.hpp:20
#define PU_CLASS_POD_GETSET(fn_name, var_name, type)
Definition pu_Include.hpp:37
#define PU_CLASS_POD_GET(fn_name, var_name, type)
Definition pu_Include.hpp:27
Definition ui_Types.hpp:44
Definition ui_Types.hpp:67