Skip to content

Add various input dialogs #13120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 363 additions & 0 deletions include/SDL3/SDL_dialog.h

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions src/dialog/SDL_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,109 @@ void SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, S
SDL_DestroyProperties(props);
#endif
}

// TODO: Dialogs after this should be implemented with XDG Portals

void SDL_ShowInputDialogWithProperties(SDL_DialogInputCallback callback, void *userdata, SDL_PropertiesID props)
{
if (!callback) {
return;
}
#ifdef SDL_DIALOG_DISABLED
SDL_SetError("SDL not built with dialog support");
callback(userdata, NULL, SDL_DIALOGRESULT_ERROR);
#else
SDL_SYS_ShowInputDialogWithProperties(callback, userdata, props);
#endif
}

SDL_ProgressDialog* SDL_ShowProgressDialogWithProperties(SDL_DialogProgressCallback callback, void *userdata, SDL_PropertiesID props)
{
if (!callback) {
return NULL;
}
#ifdef SDL_DIALOG_DISABLED
SDL_SetError("SDL not built with dialog support");
callback(userdata, NULL, SDL_DIALOGRESULT_ERROR);
return NULL;
#else
return SDL_SYS_ShowProgressDialogWithProperties(callback, userdata, props);
#endif
}

void SDL_UpdateProgressDialog(SDL_ProgressDialog* dialog, float progress, const char *new_prompt)
{
#ifdef SDL_DIALOG_DISABLED
SDL_SetError("SDL not built with dialog support");
#else
if (!dialog) {
SDL_InvalidParamError("dialog");
return;
}
if (progress < 0.0f || progress > 1.0f) {
SDL_InvalidParamError("progress");
return;
}
SDL_SYS_UpdateProgressDialog(dialog, progress, new_prompt);
#endif
}

void SDL_DestroyProgressDialog(SDL_ProgressDialog* dialog)
{
#ifdef SDL_DIALOG_DISABLED
SDL_SetError("SDL not built with dialog support");
#else
if (!dialog) {
SDL_InvalidParamError("dialog");
return;
}
SDL_SYS_DestroyProgressDialog(dialog);
#endif
}

void SDL_ShowColorPickerDialogWithProperties(SDL_DialogColorCallback callback, void *userdata, SDL_PropertiesID props)
{
if (!callback) {
return;
}

#ifdef SDL_DIALOG_DISABLED
SDL_Color c;
c.r = 0;
c.g = 0;
c.b = 0;
c.a = 0;

SDL_SetError("SDL not built with dialog support");
callback(userdata, c, SDL_DIALOGRESULT_ERROR);
#else
SDL_SYS_ShowColorPickerDialogWithProperties(callback, userdata, props);
#endif
}

void SDL_ShowDatePickerDialogWithProperties(SDL_DialogDateCallback callback, void *userdata, SDL_PropertiesID props)
{
if (!callback) {
return;
}

SDL_Date d;
d.y = 0;
d.m = 0;
d.d = 0;

#ifdef SDL_DIALOG_DISABLED
SDL_SetError("SDL not built with dialog support");
callback(userdata, d, SDL_DIALOGRESULT_ERROR);
#else
SDL_Date *date = SDL_GetPointerProperty(props, SDL_PROP_DATE_DIALOG_DEFAULT_POINTER, NULL);

// A value of 0 is "null" for that field
if (date && (date->y > 9999 || date->m > 12 || date->d > 31)) {
SDL_SetError("Invalid default date: %d-%d-%d", date->y, date->m, date->d);
callback(userdata, d, SDL_DIALOGRESULT_ERROR);
}

SDL_SYS_ShowDatePickerDialogWithProperties(callback, userdata, props);
#endif
}
6 changes: 6 additions & 0 deletions src/dialog/SDL_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
*/

void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props);
void SDL_SYS_ShowInputDialogWithProperties(SDL_DialogInputCallback callback, void *userdata, SDL_PropertiesID props);
SDL_ProgressDialog* SDL_SYS_ShowProgressDialogWithProperties(SDL_DialogProgressCallback callback, void *userdata, SDL_PropertiesID props);
void SDL_SYS_UpdateProgressDialog(SDL_ProgressDialog* dialog, float progress, const char *new_prompt);
void SDL_SYS_DestroyProgressDialog(SDL_ProgressDialog* dialog);
void SDL_SYS_ShowColorPickerDialogWithProperties(SDL_DialogColorCallback callback, void *userdata, SDL_PropertiesID props);
void SDL_SYS_ShowDatePickerDialogWithProperties(SDL_DialogDateCallback callback, void *userdata, SDL_PropertiesID props);
Loading
Loading