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

ui_Types.hpp
Go to the documentation of this file.
/*
Plutonium library
@file ui_Types.hpp
@brief Several basic types helpful for UI and rendering, such as Color
@author XorTroll
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
*/
#pragma once
#include <pu/pu_Include.hpp>
namespace pu::ui {
// Font sizes Plutonium components use by default
enum class DefaultFontSize : u32 {
Small,
Medium,
MediumLarge,
Large,
Count
};
static inline constexpr std::array<u32, static_cast<u32>(DefaultFontSize::Count)> DefaultFontSizes = { 18, 20, 25, 30 };
inline std::string MakeDefaultFontName(const u32 font_size) {
return "DefaultFont@" + std::to_string(font_size);
}
inline constexpr u32 GetDefaultFontSize(const DefaultFontSize kind) {
return DefaultFontSizes[static_cast<u32>(kind)];
}
inline std::string GetDefaultFont(const DefaultFontSize kind) {
return MakeDefaultFontName(GetDefaultFontSize(kind));
}
struct Color {
u8 r;
u8 g;
u8 b;
u8 a;
constexpr Color() : r(0), g(0), b(0), a(0xFF) {}
constexpr Color(const u8 r, const u8 g, const u8 b, const u8 a) : r(r), g(g), b(b), a(a) {}
static Color FromHex(const std::string &str_clr);
};
static inline constexpr bool TouchHitsRegion(const i32 touch_x, const i32 touch_y, const i32 region_x, const i32 region_y, const i32 region_w, const i32 region_h) {
return (touch_x >= region_x) && (touch_x < (region_x + region_w)) && (touch_y >= region_y) && (touch_y < (region_y + region_h));
}
constexpr u64 TouchPseudoKey = HidNpadButton_29;
struct TouchPoint {
i32 x;
i32 y;
constexpr TouchPoint() : x(-1), y(-1) {}
constexpr TouchPoint(const u32 x, const u32 y) : x(x), y(y) {}
inline constexpr bool IsEmpty() const {
return (this->x < 0) && (this->y < 0);
}
inline constexpr bool HitsRegion(const i32 region_x, const i32 region_y, const i32 region_w, const i32 region_h) const {
if(this->IsEmpty()) {
return false;
}
return TouchHitsRegion(this->x, this->y, region_x, region_y, region_w, region_h);
}
};
}
pu::ui
Definition: elm_Button.hpp:18
pu::ui::TouchHitsRegion
static constexpr bool TouchHitsRegion(const i32 touch_x, const i32 touch_y, const i32 region_x, const i32 region_y, const i32 region_w, const i32 region_h)
Definition: ui_Types.hpp:56
pu::ui::MakeDefaultFontName
std::string MakeDefaultFontName(const u32 font_size)
Definition: ui_Types.hpp:32
pu::ui::TouchPseudoKey
constexpr u64 TouchPseudoKey
Definition: ui_Types.hpp:60
pu::ui::GetDefaultFontSize
constexpr u32 GetDefaultFontSize(const DefaultFontSize kind)
Definition: ui_Types.hpp:36
pu::ui::GetDefaultFont
std::string GetDefaultFont(const DefaultFontSize kind)
Definition: ui_Types.hpp:40
pu::ui::DefaultFontSizes
static constexpr std::array< u32, static_cast< u32 >(DefaultFontSize::Count)> DefaultFontSizes
Definition: ui_Types.hpp:30
pu::ui::DefaultFontSize
DefaultFontSize
Definition: ui_Types.hpp:21
pu::ui::DefaultFontSize::Small
@ Small
pu::ui::DefaultFontSize::Large
@ Large
pu::ui::DefaultFontSize::MediumLarge
@ MediumLarge
pu::ui::DefaultFontSize::Medium
@ Medium
pu::ui::DefaultFontSize::Count
@ Count
pu::i32
s32 i32
Definition: pu_Include.hpp:28
pu_Include.hpp
pu::ui::Color
Definition: ui_Types.hpp:44
pu::ui::Color::FromHex
static Color FromHex(const std::string &str_clr)
pu::ui::Color::g
u8 g
Definition: ui_Types.hpp:46
pu::ui::Color::a
u8 a
Definition: ui_Types.hpp:48
pu::ui::Color::r
u8 r
Definition: ui_Types.hpp:45
pu::ui::Color::Color
constexpr Color()
Definition: ui_Types.hpp:50
pu::ui::Color::b
u8 b
Definition: ui_Types.hpp:47
pu::ui::Color::Color
constexpr Color(const u8 r, const u8 g, const u8 b, const u8 a)
Definition: ui_Types.hpp:51
pu::ui::TouchPoint
Definition: ui_Types.hpp:62
pu::ui::TouchPoint::y
i32 y
Definition: ui_Types.hpp:64
pu::ui::TouchPoint::TouchPoint
constexpr TouchPoint(const u32 x, const u32 y)
Definition: ui_Types.hpp:67
pu::ui::TouchPoint::TouchPoint
constexpr TouchPoint()
Definition: ui_Types.hpp:66
pu::ui::TouchPoint::HitsRegion
constexpr bool HitsRegion(const i32 region_x, const i32 region_y, const i32 region_w, const i32 region_h) const
Definition: ui_Types.hpp:73
pu::ui::TouchPoint::x
i32 x
Definition: ui_Types.hpp:63
pu::ui::TouchPoint::IsEmpty
constexpr bool IsEmpty() const
Definition: ui_Types.hpp:69