Plutonium framework API 0.3.0 UI framework libraries for libnx

ui_Layout.hpp
Go to the documentation of this file.
1
2/*
3
4 Plutonium library
5
6 @file ui_Layout.hpp
7 @brief Contains pu::Layout class, the object used to render within applications
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/ui_Container.hpp>
16#include <functional>
17
18 namespace pu::ui {
19
20 class Layout : public Container {
21 public:
22 using OnInputCallback = std::function<void(const u64, const u64, const u64, const TouchPoint)>;
23 using RenderCallback = std::function<void()>;
24
25 static constexpr Color DefaultBackgroundColor = { 0xE1, 0xE1, 0xE1, 0xFF };
26
27 private:
28 bool has_image;
29 Color over_bg_color;
30 TouchPoint sim_touch_pos;
31 sdl2::Texture over_bg_tex;
32 OnInputCallback on_ipt;
33 std::vector<RenderCallback> render_cbs;
34
35 public:
36 Layout() : Container(0, 0, render::ScreenWidth, render::ScreenHeight), has_image(false), over_bg_color(DefaultBackgroundColor), sim_touch_pos(), over_bg_tex(), on_ipt(), render_cbs() {}
37 PU_SMART_CTOR(Layout)
38 ~Layout();
39
40 inline bool HasChildren() {
41 return !this->elems.empty();
42 }
43
44 inline void SetOnInput(OnInputCallback on_ipt_cb) {
45 this->on_ipt = on_ipt_cb;
46 }
47
48 inline OnInputCallback GetOnInput() {
49 return this->on_ipt;
50 }
51
52 inline void AddRenderCallback(RenderCallback render_cb) {
53 this->render_cbs.push_back(render_cb);
54 }
55
56 inline std::vector<RenderCallback> &GetRenderCallbacks() {
57 return this->render_cbs;
58 }
59
60 inline bool HasBackgroundImage() {
61 return this->has_image;
62 }
63
64 inline sdl2::Texture GetBackgroundImageTexture() {
65 return this->over_bg_tex;
66 }
67
68 inline Color GetBackgroundColor() {
69 return this->over_bg_color;
70 }
71
72 void SetBackgroundImage(const std::string &path);
73 void SetBackgroundColor(const Color clr);
74
75 inline void SimulateTouchPosition(const TouchPoint sim_touch_pos) {
76 this->sim_touch_pos = sim_touch_pos;
77 }
78
79 TouchPoint ConsumeSimulatedTouchPosition();
80 };
81
82}
pu::ui::Container
Definition: ui_Container.hpp:21
pu::ui::Container::elems
std::vector< elm::Element::Ref > elems
Definition: ui_Container.hpp:27
pu::ui::Layout
Definition: ui_Layout.hpp:20
pu::ui::Layout::AddRenderCallback
void AddRenderCallback(RenderCallback render_cb)
Definition: ui_Layout.hpp:52
pu::ui::Layout::HasBackgroundImage
bool HasBackgroundImage()
Definition: ui_Layout.hpp:60
pu::ui::Layout::SetOnInput
void SetOnInput(OnInputCallback on_ipt_cb)
Definition: ui_Layout.hpp:44
pu::ui::Layout::ConsumeSimulatedTouchPosition
TouchPoint ConsumeSimulatedTouchPosition()
pu::ui::Layout::HasChildren
bool HasChildren()
Definition: ui_Layout.hpp:40
pu::ui::Layout::SetBackgroundColor
void SetBackgroundColor(const Color clr)
pu::ui::Layout::OnInputCallback
std::function< void(const u64, const u64, const u64, const TouchPoint)> OnInputCallback
Definition: ui_Layout.hpp:22
pu::ui::Layout::GetBackgroundColor
Color GetBackgroundColor()
Definition: ui_Layout.hpp:68
pu::ui::Layout::RenderCallback
std::function< void()> RenderCallback
Definition: ui_Layout.hpp:23
pu::ui::Layout::GetRenderCallbacks
std::vector< RenderCallback > & GetRenderCallbacks()
Definition: ui_Layout.hpp:56
pu::ui::Layout::DefaultBackgroundColor
static constexpr Color DefaultBackgroundColor
Definition: ui_Layout.hpp:25
pu::ui::Layout::SimulateTouchPosition
void SimulateTouchPosition(const TouchPoint sim_touch_pos)
Definition: ui_Layout.hpp:75
pu::ui::Layout::~Layout
~Layout()
pu::ui::Layout::GetBackgroundImageTexture
sdl2::Texture GetBackgroundImageTexture()
Definition: ui_Layout.hpp:64
pu::ui::Layout::Layout
Layout()
Definition: ui_Layout.hpp:36
pu::ui::Layout::GetOnInput
OnInputCallback GetOnInput()
Definition: ui_Layout.hpp:48
pu::ui::Layout::SetBackgroundImage
void SetBackgroundImage(const std::string &path)
pu::sdl2::Texture
SDL_Texture * Texture
Definition: sdl2_Types.hpp:11
pu::ui::render::ScreenWidth
constexpr u32 ScreenWidth
Definition: render_Renderer.hpp:21
pu::ui::render::ScreenHeight
constexpr u32 ScreenHeight
Definition: render_Renderer.hpp:22
pu::ui
Definition: elm_Button.hpp:18
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
ui_Container.hpp