Callback used by file dialog functions.
Defined in <SDL3/SDL_dialog.h>
typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);
userdata | an app-provided pointer, for the callback's use. |
filelist | the file(s) chosen by the user. |
filter | index of the selected filter. |
The specific usage is described in each function.
If filelist
is:
NULL
, the user chose one or more files. The argument is a null-terminated list of pointers to C strings, each containing a path.The filelist argument should not be freed; it will automatically be freed when the callback returns.
The filter argument is the index of the filter that was selected, or -1 if no filter was selected or if the platform or method doesn't support fetching the selected filter.
This datatype is available since SDL 3.1.3.
#include <SDL3/SDL.h>
static const SDL_DialogFileFilter filters[] = {
"PNG images", "png" },
{ "JPEG images", "jpg;jpeg" },
{ "All images", "png;jpg;jpeg" },
{ "All files", "*" }
{
};
static void SDLCALL callback(void* userdata, const char* const* filelist, int filter)
{if (!filelist) {
"An error occured: %s", SDL_GetError());
SDL_Log(return;
else if (!*filelist) {
} "The user did not select any file.");
SDL_Log("Most likely, the dialog was canceled.");
SDL_Log(return;
}
while (*filelist) {
"Full path to selected file: '%s'", *filelist);
SDL_Log(
filelist++;
}
if (filter < 0) {
"The current platform does not support fetching "
SDL_Log("the selected filter, or the user did not select"
" any filter.");
else if (filter < SDL_arraysize(filters)) {
} "The filter selected by the user is '%s' (%s).",
SDL_Log(
filters[filter].pattern, filters[filter].name);
} }