SDL_ShowSaveFileDialog(3)
πΎ SDL_ShowSaveFileDialog β¨
okay bestie, welcome to the SDL_ShowSaveFileDialog(3) page, part of the SDL3 FUNCTIONS lineup π she's a lil function in the SDL 3 world and she's here to pop open a save-file dialog for you π
πΈ NAME πΈ
SDL_ShowSaveFileDialog β pops up a dialog so your user can pick a new or existing file on their filesystem ποΈβ¨ like "where do you wanna put this, queen?"
π SYNOPSIS π
#include <SDL3/SDL_dialog.h>
void SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location);
she takes six arguments and returns void, no cap π«Ά
π¦ DESCRIPTION π¦
first thing, and this is important: this is an asynchronous function. she returns immediately β like, she does not wait around for your user to make up their mind π the actual result gets handed off to the callback.
so when the callback gets invoked, it receives a null-terminated list of the files the user chose π here's the vibe check on that list:
- the list will be empty if the user canceled the dialog π
- the list will be
NULLif an error occurred π
not me warning you about this: the callback may be called from a different thread than the one the function was invoked on π keep that in mind, bestie.
also, the chosen file may or may not already exist β she's flexible like that, she doesn't gatekeep π
and a Linux-specific note for my portal girlies π§ on Linux, dialogs may require XDG Portals, which requires DBus, which requires an event-handling loop. if your app doesn't use SDL to handle events, you should add a call to SDL_PumpEvents in your main loop. periodt. π
π FUNCTION PARAMETERS π
callbackβ a function pointer that gets invoked when the user selects a file and accepts, or cancels the dialog, or when an error occurs π«Άuserdataβ an optional pointer you can pass extra data through to the callback when it gets invoked β¨windowβ the window that the dialog should be modal for. it may beNULL. heads up tho: not all platforms support this option πfiltersβ a list of filters, may beNULL. again, not all platforms support this option, and even the platforms that do support it may let the user just... ignore the filters π if it's non-NULL, it must remain valid at least until the callback is invoked β don't let it die early bestie, she's holding onto it πnfiltersβ the number of filters. ignored iffiltersisNULLπdefault_locationβ the default folder or file to start the dialog at, may beNULL. and yep, you guessed it: not all platforms support this option πΈ
π§΅ THREAD SAFETY π§΅
call this function only from the main thread, no exceptions, that's the rule π the callback, though? she may be invoked from the same thread or from a different one, depending on the OS's constraints. main character energy with a lil unpredictability π β¨
β AVAILABILITY β
this function is available since SDL 3.2.0 π she's not ancient, she's fresh.
π SEE ALSO π
SDL_DialogFileCallback(3type)SDL_DialogFileFilter(3type)SDL_ShowOpenFileDialog(3)SDL_ShowOpenFolderDialog(3)SDL_ShowFileDialogWithProperties(3)
go read those too, iykyk π
and that's the whole page, bestie!! this was brought to you by Simple Directmedia Layer, rocking SDL 3.4.18 π¦ now go save some files, slay, and remember: the callback might be on another thread, so stay safe out there ππΈβ¨
π¦ 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