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
16#include <functional>
17
18namespace 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() {}
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
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
65 return this->over_bg_tex;
66 }
67
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
80 };
81
82}
Definition: ui_Container.hpp:21
std::vector< elm::Element::Ref > elems
Definition: ui_Container.hpp:27
Definition: ui_Layout.hpp:20
void AddRenderCallback(RenderCallback render_cb)
Definition: ui_Layout.hpp:52
bool HasBackgroundImage()
Definition: ui_Layout.hpp:60
void SetOnInput(OnInputCallback on_ipt_cb)
Definition: ui_Layout.hpp:44
TouchPoint ConsumeSimulatedTouchPosition()
bool HasChildren()
Definition: ui_Layout.hpp:40
void SetBackgroundColor(const Color clr)
std::function< void(const u64, const u64, const u64, const TouchPoint)> OnInputCallback
Definition: ui_Layout.hpp:22
Color GetBackgroundColor()
Definition: ui_Layout.hpp:68
std::function< void()> RenderCallback
Definition: ui_Layout.hpp:23
std::vector< RenderCallback > & GetRenderCallbacks()
Definition: ui_Layout.hpp:56
static constexpr Color DefaultBackgroundColor
Definition: ui_Layout.hpp:25
void SimulateTouchPosition(const TouchPoint sim_touch_pos)
Definition: ui_Layout.hpp:75
sdl2::Texture GetBackgroundImageTexture()
Definition: ui_Layout.hpp:64
Layout()
Definition: ui_Layout.hpp:36
OnInputCallback GetOnInput()
Definition: ui_Layout.hpp:48
void SetBackgroundImage(const std::string &path)
SDL_Texture * Texture
Definition: sdl2_Types.hpp:11
constexpr u32 ScreenWidth
Definition: render_Renderer.hpp:21
constexpr u32 ScreenHeight
Definition: render_Renderer.hpp:22
Definition: elm_Button.hpp:18
#define PU_SMART_CTOR(type)
Definition: pu_Include.hpp:19
Definition: ui_Types.hpp:44
Definition: ui_Types.hpp:62