Skip to content

Commit 382292d

Browse files
author
Semphris
committed
Input dialogs
1 parent 685f172 commit 382292d

File tree

10 files changed

+1816
-26
lines changed

10 files changed

+1816
-26
lines changed

include/SDL3/SDL_dialog.h

Lines changed: 363 additions & 0 deletions
Large diffs are not rendered by default.

src/dialog/SDL_dialog.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,109 @@ void SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, S
129129
SDL_DestroyProperties(props);
130130
#endif
131131
}
132+
133+
// TODO: Dialogs after this should be implemented with XDG Portals
134+
135+
void SDL_ShowInputDialogWithProperties(SDL_DialogInputCallback callback, void *userdata, SDL_PropertiesID props)
136+
{
137+
if (!callback) {
138+
return;
139+
}
140+
#ifdef SDL_DIALOG_DISABLED
141+
SDL_SetError("SDL not built with dialog support");
142+
callback(userdata, NULL, SDL_DIALOGRESULT_ERROR);
143+
#else
144+
SDL_SYS_ShowInputDialogWithProperties(callback, userdata, props);
145+
#endif
146+
}
147+
148+
SDL_ProgressDialog* SDL_ShowProgressDialogWithProperties(SDL_DialogProgressCallback callback, void *userdata, SDL_PropertiesID props)
149+
{
150+
if (!callback) {
151+
return NULL;
152+
}
153+
#ifdef SDL_DIALOG_DISABLED
154+
SDL_SetError("SDL not built with dialog support");
155+
callback(userdata, NULL, SDL_DIALOGRESULT_ERROR);
156+
return NULL;
157+
#else
158+
return SDL_SYS_ShowProgressDialogWithProperties(callback, userdata, props);
159+
#endif
160+
}
161+
162+
void SDL_UpdateProgressDialog(SDL_ProgressDialog* dialog, float progress, const char *new_prompt)
163+
{
164+
#ifdef SDL_DIALOG_DISABLED
165+
SDL_SetError("SDL not built with dialog support");
166+
#else
167+
if (!dialog) {
168+
SDL_InvalidParamError("dialog");
169+
return;
170+
}
171+
if (progress < 0.0f || progress > 1.0f) {
172+
SDL_InvalidParamError("progress");
173+
return;
174+
}
175+
SDL_SYS_UpdateProgressDialog(dialog, progress, new_prompt);
176+
#endif
177+
}
178+
179+
void SDL_DestroyProgressDialog(SDL_ProgressDialog* dialog)
180+
{
181+
#ifdef SDL_DIALOG_DISABLED
182+
SDL_SetError("SDL not built with dialog support");
183+
#else
184+
if (!dialog) {
185+
SDL_InvalidParamError("dialog");
186+
return;
187+
}
188+
SDL_SYS_DestroyProgressDialog(dialog);
189+
#endif
190+
}
191+
192+
void SDL_ShowColorPickerDialogWithProperties(SDL_DialogColorCallback callback, void *userdata, SDL_PropertiesID props)
193+
{
194+
if (!callback) {
195+
return;
196+
}
197+
198+
#ifdef SDL_DIALOG_DISABLED
199+
SDL_Color c;
200+
c.r = 0;
201+
c.g = 0;
202+
c.b = 0;
203+
c.a = 0;
204+
205+
SDL_SetError("SDL not built with dialog support");
206+
callback(userdata, c, SDL_DIALOGRESULT_ERROR);
207+
#else
208+
SDL_SYS_ShowColorPickerDialogWithProperties(callback, userdata, props);
209+
#endif
210+
}
211+
212+
void SDL_ShowDatePickerDialogWithProperties(SDL_DialogDateCallback callback, void *userdata, SDL_PropertiesID props)
213+
{
214+
if (!callback) {
215+
return;
216+
}
217+
218+
SDL_Date d;
219+
d.y = 0;
220+
d.m = 0;
221+
d.d = 0;
222+
223+
#ifdef SDL_DIALOG_DISABLED
224+
SDL_SetError("SDL not built with dialog support");
225+
callback(userdata, d, SDL_DIALOGRESULT_ERROR);
226+
#else
227+
SDL_Date *date = SDL_GetPointerProperty(props, SDL_PROP_DATE_DIALOG_DEFAULT_POINTER, NULL);
228+
229+
// A value of 0 is "null" for that field
230+
if (date && (date->y > 9999 || date->m > 12 || date->d > 31)) {
231+
SDL_SetError("Invalid default date: %d-%d-%d", date->y, date->m, date->d);
232+
callback(userdata, d, SDL_DIALOGRESULT_ERROR);
233+
}
234+
235+
SDL_SYS_ShowDatePickerDialogWithProperties(callback, userdata, props);
236+
#endif
237+
}

