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

ui_Layout.hpp
Go to the documentation of this file.
/*
Plutonium library
@file ui_Layout.hpp
@brief Contains pu::Layout class, the object used to render within applications
@author XorTroll
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
*/
#pragma once
#include <pu/ui/ui_Container.hpp>
#include <functional>
namespace pu::ui {
class Layout : public Container {
public:
using OnInputCallback = std::function<void(const u64, const u64, const u64, const TouchPoint)>;
using RenderCallback = std::function<void()>;
static constexpr Color DefaultBackgroundColor = { 0xE1, 0xE1, 0xE1, 0xFF };
private:
bool has_image;
Color over_bg_color;
TouchPoint sim_touch_pos;
sdl2::Texture over_bg_tex;
OnInputCallback on_ipt;
std::vector<RenderCallback> render_cbs;
public:
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() {}
PU_SMART_CTOR(Layout)
~Layout();
inline bool HasChildren() {
return !this->elems.empty();
}
inline void SetOnInput(OnInputCallback on_ipt_cb) {
this->on_ipt = on_ipt_cb;
}
inline OnInputCallback GetOnInput() {
return this->on_ipt;
}
inline void AddRenderCallback(RenderCallback render_cb) {
this->render_cbs.push_back(render_cb);
}
inline std::vector<RenderCallback> &GetRenderCallbacks() {
return this->render_cbs;
}
inline bool HasBackgroundImage() {
return this->has_image;
}
inline sdl2::Texture GetBackgroundImageTexture() {
return this->over_bg_tex;
}
inline Color GetBackgroundColor() {
return this->over_bg_color;
}
void SetBackgroundImage(const std::string &path);
void SetBackgroundColor(const Color clr);
inline void SimulateTouchPosition(const TouchPoint sim_touch_pos) {
this->sim_touch_pos = sim_touch_pos;
}
TouchPoint ConsumeSimulatedTouchPosition();
};
}
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