Plutonium framework API 0.3.0
UI framework libraries for libnx
Loading...
Searching...
No Matches
ui_Dialog.hpp
Go to the documentation of this file.
1
2/*
3
4 Plutonium library
5
6 @file ui_Dialog.hpp
7 @brief A Dialog is an easy way to ask the user to choose between several options.
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 <pu/ui/render/render_Renderer.hpp>
16#include <vector>
17
18namespace pu::ui {
19
20 class Application;
21
22 class Dialog {
23 public:
24 static constexpr Color DefaultTitleColor = { 0xA, 0xA, 0xA, 0xFF };
25 static constexpr Color DefaultContentColor = { 0x14, 0x14, 0x14, 0xFF };
26 static constexpr Color DefaultOptionColor = { 0xA, 0xA, 0xA, 0xFF };
27
28 static constexpr u32 DefaultDialogExtraBaseWidth = 375;
29 static constexpr u32 DefaultDialogBorderRadius = 52;
30
31 static constexpr u32 DefaultSpaceBetweenOptions = 30;
32 static constexpr u32 DefaultSpaceBetweenOptionRows = 15;
33
34 static constexpr u32 DefaultTitleExtraWidth = 135;
35 static constexpr u32 DefaultContentExtraWidth = 135;
37 static constexpr u32 DefaultTitleTopMargin = 30;
38
39 static constexpr u32 DefaultTitleX = 67;
40 static constexpr u32 DefaultTitleY = 82;
41 static constexpr u32 DefaultContentX = 67;
42 static constexpr u32 DefaultContentY = 210;
43
44 static constexpr u32 DefaultIconExtraHeight = 37;
45
47 static constexpr u32 DefaultOptionHeight = 90;
48 static constexpr u32 DefaultOptionHorizontalMargin = 45;
50 static constexpr u32 DefaultOptionBottomMargin = 37;
51
52 static constexpr u8 DefaultMaxScreenFadeAlpha = 125;
53
54 static constexpr u32 DefaultIconMargin = 45;
55
56 static constexpr u8 DefaultOverAlphaIncrementSteps = 12;
57 static constexpr u8 DefaultFadeAlphaIncrementSteps = 18;
58
59 static constexpr Color DefaultDialogColor = { 0xE1, 0xE1, 0xE1, 0xFF };
60 static constexpr Color DefaultOverColor = { 0xB4, 0xB4, 0xC8, 0xFF };
61
62 private:
63 std::string title_font_name;
64 std::string cnt_font_name;
65 std::string opt_font_name;
66 std::string title;
67 std::string cnt;
68 sdl2::Texture title_tex;
69 sdl2::Texture cnt_tex;
70 std::vector<std::string> opts;
71 std::string cancel_opt;
72 u32 selected_opt_idx;
73 i32 selected_opt_over_alpha;
74 SigmoidIncrementer<i32> selected_opt_over_alpha_incr;
75 i32 prev_selected_opt_idx;
76 i32 prev_selected_opt_over_alpha;
77 SigmoidIncrementer<i32> prev_selected_opt_over_alpha_incr;
78 bool user_cancelled;
79 sdl2::TextureHandle::Ref icon_tex;
80 Color title_clr;
81 Color cnt_clr;
82 Color opt_clr;
83 u32 dialog_extra_base_width;
84 u32 dialog_border_radius;
85 u32 space_between_options;
86 u32 space_between_option_rows;
87 u32 title_extra_width;
88 u32 cnt_extra_width;
89 u32 space_between_cnt_and_options;
90 u32 title_top_margin;
91 u32 title_x;
92 u32 title_y;
93 u32 cnt_x;
94 u32 cnt_y;
95 u32 icon_extra_height;
96 u32 opts_base_h_margin;
97 u32 opt_height;
98 u32 opt_h_margin;
99 u32 opt_border_radius;
100 u32 opt_bottom_margin;
101 u8 max_screen_fade_alpha;
102 u32 icon_margin;
103 Color dialog_clr;
104 Color over_clr;
105 u8 over_alpha_incr_steps;
106 u8 fade_alpha_incr_steps;
107
108 inline Color MakeDialogColor(const u8 alpha) {
109 return this->dialog_clr.WithAlpha(alpha);
110 }
111
112 inline Color MakeOverColor(const u8 alpha) {
113 return this->over_clr.WithAlpha(alpha);
114 }
115
116 void LoadTitle();
117 void LoadContent();
118 void DisposeIcon();
119
120 public:
121 Dialog(const std::string &title, const std::string &content);
124
125 void AddOption(const std::string &opt_name);
126
127 inline void SetCancelOption(const std::string &opt_name) {
128 this->cancel_opt = opt_name;
129 }
130
131 inline void RemoveCancelOption() {
132 this->SetCancelOption("");
133 }
134
135 inline bool HasCancelOption() {
136 return !this->cancel_opt.empty();
137 }
138
139 PU_CLASS_POD_GET(TitleColor, title_clr, Color)
140
141 void SetTitleColor(const Color clr);
142
143 void SetTitle(const std::string &new_title);
144
145 PU_CLASS_POD_GET(ContentColor, cnt_clr, Color)
146
147 void SetContentColor(const Color clr);
148
149 void SetContent(const std::string &new_content);
150
151 PU_CLASS_POD_GETSET(OptionColor, opt_clr, Color)
152
153 PU_CLASS_POD_GETSET(DialogExtraBaseWidth, dialog_extra_base_width, u32)
154 PU_CLASS_POD_GETSET(DialogBorderRadius, dialog_border_radius, u32)
155 PU_CLASS_POD_GETSET(SpaceBetweenOptions, space_between_options, u32)
156 PU_CLASS_POD_GETSET(SpaceBetweenOptionRows, space_between_option_rows, u32)
157 PU_CLASS_POD_GETSET(TitleExtraWidth, title_extra_width, u32)
158 PU_CLASS_POD_GETSET(ContentExtraWidth, cnt_extra_width, u32)
159 PU_CLASS_POD_GETSET(SpaceBetweenContentAndOptions, space_between_cnt_and_options, u32)
160 PU_CLASS_POD_GETSET(TitleTopMargin, title_top_margin, u32)
161 PU_CLASS_POD_GETSET(TitleX, title_x, u32)
162 PU_CLASS_POD_GETSET(TitleY, title_y, u32)
163 PU_CLASS_POD_GETSET(ContentX, cnt_x, u32)
164 PU_CLASS_POD_GETSET(ContentY, cnt_y, u32)
165 PU_CLASS_POD_GETSET(IconExtraHeight, icon_extra_height, u32)
166 PU_CLASS_POD_GETSET(OptionsBaseHorizontalMargin, opts_base_h_margin, u32)
167 PU_CLASS_POD_GETSET(OptionHeight, opt_height, u32)
168 PU_CLASS_POD_GETSET(OptionHorizontalMargin, opt_h_margin, u32)
169 PU_CLASS_POD_GETSET(OptionBorderRadius, opt_border_radius, u32)
170 PU_CLASS_POD_GETSET(OptionBottomMargin, opt_bottom_margin, u32)
171 PU_CLASS_POD_GETSET(MaxScreenFadeAlpha, max_screen_fade_alpha, u8)
172 PU_CLASS_POD_GETSET(IconMargin, icon_margin, u32)
173 PU_CLASS_POD_GETSET(DialogColor, dialog_clr, Color)
174 PU_CLASS_POD_GETSET(OverColor, over_clr, Color)
175 PU_CLASS_POD_GETSET(OverAlphaIncrementSteps, over_alpha_incr_steps, u8)
176 PU_CLASS_POD_GETSET(FadeAlphaIncrementSteps, fade_alpha_incr_steps, u8)
177
178 void SetIcon(sdl2::TextureHandle::Ref tex);
179
180 inline bool HasIcon() {
181 return this->icon_tex != nullptr;
182 }
183
185
186 inline constexpr bool UserCancelled() {
187 return this->user_cancelled;
188 }
189
190 inline bool IsOk() {
191 if(this->user_cancelled) {
192 return false;
193 }
194
195 if(this->HasCancelOption() && (this->selected_opt_idx == (this->opts.size() - 1))) {
196 return false;
197 }
198
199 return true;
200 }
201 };
202
203}
Definition sdl2_Types.hpp:18
Definition ui_Application.hpp:22
Definition ui_Dialog.hpp:22
static constexpr u32 DefaultIconMargin
Definition ui_Dialog.hpp:54
static constexpr Color DefaultTitleColor
Definition ui_Dialog.hpp:24
constexpr bool UserCancelled()
Definition ui_Dialog.hpp:186
void SetCancelOption(const std::string &opt_name)
Definition ui_Dialog.hpp:127
static constexpr u32 DefaultDialogExtraBaseWidth
Definition ui_Dialog.hpp:28
bool HasCancelOption()
Definition ui_Dialog.hpp:135
static constexpr u32 DefaultContentX
Definition ui_Dialog.hpp:41
static constexpr Color DefaultDialogColor
Definition ui_Dialog.hpp:59
void SetContentColor(const Color clr)
static constexpr Color DefaultContentColor
Definition ui_Dialog.hpp:25
static constexpr u32 DefaultTitleTopMargin
Definition ui_Dialog.hpp:37
static constexpr u32 DefaultOptionBorderRadius
Definition ui_Dialog.hpp:49
static constexpr u32 DefaultTitleExtraWidth
Definition ui_Dialog.hpp:34
i32 Show(Application *app_ref)
static constexpr u8 DefaultOverAlphaIncrementSteps
Definition ui_Dialog.hpp:56
static constexpr u32 DefaultOptionHorizontalMargin
Definition ui_Dialog.hpp:48
static constexpr u32 DefaultDialogBorderRadius
Definition ui_Dialog.hpp:29
static constexpr u32 DefaultSpaceBetweenContentAndOptions
Definition ui_Dialog.hpp:36
static constexpr u32 DefaultOptionsBaseHorizontalMargin
Definition ui_Dialog.hpp:46
void SetContent(const std::string &new_content)
void SetTitle(const std::string &new_title)
void SetTitleColor(const Color clr)
static constexpr u8 DefaultMaxScreenFadeAlpha
Definition ui_Dialog.hpp:52
void RemoveCancelOption()
Definition ui_Dialog.hpp:131
static constexpr Color DefaultOverColor
Definition ui_Dialog.hpp:60
static constexpr u32 DefaultOptionBottomMargin
Definition ui_Dialog.hpp:50
static constexpr u32 DefaultSpaceBetweenOptions
Definition ui_Dialog.hpp:31
void AddOption(const std::string &opt_name)
static constexpr u32 DefaultTitleX
Definition ui_Dialog.hpp:39
static constexpr u32 DefaultSpaceBetweenOptionRows
Definition ui_Dialog.hpp:32
static constexpr u32 DefaultIconExtraHeight
Definition ui_Dialog.hpp:44
static constexpr u32 DefaultContentY
Definition ui_Dialog.hpp:42
bool HasIcon()
Definition ui_Dialog.hpp:180
void SetIcon(sdl2::TextureHandle::Ref tex)
static constexpr Color DefaultOptionColor
Definition ui_Dialog.hpp:26
static constexpr u32 DefaultOptionHeight
Definition ui_Dialog.hpp:47
static constexpr u32 DefaultContentExtraWidth
Definition ui_Dialog.hpp:35
bool IsOk()
Definition ui_Dialog.hpp:190
static constexpr u32 DefaultTitleY
Definition ui_Dialog.hpp:40
static constexpr u8 DefaultFadeAlphaIncrementSteps
Definition ui_Dialog.hpp:57
Dialog(const std::string &title, const std::string &content)
Definition sdl2_Types.hpp:10
#define PU_SMART_CTOR(type)
Definition pu_Include.hpp:20
#define PU_CLASS_POD_GETSET(fn_name, var_name, type)
Definition pu_Include.hpp:37
#define PU_CLASS_POD_GET(fn_name, var_name, type)
Definition pu_Include.hpp:27
Definition ui_Types.hpp:44