SDL_DialogFileCallback(3type)
π SDL_DialogFileCallback β bestie edition π
okay so this is a SDL3 DATATYPES page, and it's literally all about SDL_DialogFileCallback, the callback that file dialog functions call back to. yes the name is a mouthful. we love her anyway. π
β¨ NAME β¨
SDL_DialogFileCallback β the callback used by file dialog functions. that's it, that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_dialog.h>
typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);
look at her. iconic signature. no notes. π
π¦ DESCRIPTION π¦
so the specific usage is described in each function β this page is just the general tea. but here's the important part, and bestie, you're gonna wanna pay attention because filelist can mean three completely different things and that's the whole plot twist: π
- if
filelistisNULL, an error occurred. you can get the details withSDL_GetError(). - if
filelistis a pointer toNULL, the user either didn't choose any file or canceled the dialog. no file for you. π - if
filelistis a pointer to non-NULL, the user chose one or more files! slay! the argument is a null-terminated array of pointers to UTF-8 encoded strings, and each one contains a path. π«Ά
β οΈ do NOT free the filelist argument. like, don't. it gets automatically freed when the callback returns. it's not yours, it's on loan. hands off. π
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. so -1 is basically the "idk bestie" value. π
now, Android section, because Android is always doing something extra: in Android, the filelist are content:// URIs. they should be opened using SDL_IOFromFile() with appropriate modes. and this applies both to open and save file dialogs. so don't forget it. β¨
π§ FUNCTION PARAMETERS π§
userdataβ an app-provided pointer, for the callback's use. it's your little bag of stuff you get to bring along. πfilelistβ the file(s) chosen by the user. the main character of this whole page, honestly. πfilterβ index of the selected filter. yes, just the index. the number. that's it. πΈ
π AVAILABILITY π
this datatype is available since SDL 3.2.0. so if you're on anything older... bestie. upgrade. π
π SEE ALSO π
SDL_DialogFileFilter(3type)SDL_ShowOpenFileDialog(3)SDL_ShowSaveFileDialog(3)SDL_ShowOpenFolderDialog(3)SDL_ShowFileDialogWithProperties(3)
the whole friend group. go read them next, iykyk. π¦
okay that's the page!! brought to you by Simple Directmedia Layer, version SDL 3.4.18, and this little SDL_DialogFileCallback(3type) moment. mwah. stay hydrated, read your docs, and never free that filelist. πβ¨π₯
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms