Plutonium framework API 1.0.0
Easy-to-use, SDL2-based UI framework for Nintendo Switch homebrew
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pu::ui::Application Class Referenceabstract

Type that represents the basic object in this library, the general context for UI and rendering. More...

#include <ui_Application.hpp>

Public Types

using DialogPrepareCallback = std::function<void(Dialog::Ref&)>
 Function type used to further customize a Dialog (setting fields) when using Application::CreateShowDialog.
 
using OnInputCallback = std::function<void(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos)>
 Function type used to handle input events.
 
using RenderCallback = std::function<void()>
 Function type to be called every rendering loop/frame.
 
using RenderOverFunction = std::function<bool(render::Renderer::Ref&)>
 Function type to be called when rendering over the main rendering loop/frame.
 

Public Member Functions

 Application (render::Renderer::Ref renderer)
 Creates a new Application with the specified Renderer.
 
virtual ~Application ()
 
void LoadLayout (Layout::Ref lyt)
 Loads the Layout to be used by the Application.
 
template<typename L>
std::shared_ptr< L > GetLayout ()
 Gets the current Layout (of the specified type).
 
Result Load ()
 Loads the Application.
 
virtual void OnLoad ()=0
 Function to be implemented by child classes, called when the Application is loaded.
 
void AddRenderCallback (RenderCallback render_cb)
 Adds a RenderCallback to the Application.
 
void SetOnInput (OnInputCallback on_ipt_cb)
 Sets the OnInputCallback for the Application.
 
i32 ShowDialog (Dialog::Ref &dialog)
 Shows a Dialog and waits for the user to interact with it.
 
i32 CreateShowDialog (const std::string &title, const std::string &content, const std::vector< std::string > &opts, const bool use_last_opt_as_cancel, sdl2::TextureHandle::Ref icon={}, DialogPrepareCallback prepare_cb=nullptr)
 Wrapper function that creates a Dialog with the specified parameters and shows it.
 
void StartOverlay (Overlay::Ref ovl)
 Starts an Overlay.
 
void StartOverlayWithTimeout (Overlay::Ref ovl, const u64 ms)
 Starts an Overlay with a timeout.
 
void EndOverlay ()
 Ends the current Overlay.
 
void Show ()
 Shows the Application.
 
void ShowWithFadeIn ()
 Shows the Application with a fade-in effect.
 
bool IsShown ()
 Gets whether the Application is currently shown.
 
bool CanBeShown ()
 Gets whether the Application can be shown.
 
bool CallForRender ()
 Calls for rendering the Application.
 
bool CallForRenderWithRenderOver (RenderOverFunction render_over_fn)
 Calls for rendering the Application with a custom RenderOverFunction.
 
void LockRender ()
 Locks the rendering mutex.
 
void UnlockRender ()
 Unlocks the rendering mutex.
 
void FadeIn ()
 Starts and waits for a fade-in effect.
 
void FadeOut ()
 Starts and waits for a fade-out effect.
 
bool IsFadingOrFadedIn ()
 Gets whether the Application is currently fading in or already faded in.
 
void SetFadeAlphaIncrementStepCount (const u8 fade_alpha_increment_steps)
 Sets the number of steps for the fade-in and fade-out effects.
 
void SetFadeBackgroundImage (sdl2::TextureHandle::Ref bg_tex)
 Sets the target background image for the fade effect.
 
void ResetFadeBackgroundImage ()
 Resets the background image used for the fade effect.
 
sdl2::TextureHandle::Ref & GetFadeBackgroundImageTexture ()
 Gets the background image used for the fade effect.
 
bool HasFadeBackgroundImage ()
 Gets whether the fade effect is using a background image.
 
void SetFadeBackgroundColor (const Color clr)
 Sets the background color for the fade effect.
 
void Close (const bool do_exit=false)
 Closes the Application.
 
void CloseWithFadeOut (const bool do_exit=false)
 Closes the Application with a fade-out effect.
 
u64 GetButtonsDown ()
 Gets the currently pressed button keys.
 
u64 GetButtonsUp ()
 Gets the currently released button keys.
 
