Plutonium framework API  0.3
Simple UI framework for libnx and SDL2
ui_Application.hpp
Go to the documentation of this file.
1 
2 /*
3 
4  Plutonium library
5 
6  @file ui_Application.hpp
7  @brief An Application is the base to use the UI system of this library.
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 <vector>
16 #include <functional>
17 #include <chrono>
18 #include <pu/ui/ui_Dialog.hpp>
19 #include <pu/ui/ui_Layout.hpp>
20 #include <pu/ui/ui_Overlay.hpp>
21 
22 namespace pu::ui
23 {
25  {
26  public:
27  Application(render::Renderer::Ref Renderer);
29 
30  template<typename Lyt>
31  void LoadLayout(std::shared_ptr<Lyt> Layout)
32  {
33  static_assert(std::is_base_of<ui::Layout, Lyt>::value, "Layouts must inherit from pu::ui::Layout!");
34 
35  this->lyt = std::dynamic_pointer_cast<ui::Layout>(Layout);
36  }
37 
38  void Prepare();
39  // Force create a derived Application which should initialize everything here
40  virtual void OnLoad() = 0;
41 
42  void AddThread(std::function<void()> Callback);
43  void SetOnInput(std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> Callback);
44  i32 ShowDialog(Dialog::Ref &ToShow);
45  int CreateShowDialog(String Title, String Content, std::vector<String> Options, bool UseLastOptionAsCancel, std::string Icon = "");
46 
47  template<typename Ovl>
48  void StartOverlay(std::shared_ptr<Ovl> Overlay)
49  {
50  static_assert(std::is_base_of<ui::Overlay, Ovl>::value, "Overlays must inherit from pu::ui::Overlay!");
51 
52  if(this->ovl == nullptr) this->ovl = std::dynamic_pointer_cast<ui::Overlay>(Overlay);
53  }
54 
55  template<typename Ovl>
56  void StartOverlayWithTimeout(std::shared_ptr<Ovl> Overlay, u64 Milli)
57  {
58  static_assert(std::is_base_of<ui::Overlay, Ovl>::value, "Overlays must inherit from pu::ui::Overlay!");
59 
60  if(this->ovl == nullptr)
61  {
62  this->ovl = std::dynamic_pointer_cast<ui::Overlay>(Overlay);
63  this->tmillis = Milli;
64  this->tclock = std::chrono::steady_clock::now();
65  }
66  }
67 
68  void EndOverlay();
69  void Show();
70  void ShowWithFadeIn();
71  bool IsShown();
72  bool CallForRender();
73  bool CallForRenderWithRenderOver(std::function<bool(render::Renderer::Ref&)> RenderFunc);
74  void FadeIn();
75  void FadeOut();
76  bool IsFadedIn();
77  void SetFadeAlphaAmountPerFrame(u8 Alpha);
78  void OnRender();
79  void Close();
80  void CloseWithFadeOut();
81  protected:
82  bool loaded;
83  bool rover;
84  std::function<bool(render::Renderer::Ref&)> rof;
85  bool show;
86  u8 aapf;
88  bool closefact;
89  Layout::Ref lyt;
90  u64 tmillis;
91  std::chrono::steady_clock::time_point tclock;
92  bool fovl;
93  bool ffovl;
94  Overlay::Ref ovl;
95  std::vector<std::function<void()>> thds;
96  std::function<void(u64, u64, u64, Touch)> cbipt;
97  render::Renderer::Ref rend;
98  };
99 }
Definition: pu_String.hpp:21
std::vector< std::function< void()> > thds
Definition: ui_Application.hpp:95
std::function< bool(render::Renderer::Ref &)> rof
Definition: ui_Application.hpp:84
bool ffovl
Definition: ui_Application.hpp:93
Definition: ui_Types.hpp:38
Layout::Ref lyt
Definition: ui_Application.hpp:89
Overlay::Ref ovl
Definition: ui_Application.hpp:94
i32 fadea
Definition: ui_Application.hpp:87
render::Renderer::Ref rend
Definition: ui_Application.hpp:97
void SetFadeAlphaAmountPerFrame(u8 Alpha)
virtual void OnLoad()=0
void LoadLayout(std::shared_ptr< Lyt > Layout)
Definition: ui_Application.hpp:31
bool closefact
Definition: ui_Application.hpp:88
s32 i32
Definition: pu_Macros.hpp:17
#define PU_SMART_CTOR(type)
Definition: pu_Macros.hpp:8
void AddThread(std::function< void()> Callback)
bool fovl
Definition: ui_Application.hpp:92
bool show
Definition: ui_Application.hpp:85
u8 aapf
Definition: ui_Application.hpp:86
void SetOnInput(std::function< void(u64 Down, u64 Up, u64 Held, Touch Pos)> Callback)
std::function< void(u64, u64, u64, Touch)> cbipt
Definition: ui_Application.hpp:96
std::chrono::steady_clock::time_point tclock
Definition: ui_Application.hpp:91
Application(render::Renderer::Ref Renderer)
Definition: ui_Layout.hpp:20
SDL_Renderer * Renderer
Definition: sdl2_Types.hpp:13
void StartOverlayWithTimeout(std::shared_ptr< Ovl > Overlay, u64 Milli)
Definition: ui_Application.hpp:56
bool rover
Definition: ui_Application.hpp:83
int CreateShowDialog(String Title, String Content, std::vector< String > Options, bool UseLastOptionAsCancel, std::string Icon="")
Definition: ui_Overlay.hpp:19
bool CallForRenderWithRenderOver(std::function< bool(render::Renderer::Ref &)> RenderFunc)
void StartOverlay(std::shared_ptr< Ovl > Overlay)
Definition: ui_Application.hpp:48
Definition: ui_Application.hpp:24
bool loaded
Definition: ui_Application.hpp:82
u64 tmillis
Definition: ui_Application.hpp:90
i32 ShowDialog(Dialog::Ref &ToShow)