src/dialog/SDL_dialog.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@
2020
*/
2121

2222
void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props);
23+
void SDL_SYS_ShowInputDialogWithProperties(SDL_DialogInputCallback callback, void *userdata, SDL_PropertiesID props);
24+
SDL_ProgressDialog* SDL_SYS_ShowProgressDialogWithProperties(SDL_DialogProgressCallback callback, void *userdata, SDL_PropertiesID props);
25+
void SDL_SYS_UpdateProgressDialog(SDL_ProgressDialog* dialog, float progress, const char *new_prompt);
26+
void SDL_SYS_DestroyProgressDialog(SDL_ProgressDialog* dialog);
27+
void SDL_SYS_ShowColorPickerDialogWithProperties(SDL_DialogColorCallback callback, void *userdata, SDL_PropertiesID props);
28+
void SDL_SYS_ShowDatePickerDialogWithProperties(SDL_DialogDateCallback callback, void *userdata, SDL_PropertiesID props);

src/dialog/dummy/SDL_dummydialog.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,57 @@
2626

2727
void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props)
2828
{
29-
SDL_Unsupported();
30-
callback(userdata, NULL, -1);
29+
SDL_Unsupported();
30+
callback(userdata, NULL, -1);
31+
}
32+
33+
void SDL_SYS_ShowInputDialogWithProperties(SDL_DialogInputCallback callback, void *userdata, SDL_PropertiesID props)
34+
{
35+
SDL_Unsupported();
36+
callback(userdata, NULL, SDL_DIALOGRESULT_ERROR);
37+
}
38+
39+
SDL_ProgressDialog* SDL_SYS_ShowProgressDialogWithProperties(SDL_DialogProgressCallback callback, void *userdata, SDL_PropertiesID props)
40+
{
41+
SDL_Unsupported();
42+
callback(userdata, SDL_DIALOGRESULT_ERROR);
43+
44+
// In case the callback calls SDL_SetError()
45+
SDL_Unsupported();
46+
return NULL;
47+
}
48+
49+
void SDL_SYS_UpdateProgressDialog(SDL_ProgressDialog* dialog, float progress, const char *new_prompt)
50+
{
51+
SDL_Unsupported();
52+
}
53+
54+
void SDL_SYS_DestroyProgressDialog(SDL_ProgressDialog* dialog)
55+
{
56+
SDL_Unsupported();
57+
}
58+
59+
void SDL_SYS_ShowColorPickerDialogWithProperties(SDL_DialogColorCallback callback, void *userdata, SDL_PropertiesID props)
60+
{
61+
SDL_Color color;
62+
color.r = 0;
63+
color.g = 0;
64+
color.b = 0;
65+
color.a = 0;
66+
67+
SDL_Unsupported();
68+
callback(userdata, color, SDL_DIALOGRESULT_ERROR);
69+
}
70+
71+
void SDL_SYS_ShowDatePickerDialogWithProperties(SDL_DialogDateCallback callback, void *userdata, SDL_PropertiesID props)
72+
{
73+
SDL_Date date;
74+
date.y = 0;
75+
date.m = 0;
76+
date.d = 0;
77+
78+
SDL_Unsupported();
79+
callback(userdata, date, SDL_DIALOGRESULT_ERROR);
3180
}
3281

3382
#endif // SDL_DIALOG_DUMMY

0 commit comments

Comments
 (0)