u64 GetButtonsHeld ()
 Gets the currently held button keys.
 
HidTouchScreenState GetTouchState ()
 Gets the currently pressed touch position.
 

Static Public Attributes

static constexpr u8 DefaultFadeAlphaIncrementSteps = 20
 

Protected Attributes

bool loaded
 
bool in_render_over
 
RenderOverFunction render_over_fn
 
bool is_shown
 
u8 fade_alpha_increment_steps
 
SigmoidIncrementer< i32fade_alpha_incr
 
i32 fade_alpha
 
sdl2::TextureHandle::Ref fade_bg_tex
 
Color fade_bg_clr
 
Layout::Ref lyt
 
Overlay::Ref ovl
 
u64 ovl_timeout_ms
 
std::chrono::steady_clock::time_point ovl_start_time
 
std::vector< RenderCallbackrender_cbs
 
OnInputCallback on_ipt_cb
 
render::Renderer::Ref renderer
 
RMutex render_lock
 

Detailed Description

Type that represents the basic object in this library, the general context for UI and rendering.

Member Typedef Documentation

◆ DialogPrepareCallback

using pu::ui::Application::DialogPrepareCallback = std::function<void(Dialog::Ref&)>

Function type used to further customize a Dialog (setting fields) when using Application::CreateShowDialog.

◆ OnInputCallback

using pu::ui::Application::OnInputCallback = std::function<void(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos)>

Function type used to handle input events.

Parameters
keys_downThe keys that were pressed in this frame.
keys_upThe keys that were released in this frame.
keys_heldThe keys that are being held in this frame.
touch_posThe position of the touch on the screen.

◆ RenderCallback

using pu::ui::Application::RenderCallback = std::function<void()>

Function type to be called every rendering loop/frame.

◆ RenderOverFunction

using pu::ui::Application::RenderOverFunction = std::function<bool(render::Renderer::Ref&)>

Function type to be called when rendering over the main rendering loop/frame.

Parameters
rendererThe Renderer instance to render over.
Returns
Whether the rendering loop/frame should continue.

Constructor & Destructor Documentation

◆ Application()

pu::ui::Application::Application ( render::Renderer::Ref renderer)

Creates a new Application with the specified Renderer.

Parameters
rendererThe Renderer to use for rendering.

◆ ~Application()

virtual pu::ui::Application::~Application ( )
virtual

Member Function Documentation

◆ AddRenderCallback()

void pu::ui::Application::AddRenderCallback ( RenderCallback render_cb)
inline

Adds a RenderCallback to the Application.

Parameters
render_cbThe RenderCallback to add.

◆ CallForRender()

bool pu::ui::Application::CallForRender ( )

Calls for rendering the Application.

Note
This is essentially the rendering code called every frame. This function may be used to create custom rendering loops, but be careful when using it.
Returns
Whether the rendering loop/frame should continue.

◆ CallForRenderWithRenderOver()

bool pu::ui::Application::CallForRenderWithRenderOver ( RenderOverFunction render_over_fn)

Calls for rendering the Application with a custom RenderOverFunction.

Parameters
render_over_fnThe RenderOverFunction to use.
Note
This function is useful when you want to render over the main rendering loop/frame. This logic is internally used with Dialog rendering.
Returns
Whether the rendering loop/frame should continue.

◆ CanBeShown()

bool pu::ui::Application::CanBeShown ( )
inline

Gets whether the Application can be shown.

Note
This function checks if the Application is loaded and if any Layout was set.
Returns
Whether the Application can be shown.

◆ Close()

void pu::ui::Application::Close ( const bool do_exit = false)

Closes the Application.

Parameters
do_exitWhether the program should fully exit after closing.
Note
This function will finish the Application and, if specified, exit the program using exit(0).

◆ CloseWithFadeOut()

void pu::ui::Application::CloseWithFadeOut ( const bool do_exit = false)
inline

Closes the Application with a fade-out effect.

Parameters
do_exitWhether the program should fully exit after closing.
Note
This function will finish the Application with a fade-out effect and, if specified, exit the program using exit(0).

◆ CreateShowDialog()

