Plutonium framework API 0.3.0
UI framework libraries for libnx
Loading...
Searching...
No Matches
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
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::TextureHandle::Ref 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() {}
38 virtual ~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
57 return this->render_cbs;
58 }
59
60 inline bool HasBackgroundImage() {
61 return this->over_bg_tex != nullptr;
62 }
63
65 return this->over_bg_tex;
66 }
67
69 return this->over_bg_color;
70 }
71
74 void SetBackgroundColor(const Color clr);
75
76 inline void SimulateTouchPosition(const TouchPoint sim_touch_pos) {
77 this->sim_touch_pos = sim_touch_pos;
78 }
79
81 };
82
83}
Definition sdl2_Types.hpp:18
Definition ui_Container.hpp:21
Definition ui_Layout.hpp:20
void AddRenderCallback(RenderCallback render_cb)
Definition ui_Layout.hpp:52
bool HasBackgroundImage()
Definition ui_Layout.hpp:60
void SetBackgroundImage(sdl2::TextureHandle::Ref bg_tex)
void SetOnInput(OnInputCallback on_ipt_cb)
Definition ui_Layout.hpp:44
TouchPoint ConsumeSimulatedTouchPosition()
void ResetBackgroundImage()
bool HasChildren()
Definition ui_Layout.hpp:40
void SetBackgroundColor(const Color clr)
virtual ~Layout()
Color GetBackgroundColor()
Definition ui_Layout.hpp:68
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:76
sdl2::TextureHandle::Ref & GetBackgroundImageTexture()
Definition ui_Layout.hpp:64
Layout()
Definition ui_Layout.hpp:36
OnInputCallback GetOnInput()
Definition ui_Layout.hpp:48
Definition sdl2_Types.hpp:10
#define PU_SMART_CTOR(type)
Definition pu_Include.hpp:20
Definition ui_Types.hpp:44
Definition ui_Types.hpp:67