Plutonium framework API 0.3.0
UI framework libraries for libnx
elm_Toggle.hpp
Go to the documentation of this file.
1
2/*
3
4 Plutonium library
5
6 @file Toggle.hpp
7 @brief A Toggle is an Element used to switch between two options by toggling the item.
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 Toggle : public Element {
20 public:
21 static constexpr u32 ContentHorizontalMargin = 30;
22 static constexpr u32 ContentVerticalMargin = 20;
23
24 static constexpr u8 ToggleAlphaIncrement = 48;
25
26 static constexpr Color MakeBackgroundColor(const u8 alpha) {
27 return { 130, 130, 130, alpha };
28 }
29
30 private:
31 i32 x;
32 i32 y;
33 u64 key;
34 bool checked;
35 Color clr;
36 std::string fnt_name;
37 i32 toggle_alpha;
38 std::string cnt;
39 sdl2::Texture cnt_tex;
40
41 public:
42 Toggle(const i32 x, const i32 y, const std::string &content, const u64 toggle_key, const Color clr);
45
46 inline i32 GetX() override {
47 return this->x;
48 }
49
50 inline void SetX(const i32 x) {
51 this->x = x;
52 }
53
54 inline i32 GetY() override {
55 return this->y;
56 }
57
58 inline void SetY(const i32 y) {
59 this->y = y;
60 }
61
62 i32 GetWidth() override;
63 i32 GetHeight() override;
64
65 inline std::string GetContent() {
66 return this->cnt;
67 }
68
69 void SetContent(const std::string &content);
70 void SetFont(const std::string &font_name);
71
72 inline Color GetColor() {
73 return this->clr;
74 }
75
76 void SetColor(const Color clr);
77
78 inline u64 GetKey() {
79 return this->key;
80 }
81
82 inline void SetKey(const u64 toggle_key) {
83 this->key = toggle_key;
84 }
85
86 inline bool IsChecked() {
87 return this->checked;
88 }
89
90 void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override;
91 void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override;
92 };
93
94}
Definition: elm_Element.hpp:37
Definition: elm_Toggle.hpp:19
Toggle(const i32 x, const i32 y, const std::string &content, const u64 toggle_key, const Color clr)
void SetFont(const std::string &font_name)
void SetX(const i32 x)
Definition: elm_Toggle.hpp:50
u64 GetKey()
Definition: elm_Toggle.hpp:78
static constexpr u32 ContentHorizontalMargin
Definition: elm_Toggle.hpp:21
std::string GetContent()
Definition: elm_Toggle.hpp:65
bool IsChecked()
Definition: elm_Toggle.hpp:86
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override
void SetKey(const u64 toggle_key)
Definition: elm_Toggle.hpp:82
i32 GetY() override
Definition: elm_Toggle.hpp:54
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override
static constexpr u8 ToggleAlphaIncrement
Definition: elm_Toggle.hpp:24
void SetColor(const Color clr)
void SetContent(const std::string &content)
i32 GetHeight() override
static constexpr Color MakeBackgroundColor(const u8 alpha)
Definition: elm_Toggle.hpp:26
i32 GetWidth() override
i32 GetX() override
Definition: elm_Toggle.hpp:46
static constexpr u32 ContentVerticalMargin
Definition: elm_Toggle.hpp:22
Color GetColor()
Definition: elm_Toggle.hpp:72
void SetY(const i32 y)
Definition: elm_Toggle.hpp:58
SDL_Texture * Texture
Definition: sdl2_Types.hpp:11
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