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

ui_Application.hpp
Go to the documentation of this file.
/*
Plutonium library
@file ui_Application.hpp
@brief An Application is the base to use the UI system of this library.
@author XorTroll
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
*/
#pragma once
#include <pu/ui/ui_Dialog.hpp>
#include <pu/ui/ui_Layout.hpp>
#include <pu/ui/ui_Overlay.hpp>
#include <chrono>
namespace pu::ui {
class Application {
public:
using OnInputCallback = std::function<void(const u64, const u64, const u64, const TouchPoint)>;
using RenderCallback = std::function<void()>;
using RenderOverFunction = std::function<bool(render::Renderer::Ref&)>;
static constexpr u8 DefaultFadeAlphaIncrement = 35;
protected:
bool loaded;
bool in_render_over;
RenderOverFunction render_over_fn;
bool is_shown;
u8 fade_alpha_increment;
i32 fade_alpha;
Layout::Ref lyt;
Overlay::Ref ovl;
u64 ovl_timeout_ms;
std::chrono::steady_clock::time_point ovl_start_time;
std::vector<RenderCallback> render_cbs;
OnInputCallback on_ipt_cb;
render::Renderer::Ref renderer;
PadState input_pad;
public:
Application(render::Renderer::Ref renderer);
PU_SMART_CTOR(Application)
inline void LoadLayout(Layout::Ref lyt) {
this->lyt = lyt;
}
template<typename L>
inline std::shared_ptr<L> GetLayout() {
static_assert(std::is_base_of_v<ui::Layout, L>);
return std::static_pointer_cast<L>(this->lyt);
}
void Prepare();
// Force create a derived Application class which initializes everything here
virtual void OnLoad() = 0;
inline void AddRenderCallback(RenderCallback render_cb) {
this->render_cbs.push_back(render_cb);
}
inline void SetOnInput(OnInputCallback on_ipt_cb) {
this->on_ipt_cb = on_ipt_cb;
}
inline i32 ShowDialog(Dialog::Ref &dialog) {
return dialog->Show(this);
}
i32 CreateShowDialog(const std::string &title, const std::string &content, const std::vector<std::string> &opts, const bool use_last_opt_as_cancel, const std::string &icon_path = "");
inline void StartOverlay(Overlay::Ref ovl) {
if(this->ovl == nullptr) {
this->ovl = ovl;
}
}
void StartOverlayWithTimeout(Overlay::Ref ovl, const u64 ms);
void EndOverlay();
void Show();
inline void ShowWithFadeIn() {
this->FadeIn();
this->Show();
}
inline bool IsShown() {
return this->is_shown;
}
inline bool CanBeShown() {
return this->loaded && (this->lyt != nullptr);
}
bool CallForRender();
bool CallForRenderWithRenderOver(RenderOverFunction render_over_fn);
void FadeIn();
void FadeOut();
inline bool IsFadedIn() {
return this->fade_alpha > 0;
}
inline void SetFadeAlphaIncrement(const u8 fade_alpha_increment) {
this->fade_alpha_increment = fade_alpha_increment;
}
void OnRender();
void Close();
inline void CloseWithFadeOut() {
this->FadeOut();
this->Close();
}
inline u64 GetButtonsDown() {
return padGetButtonsDown(&this->input_pad);
}
inline u64 GetButtonsUp() {
return padGetButtonsUp(&this->input_pad);
}
inline u64 GetButtonsHeld() {
return padGetButtons(&this->input_pad);
}
inline HidTouchScreenState GetTouchState() {
HidTouchScreenState state = {};
hidGetTouchScreenStates(&state, 1);
return state;
}
};
}
pu::ui::Application
Definition: ui_Application.hpp:22
pu::ui::Application::OnRender
void OnRender()
pu::ui::Application::IsShown
bool IsShown()
Definition: ui_Application.hpp:94
pu::ui::Application::is_shown
bool is_shown
Definition: ui_Application.hpp:34
pu::ui::Application::render_cbs
std::vector< RenderCallback > render_cbs
Definition: ui_Application.hpp:41
pu::ui::Application::GetTouchState
HidTouchScreenState GetTouchState()
Definition: ui_Application.hpp:135
pu::ui::Application::OnLoad
virtual void OnLoad()=0
pu::ui::Application::CallForRender
bool CallForRender()
pu::ui::Application::on_ipt_cb
OnInputCallback on_ipt_cb
Definition: ui_Application.hpp:42
pu::ui::Application::RenderOverFunction
std::function< bool(render::Renderer::Ref &)> RenderOverFunction
Definition: ui_Application.hpp:26
pu::ui::Application::Application
Application(render::Renderer::Ref renderer)
pu::ui::Application::lyt
Layout::Ref lyt
Definition: ui_Application.hpp:37
pu::ui::Application::StartOverlay
void StartOverlay(Overlay::Ref ovl)
Definition: ui_Application.hpp:79
pu::ui::Application::StartOverlayWithTimeout
void StartOverlayWithTimeout(Overlay::Ref ovl, const u64 ms)
pu::ui::Application::GetButtonsDown
u64 GetButtonsDown()
Definition: ui_Application.hpp:123
pu::ui::Application::CloseWithFadeOut
void CloseWithFadeOut()
Definition: ui_Application.hpp:118
pu::ui::Application::GetButtonsUp
u64 GetButtonsUp()
Definition: ui_Application.hpp:127
pu::ui::Application::GetButtonsHeld
u64 GetButtonsHeld()
Definition: ui_Application.hpp:131
pu::ui::Application::CanBeShown
bool CanBeShown()
Definition: ui_Application.hpp:98
pu::ui::Application::FadeOut
void FadeOut()
pu::ui::Application::SetFadeAlphaIncrement
void SetFadeAlphaIncrement(const u8 fade_alpha_increment)
Definition: ui_Application.hpp:111
pu::ui::Application::FadeIn
void FadeIn()
pu::ui::Application::fade_alpha_increment
u8 fade_alpha_increment
Definition: ui_Application.hpp:35
pu::ui::Application::AddRenderCallback
void AddRenderCallback(RenderCallback render_cb)
Definition: ui_Application.hpp:65
pu::ui::Application::ShowWithFadeIn
void ShowWithFadeIn()
Definition: ui_Application.hpp:89
pu::ui::Application::DefaultFadeAlphaIncrement
static constexpr u8 DefaultFadeAlphaIncrement
Definition: ui_Application.hpp:28
pu::ui::Application::input_pad
PadState input_pad
Definition: ui_Application.hpp:44
pu::ui::Application::CreateShowDialog
i32 CreateShowDialog(const std::string &title, const std::string &content, const std::vector< std::string > &opts, const bool use_last_opt_as_cancel, const std::string &icon_path="")
pu::ui::Application::RenderCallback
std::function< void()> RenderCallback
Definition: ui_Application.hpp:25
pu::ui::Application::EndOverlay
void EndOverlay()
pu::ui::Application::in_render_over
bool in_render_over
Definition: ui_Application.hpp:32
pu::ui::Application::fade_alpha
i32 fade_alpha
Definition: ui_Application.hpp:36
pu::ui::Application::SetOnInput
void SetOnInput(OnInputCallback on_ipt_cb)
Definition: ui_Application.hpp:69
pu::ui::Application::Close
void Close()
pu::ui::Application::loaded
bool loaded
Definition: ui_Application.hpp:31
pu::ui::Application::GetLayout
std::shared_ptr< L > GetLayout()
Definition: ui_Application.hpp:55
pu::ui::Application::Prepare
void Prepare()
pu::ui::Application::IsFadedIn
bool IsFadedIn()
Definition: ui_Application.hpp:107
pu::ui::Application::ovl
Overlay::Ref ovl
Definition: ui_Application.hpp:38
pu::ui::Application::render_over_fn
RenderOverFunction render_over_fn
Definition: ui_Application.hpp:33
pu::ui::Application::ovl_timeout_ms
u64 ovl_timeout_ms
Definition: ui_Application.hpp:39
pu::ui::Application::CallForRenderWithRenderOver
bool CallForRenderWithRenderOver(RenderOverFunction render_over_fn)
pu::ui::Application::renderer
render::Renderer::Ref renderer
Definition: ui_Application.hpp:43
pu::ui::Application::LoadLayout
void LoadLayout(Layout::Ref lyt)
Definition: ui_Application.hpp:50
pu::ui::Application::ShowDialog
i32 ShowDialog(Dialog::Ref &dialog)
Definition: ui_Application.hpp:73
pu::ui::Application::Show
void Show()
pu::ui::Application::OnInputCallback
std::function< void(const u64, const u64, const u64, const TouchPoint)> OnInputCallback
Definition: ui_Application.hpp:24
pu::ui::Application::ovl_start_time
std::chrono::steady_clock::time_point ovl_start_time
Definition: ui_Application.hpp:40
pu::ui::Layout
Definition: ui_Layout.hpp:20
pu::ui
Definition: elm_Button.hpp:18
pu::i32
s32 i32
Definition: pu_Include.hpp:28
PU_SMART_CTOR
#define PU_SMART_CTOR(type)
Definition: pu_Include.hpp:19
pu::ui::TouchPoint
Definition: ui_Types.hpp:62
ui_Dialog.hpp
ui_Layout.hpp
ui_Overlay.hpp