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
15#include <pu/ui/elm/elm_Element.hpp>
16
17 namespace 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);
43 PU_SMART_CTOR(Toggle)
44 ~Toggle();
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}
pu::ui::elm::Element
Definition: elm_Element.hpp:37
pu::ui::elm::Toggle
Definition: elm_Toggle.hpp:19
pu::ui::elm::Toggle::Toggle
Toggle(const i32 x, const i32 y, const std::string &content, const u64 toggle_key, const Color clr)
pu::ui::elm::Toggle::SetFont
void SetFont(const std::string &font_name)
pu::ui::elm::Toggle::SetX
void SetX(const i32 x)
Definition: elm_Toggle.hpp:50
pu::ui::elm::Toggle::GetKey
u64 GetKey()
Definition: elm_Toggle.hpp:78
pu::ui::elm::Toggle::ContentHorizontalMargin
static constexpr u32 ContentHorizontalMargin
Definition: elm_Toggle.hpp:21
pu::ui::elm::Toggle::~Toggle
~Toggle()
pu::ui::elm::Toggle::GetContent
std::string GetContent()
Definition: elm_Toggle.hpp:65
pu::ui::elm::Toggle::IsChecked
bool IsChecked()
Definition: elm_Toggle.hpp:86
pu::ui::elm::Toggle::OnRender
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override
pu::ui::elm::Toggle::SetKey
void SetKey(const u64 toggle_key)
Definition: elm_Toggle.hpp:82
pu::ui::elm::Toggle::GetY
i32 GetY() override
Definition: elm_Toggle.hpp:54
pu::ui::elm::Toggle::OnInput
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override
pu::ui::elm::Toggle::ToggleAlphaIncrement
static constexpr u8 ToggleAlphaIncrement
Definition: elm_Toggle.hpp:24
pu::ui::elm::Toggle::SetColor
void SetColor(const Color clr)
pu::ui::elm::Toggle::SetContent
void SetContent(const std::string &content)
pu::ui::elm::Toggle::GetHeight
i32 GetHeight() override
pu::ui::elm::Toggle::MakeBackgroundColor
static constexpr Color MakeBackgroundColor(const u8 alpha)
Definition: elm_Toggle.hpp:26
pu::ui::elm::Toggle::GetWidth
i32 GetWidth() override
pu::ui::elm::Toggle::GetX
i32 GetX() override
Definition: elm_Toggle.hpp:46
pu::ui::elm::Toggle::ContentVerticalMargin
static constexpr u32 ContentVerticalMargin
Definition: elm_Toggle.hpp:22
pu::ui::elm::Toggle::GetColor
Color GetColor()
Definition: elm_Toggle.hpp:72
pu::ui::elm::Toggle::SetY
void SetY(const i32 y)
Definition: elm_Toggle.hpp:58
elm_Element.hpp
pu::sdl2::Texture
SDL_Texture * Texture
Definition: sdl2_Types.hpp:11
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