Plutonium framework API 0.3.0
UI framework libraries for libnx
Loading...
Searching...
No Matches
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
17namespace pu::ui::elm {
18
19 class Toggle : public Element {
20 public:
21 static constexpr u32 DefaultContentHorizontalMargin = 30;
22 static constexpr u32 DefaultContentVerticalMargin = 20;
23
25
26 static constexpr u8 DefaultToggleAlphaIncrement = 48;
27
28 static constexpr Color DefaultBackgroundColor = { 130, 130, 130, 255 };
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 u32 cnt_h_margin;
41 u32 cnt_v_margin;
42 u8 toggle_alpha_incr;
43 Color bg_clr;
44
45 inline Color MakeBackgroundColor(const u8 alpha) {
46 return this->bg_clr.WithAlpha(alpha);
47 }
48
49 public:
50 Toggle(const i32 x, const i32 y, const std::string &content, const u64 toggle_key, const Color clr);
53
54 inline i32 GetX() override {
55 return this->x;
56 }
57
58 inline void SetX(const i32 x) {
59 this->x = x;
60 }
61
62 inline i32 GetY() override {
63 return this->y;
64 }
65
66 inline void SetY(const i32 y) {
67 this->y = y;
68 }
69
70 i32 GetWidth() override;
71 i32 GetHeight() override;
72
73 inline std::string GetContent() {
74 return this->cnt;
75 }
76
77 void SetContent(const std::string &content);
78 void SetFont(const std::string &font_name);
79
80 PU_CLASS_POD_GET(Color, clr, Color)
81
82 void SetColor(const Color clr);
83
84 PU_CLASS_POD_GETSET(Key, key, u64)
85
86 PU_CLASS_POD_GET(Checked, checked, bool)
87
88 void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override;
89 void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override;
90 };
91
92}
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:58
static constexpr Color DefaultBackgroundColor
Definition elm_Toggle.hpp:28
std::string GetContent()
Definition elm_Toggle.hpp:73
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override
i32 GetY() override
Definition elm_Toggle.hpp:62
static constexpr u32 DefaultContentVerticalMargin
Definition elm_Toggle.hpp:22
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override
void SetColor(const Color clr)
void SetContent(const std::string &content)
i32 GetHeight() override
static constexpr u8 DefaultToggleAlphaIncrement
Definition elm_Toggle.hpp:26
i32 GetWidth() override
i32 GetX() override
Definition elm_Toggle.hpp:54
static constexpr u32 DefaultContentHorizontalMargin
Definition elm_Toggle.hpp:21
static constexpr DefaultFontSize DefaultContentFontSize
Definition elm_Toggle.hpp:24
void SetY(const i32 y)
Definition elm_Toggle.hpp:66
Definition render_Renderer.hpp:127
Definition sdl2_Types.hpp:10
Definition render_Renderer.hpp:20
Definition elm_Button.hpp:18
DefaultFontSize
Definition ui_Types.hpp:21
#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