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

ui_Dialog.hpp
Go to the documentation of this file.
/*
Plutonium library
@file ui_Dialog.hpp
@brief A Dialog is an easy way to ask the user to choose between several options.
@author XorTroll
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
*/
#pragma once
#include <pu/ui/render/render_Renderer.hpp>
#include <vector>
namespace pu::ui {
class Application;
class Dialog {
public:
static constexpr Color DefaultTitleColor = { 0xA, 0xA, 0xA, 0xFF };
static constexpr Color DefaultContentColor = { 0x14, 0x14, 0x14, 0xFF };
static constexpr Color DefaultOptionColor = { 0xA, 0xA, 0xA, 0xFF };
static constexpr u32 DialogExtraBaseWidth = 250;
static constexpr u32 DialogBorderRadius = 35;
static constexpr u32 SpaceBetweenOptions = 20;
static constexpr u32 TitleExtraWidth = 90;
static constexpr u32 ContentExtraWidth = 90;
static constexpr u32 SpaceBetweenContentAndOptions = 140;
static constexpr u32 TitleTopMargin = 20;
static constexpr u32 TitleX = 45;
static constexpr u32 TitleY = 55;
static constexpr u32 ContentX = 45;
static constexpr u32 ContentY = 140;
static constexpr u32 IconExtraHeight = 25;
static constexpr u32 OptionsBaseHorizontalMargin = 45;
static constexpr u32 OptionHeight = 60;
static constexpr u32 OptionHorizontalMargin = 30;
static constexpr u32 OptionBorderRadius = OptionHeight / 3;
static constexpr u32 OptionBottomMargin = 25;
static constexpr u8 MaxScreenFadeAlpha = 125;
static constexpr u32 IconMargin = 30;
static inline constexpr Color MakeDialogColor(const u8 alpha) {
return { 0xE1, 0xE1, 0xE1, alpha };
}
static inline constexpr Color MakeOverColor(const u8 alpha) {
return { 0xB4, 0xB4, 0xC8, alpha };
}
static constexpr u8 OverAlphaIncrement = 48;
static constexpr u8 FadeAlphaIncrement = 25;
private:
std::string title_font_name;
std::string cnt_font_name;
std::string opt_font_name;
std::string title;
std::string cnt;
sdl2::Texture title_tex;
sdl2::Texture cnt_tex;
std::vector<std::string> opts;
std::vector<sdl2::Texture> opt_texs;
std::string cancel_opt;
i32 selected_opt_idx;
i32 selected_opt_over_alpha;
i32 prev_selected_opt_idx;
i32 prev_selected_opt_over_alpha;
bool user_cancelled;
sdl2::Texture icon_tex;
public:
Dialog(const std::string &title, const std::string &content);
PU_SMART_CTOR(Dialog)
~Dialog();
void AddOption(const std::string &opt_name);
inline void SetCancelOption(const std::string &opt_name) {
this->cancel_opt = opt_name;
}
inline void RemoveCancelOption() {
this->SetCancelOption("");
}
inline bool HasCancelOption() {
return !this->cancel_opt.empty();
}
void SetIcon(const std::string &icon_path);
inline constexpr bool HasIcon() {
return this->icon_tex != nullptr;
}
i32 Show(Application *app_ref);
inline constexpr bool UserCancelled() {
return this->user_cancelled;
}
inline bool IsOk() {
if(this->user_cancelled) {
return false;
}
if(this->HasCancelOption() && (this->selected_opt_idx == (this->opt_texs.size() - 1))) {
return false;
}
return true;
}
};
}
pu::ui::Application
Definition: ui_Application.hpp:22
pu::ui::Dialog
Definition: ui_Dialog.hpp:22
pu::ui::Dialog::MaxScreenFadeAlpha
static constexpr u8 MaxScreenFadeAlpha
Definition: ui_Dialog.hpp:51
pu::ui::Dialog::DefaultTitleColor
static constexpr Color DefaultTitleColor
Definition: ui_Dialog.hpp:24
pu::ui::Dialog::UserCancelled
constexpr bool UserCancelled()
Definition: ui_Dialog.hpp:111
pu::ui::Dialog::ContentY
static constexpr u32 ContentY
Definition: ui_Dialog.hpp:41
pu::ui::Dialog::SetCancelOption
void SetCancelOption(const std::string &opt_name)
Definition: ui_Dialog.hpp:91
pu::ui::Dialog::HasCancelOption
bool HasCancelOption()
Definition: ui_Dialog.hpp:99
pu::ui::Dialog::MakeOverColor
static constexpr Color MakeOverColor(const u8 alpha)
Definition: ui_Dialog.hpp:59
pu::ui::Dialog::IconMargin
static constexpr u32 IconMargin
Definition: ui_Dialog.hpp:53
pu::ui::Dialog::OptionHorizontalMargin
static constexpr u32 OptionHorizontalMargin
Definition: ui_Dialog.hpp:47
pu::ui::Dialog::OptionBorderRadius
static constexpr u32 OptionBorderRadius
Definition: ui_Dialog.hpp:48
pu::ui::Dialog::DefaultContentColor
static constexpr Color DefaultContentColor
Definition: ui_Dialog.hpp:25
pu::ui::Dialog::TitleExtraWidth
static constexpr u32 TitleExtraWidth
Definition: ui_Dialog.hpp:33
pu::ui::Dialog::TitleTopMargin
static constexpr u32 TitleTopMargin
Definition: ui_Dialog.hpp:36
pu::ui::Dialog::~Dialog
~Dialog()
pu::ui::Dialog::Show
i32 Show(Application *app_ref)
pu::ui::Dialog::DialogExtraBaseWidth
static constexpr u32 DialogExtraBaseWidth
Definition: ui_Dialog.hpp:28
pu::ui::Dialog::OptionBottomMargin
static constexpr u32 OptionBottomMargin
Definition: ui_Dialog.hpp:49
pu::ui::Dialog::OptionHeight
static constexpr u32 OptionHeight
Definition: ui_Dialog.hpp:46
pu::ui::Dialog::SpaceBetweenContentAndOptions
static constexpr u32 SpaceBetweenContentAndOptions
Definition: ui_Dialog.hpp:35
pu::ui::Dialog::OptionsBaseHorizontalMargin
static constexpr u32 OptionsBaseHorizontalMargin
Definition: ui_Dialog.hpp:45
pu::ui::Dialog::TitleY
static constexpr u32 TitleY
Definition: ui_Dialog.hpp:39
pu::ui::Dialog::RemoveCancelOption
void RemoveCancelOption()
Definition: ui_Dialog.hpp:95
pu::ui::Dialog::OverAlphaIncrement
static constexpr u8 OverAlphaIncrement
Definition: ui_Dialog.hpp:63
pu::ui::Dialog::AddOption
void AddOption(const std::string &opt_name)
pu::ui::Dialog::SpaceBetweenOptions
static constexpr u32 SpaceBetweenOptions
Definition: ui_Dialog.hpp:31
pu::ui::Dialog::MakeDialogColor
static constexpr Color MakeDialogColor(const u8 alpha)
Definition: ui_Dialog.hpp:55
pu::ui::Dialog::HasIcon
constexpr bool HasIcon()
Definition: ui_Dialog.hpp:105
pu::ui::Dialog::IconExtraHeight
static constexpr u32 IconExtraHeight
Definition: ui_Dialog.hpp:43
pu::ui::Dialog::TitleX
static constexpr u32 TitleX
Definition: ui_Dialog.hpp:38
pu::ui::Dialog::DialogBorderRadius
static constexpr u32 DialogBorderRadius
Definition: ui_Dialog.hpp:29
pu::ui::Dialog::ContentX
static constexpr u32 ContentX
Definition: ui_Dialog.hpp:40
pu::ui::Dialog::DefaultOptionColor
static constexpr Color DefaultOptionColor
Definition: ui_Dialog.hpp:26
pu::ui::Dialog::FadeAlphaIncrement
static constexpr u8 FadeAlphaIncrement
Definition: ui_Dialog.hpp:64
pu::ui::Dialog::ContentExtraWidth
static constexpr u32 ContentExtraWidth
Definition: ui_Dialog.hpp:34
pu::ui::Dialog::IsOk
bool IsOk()
Definition: ui_Dialog.hpp:115
pu::ui::Dialog::SetIcon
void SetIcon(const std::string &icon_path)
pu::ui::Dialog::Dialog
Dialog(const std::string &title, const std::string &content)
pu::sdl2::Texture
SDL_Texture * Texture
Definition: sdl2_Types.hpp:11
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
render_Renderer.hpp
pu::ui::Color
Definition: ui_Types.hpp:44