i32 pu::ui::Application::CreateShowDialog ( const std::string & title,
const std::string & content,
const std::vector< std::string > & opts,
const bool use_last_opt_as_cancel,
sdl2::TextureHandle::Ref icon = {},
DialogPrepareCallback prepare_cb = nullptr )

Wrapper function that creates a Dialog with the specified parameters and shows it.

Parameters
titleThe title of the Dialog.
contentThe content of the Dialog.
optsThe options of the Dialog.
use_last_opt_as_cancelWhether the last option should be used as a cancel option.
iconThe icon of the Dialog.
prepare_cbThe DialogPrepareCallback to further customize the Dialog.
Returns
The index of the option selected by the user.

◆ EndOverlay()

void pu::ui::Application::EndOverlay ( )

Ends the current Overlay.

◆ FadeIn()

void pu::ui::Application::FadeIn ( )

Starts and waits for a fade-in effect.

Note
This function will block until the fade-in effect is completed.

◆ FadeOut()

void pu::ui::Application::FadeOut ( )

Starts and waits for a fade-out effect.

Note
This function will block until the fade-out effect is completed.

◆ GetButtonsDown()

u64 pu::ui::Application::GetButtonsDown ( )
inline

Gets the currently pressed button keys.

Returns
The currently pressed button keys.

◆ GetButtonsHeld()

u64 pu::ui::Application::GetButtonsHeld ( )
inline

Gets the currently held button keys.

Returns
The currently held button keys.

◆ GetButtonsUp()

u64 pu::ui::Application::GetButtonsUp ( )
inline

Gets the currently released button keys.

Returns
The currently released button keys.

◆ GetFadeBackgroundImageTexture()

sdl2::TextureHandle::Ref & pu::ui::Application::GetFadeBackgroundImageTexture ( )
inline

Gets the background image used for the fade effect.

Returns
The background image used for the fade effect.

◆ GetLayout()

template<typename L>
std::shared_ptr< L > pu::ui::Application::GetLayout ( )
inline

Gets the current Layout (of the specified type).

Template Parameters
LThe type of Layout to get.
Returns
The Layout of the specified type.

◆ GetTouchState()

HidTouchScreenState pu::ui::Application::GetTouchState ( )
inline

Gets the currently pressed touch position.

Returns
The currently pressed touch position.

◆ HasFadeBackgroundImage()

bool pu::ui::Application::HasFadeBackgroundImage ( )
inline

Gets whether the fade effect is using a background image.

Returns
Whether the fade effect is using a background image.

◆ IsFadingOrFadedIn()

bool pu::ui::Application::IsFadingOrFadedIn ( )
inline

Gets whether the Application is currently fading in or already faded in.

Returns
Whether the Application is currently fading in or already faded in.

◆ IsShown()

bool pu::ui::Application::IsShown ( )
inline

Gets whether the Application is currently shown.

Returns
Whether the Application is currently shown.

◆ Load()

Result pu::ui::Application::Load ( )

Loads the Application.

Note
This function must be called before calling Application::Show or similar.
Returns
Whether the Application was loaded successfully.

◆ LoadLayout()

void pu::ui::Application::LoadLayout ( Layout::Ref lyt)
inline

Loads the Layout to be used by the Application.

Parameters
lytThe Layout to load.

◆ LockRender()

void pu::ui::Application::LockRender ( )
inline

Locks the rendering mutex.

◆ OnLoad()

virtual void pu::ui::Application::OnLoad ( )
pure virtual

Function to be implemented by child classes, called when the Application is loaded.

Note
This function must be implemented by the user.

◆ ResetFadeBackgroundImage()

void pu::ui::Application::ResetFadeBackgroundImage ( )

Resets the background image used for the fade effect.

Note
This function will reset the background image used for the fade effect, and the fade effect will use the set solid color instead.

◆ SetFadeAlphaIncrementStepCount()

void pu::ui::Application::SetFadeAlphaIncrementStepCount ( const u8 fade_alpha_increment_steps)
inline

Sets the number of steps for the fade-in and fade-out effects.

