# Plutonium framework API: Plutonium/include/pu/ui/elm/elm_Toggle.hpp Source File

elm_Toggle.hpp
Go to the documentation of this file.
/*
Plutonium library
@file Toggle.hpp
@brief A Toggle is an Element used to switch between two options by toggling the item.
@author XorTroll
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
*/
#pragma once
#include <pu/ui/elm/elm_Element.hpp>
namespace pu::ui::elm {
class Toggle : public Element {
public:
static constexpr u32 ContentHorizontalMargin = 30;
static constexpr u32 ContentVerticalMargin = 20;
static constexpr u8 ToggleAlphaIncrement = 48;
static constexpr Color MakeBackgroundColor(const u8 alpha) {
return { 130, 130, 130, alpha };
}
private:
i32 x;
i32 y;
u64 key;
bool checked;
Color clr;
std::string fnt_name;
i32 toggle_alpha;
std::string cnt;
sdl2::Texture cnt_tex;
public:
Toggle(const i32 x, const i32 y, const std::string &content, const u64 toggle_key, const Color clr);
PU_SMART_CTOR(Toggle)
~Toggle();
inline i32 GetX() override {
return this->x;
}
inline void SetX(const i32 x) {
this->x = x;
}
inline i32 GetY() override {
return this->y;
}
inline void SetY(const i32 y) {
this->y = y;
}
i32 GetWidth() override;
i32 GetHeight() override;
inline std::string GetContent() {
return this->cnt;
}
void SetContent(const std::string &content);
void SetFont(const std::string &font_name);
inline Color GetColor() {
return this->clr;
}
void SetColor(const Color clr);
inline u64 GetKey() {
return this->key;
}
inline void SetKey(const u64 toggle_key) {
this->key = toggle_key;
}
inline bool IsChecked() {
return this->checked;
}
void OnRender(render::Renderer::Ref &drawer, const i32 x, const i32 y) override;
void OnInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos) override;
};
}
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