Parameters
fade_alpha_increment_stepsThe number of steps for the fade-in and fade-out effects.

◆ SetFadeBackgroundColor()

void pu::ui::Application::SetFadeBackgroundColor ( const Color clr)

Sets the background color for the fade effect.

Parameters
clrThe background color to use for the fade effect.
Note
Fade effects will start/end with the specified background color.
If a background image is set, this function will reset it.

◆ SetFadeBackgroundImage()

void pu::ui::Application::SetFadeBackgroundImage ( sdl2::TextureHandle::Ref bg_tex)

Sets the target background image for the fade effect.

Parameters
bg_texThe background image to use for the fade effect.
Note
Fade effects will start/end with the specified background image.

◆ SetOnInput()

void pu::ui::Application::SetOnInput ( OnInputCallback on_ipt_cb)
inline

Sets the OnInputCallback for the Application.

Parameters
on_ipt_cbThe OnInputCallback to set.

◆ Show()

void pu::ui::Application::Show ( )

Shows the Application.

Note
Application::Load must be called before calling this function, and the Layout must be previously set using Application::LoadLayout.
If no Layout was previously set or if the Application was not loaded yet, this function will inmediately return.

◆ ShowDialog()

i32 pu::ui::Application::ShowDialog ( Dialog::Ref & dialog)
inline

Shows a Dialog and waits for the user to interact with it.

Parameters
dialogThe Dialog to show.
Returns
The index of the option selected by the user.

◆ ShowWithFadeIn()

void pu::ui::Application::ShowWithFadeIn ( )
inline

Shows the Application with a fade-in effect.

Note
Application::Load must be called before calling this function, and the Layout must be previously set using Application::LoadLayout.
If no Layout was previously set or if the Application was not loaded yet, this function will inmediately return.

◆ StartOverlay()

void pu::ui::Application::StartOverlay ( Overlay::Ref ovl)
inline

Starts an Overlay.

Parameters
ovlThe Overlay to start.

◆ StartOverlayWithTimeout()

void pu::ui::Application::StartOverlayWithTimeout ( Overlay::Ref ovl,
const u64 ms )

Starts an Overlay with a timeout.

Parameters
ovlThe Overlay to start.
msThe timeout in milliseconds.

◆ UnlockRender()

void pu::ui::Application::UnlockRender ( )
inline

Unlocks the rendering mutex.

Member Data Documentation

◆ DefaultFadeAlphaIncrementSteps

u8 pu::ui::Application::DefaultFadeAlphaIncrementSteps = 20
staticconstexpr

◆ fade_alpha

i32 pu::ui::Application::fade_alpha
protected

◆ fade_alpha_incr

SigmoidIncrementer<i32> pu::ui::Application::fade_alpha_incr
protected

◆ fade_alpha_increment_steps

u8 pu::ui::Application::fade_alpha_increment_steps
protected

◆ fade_bg_clr

Color pu::ui::Application::fade_bg_clr
protected

◆ fade_bg_tex

sdl2::TextureHandle::Ref pu::ui::Application::fade_bg_tex
protected

◆ in_render_over

bool pu::ui::Application::in_render_over
protected

◆ is_shown

bool pu::ui::Application::is_shown
protected

◆ loaded

bool pu::ui::Application::loaded
protected

◆ lyt

Layout::Ref pu::ui::Application::lyt
protected

◆ on_ipt_cb

OnInputCallback pu::ui::Application::on_ipt_cb
protected

◆ ovl

Overlay::Ref pu::ui::Application::ovl
protected

◆ ovl_start_time

std::chrono::steady_clock::time_point pu::ui::Application::ovl_start_time
protected

◆ ovl_timeout_ms

u64 pu::ui::Application::ovl_timeout_ms
protected

◆ render_cbs

std::vector<RenderCallback> pu::ui::Application::render_cbs
protected

◆ render_lock

RMutex pu::ui::Application::render_lock
protected

◆ render_over_fn

RenderOverFunction pu::ui::Application::render_over_fn
protected

◆ renderer

render::Renderer::Ref pu::ui::Application::renderer
protected

The documentation for this class was generated from the following file: