SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_dialog.h
1#ifndef SDL3PP_DIALOG_H_
2#define SDL3PP_DIALOG_H_
3
4#include <SDL3/SDL_dialog.h>
5#include "SDL3pp_properties.h"
6#include "SDL3pp_stdinc.h"
7#include "SDL3pp_video.h"
8
9namespace SDL {
10
25
45using DialogFileFilter = SDL_DialogFileFilter;
46
84using DialogFileCallback = void(SDLCALL*)(void* userdata,
85 const char* const* filelist,
86 int filter);
87
126 std::function<void(const char* const* filelist, int filter)>;
127
179 void* userdata,
180 WindowRef window,
181 std::span<const DialogFileFilter> filters = {},
182 StringParam default_location = {},
183 bool allow_many = false)
184{
185 SDL_ShowOpenFileDialog(callback,
186 userdata,
187 window,
188 filters.data(),
189 narrowS32(filters.size()),
190 default_location,
191 allow_many);
192}
193
242inline void ShowOpenFileDialog(DialogFileCB callback,
243 WindowRef window,
244 std::span<const DialogFileFilter> filters = {},
245 StringParam default_location = {},
246 bool allow_many = false)
247{
248 using Wrapper = CallbackWrapper<DialogFileCB>;
249 ShowOpenFileDialog(&Wrapper::CallOnce,
250 Wrapper::Wrap(std::move(callback)),
251 window,
252 filters,
253 std::move(default_location),
254 allow_many);
255}
256
304 void* userdata,
305 WindowRef window = {},
306 std::span<const DialogFileFilter> filters = {},
307 StringParam default_location = {})
308{
309 SDL_ShowSaveFileDialog(callback,
310 userdata,
311 window,
312 filters.data(),
313 narrowS32(filters.size()),
314 default_location);
315}
316
361inline void ShowSaveFileDialog(DialogFileCB callback,
362 WindowRef window = {},
363 std::span<const DialogFileFilter> filters = {},
364 StringParam default_location = {})
365{
366 using Wrapper = CallbackWrapper<DialogFileCB>;
367 ShowSaveFileDialog(&Wrapper::CallOnce,
368 Wrapper::Wrap(std::move(callback)),
369 window,
370 filters,
371 std::move(default_location));
372}
373
418 void* userdata,
419 WindowRef window = {},
420 StringParam default_location = {},
421 bool allow_many = false)
422{
423 SDL_ShowOpenFolderDialog(
424 callback, userdata, window, default_location, allow_many);
425}
426
469 WindowRef window = {},
470 StringParam default_location = {},
471 bool allow_many = false)
472{
473 using Wrapper = CallbackWrapper<DialogFileCB>;
474 ShowOpenFolderDialog(&Wrapper::CallOnce,
475 Wrapper::Wrap(std::move(callback)),
476 std::move(window),
477 std::move(default_location),
478 allow_many);
479}
480
491using FileDialogType = SDL_FileDialogType;
492
494 SDL_FILEDIALOG_OPENFILE;
495
497 SDL_FILEDIALOG_SAVEFILE;
498
500 SDL_FILEDIALOG_OPENFOLDER;
501
548 DialogFileCallback callback,
549 void* userdata,
550 PropertiesRef props)
551{
552 SDL_ShowFileDialogWithProperties(type, callback, userdata, props);
553}
554
599 DialogFileCB callback,
600 PropertiesID props)
601{
602 using Wrapper = CallbackWrapper<DialogFileCB>;
604 type, &Wrapper::CallOnce, Wrapper::Wrap(std::move(callback)), props);
605}
606
616
617constexpr auto FILTERS_POINTER =
618 SDL_PROP_FILE_DIALOG_FILTERS_POINTER;
619
620constexpr auto NFILTERS_NUMBER =
621 SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER;
622
623constexpr auto WINDOW_POINTER =
624 SDL_PROP_FILE_DIALOG_WINDOW_POINTER;
625
626constexpr auto LOCATION_STRING =
627 SDL_PROP_FILE_DIALOG_LOCATION_STRING;
628
629constexpr auto MANY_BOOLEAN =
630 SDL_PROP_FILE_DIALOG_MANY_BOOLEAN;
631
632constexpr auto TITLE_STRING =
633 SDL_PROP_FILE_DIALOG_TITLE_STRING;
634
635constexpr auto ACCEPT_STRING =
636 SDL_PROP_FILE_DIALOG_ACCEPT_STRING;
637
638constexpr auto CANCEL_STRING =
639 SDL_PROP_FILE_DIALOG_CANCEL_STRING;
640
641} // namespace prop::FileDialog
642
644
645} // namespace SDL
646
647#endif /* SDL3PP_DIALOG_H_ */
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
SDL_FileDialogType FileDialogType
Various types of file dialogs.
Definition SDL3pp_dialog.h:491
void ShowFileDialogWithProperties(FileDialogType type, DialogFileCallback callback, void *userdata, PropertiesRef props)
Create and launch a file dialog with the specified properties.
Definition SDL3pp_dialog.h:547
void ShowOpenFolderDialog(DialogFileCallback callback, void *userdata, WindowRef window={}, StringParam default_location={}, bool allow_many=false)
Displays a dialog that lets the user select a folder on their filesystem.
Definition SDL3pp_dialog.h:417
void ShowSaveFileDialog(DialogFileCallback callback, void *userdata, WindowRef window={}, std::span< const DialogFileFilter > filters={}, StringParam default_location={})
Displays a dialog that lets the user choose a new or existing file on their filesystem.
Definition SDL3pp_dialog.h:303
void ShowOpenFileDialog(DialogFileCallback callback, void *userdata, WindowRef window, std::span< const DialogFileFilter > filters={}, StringParam default_location={}, bool allow_many=false)
Displays a dialog that lets the user select a file on their filesystem.
Definition SDL3pp_dialog.h:178
void(SDLCALL *)(void *userdata, const char *const *filelist, int filter) DialogFileCallback
Callback used by file dialog functions.
Definition SDL3pp_dialog.h:84
SDL_DialogFileFilter DialogFileFilter
An entry for filters for file dialogs.
Definition SDL3pp_dialog.h:45
constexpr FileDialogType FILEDIALOG_OPENFOLDER
OPENFOLDER.
Definition SDL3pp_dialog.h:499
constexpr FileDialogType FILEDIALOG_OPENFILE
OPENFILE.
Definition SDL3pp_dialog.h:493
std::function< void(const char *const *filelist, int filter)> DialogFileCB
Callback used by file dialog functions.
Definition SDL3pp_dialog.h:125
constexpr FileDialogType FILEDIALOG_SAVEFILE
SAVEFILE.
Definition SDL3pp_dialog.h:496
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
SDL_PropertiesID PropertiesID
Alias to raw representation for Properties.
Definition SDL3pp_properties.h:47
ResourceRef< Window > WindowRef
Reference for Window.
Definition SDL3pp_video.h:54
Properties for file dialogs.
Definition SDL3pp_dialog.h:615
constexpr auto FILTERS_POINTER
Pointer to filters.
Definition SDL3pp_dialog.h:617
constexpr auto ACCEPT_STRING
String for accept.
Definition SDL3pp_dialog.h:635
constexpr auto CANCEL_STRING
String for cancel.
Definition SDL3pp_dialog.h:638
constexpr auto WINDOW_POINTER
Pointer to window.
Definition SDL3pp_dialog.h:623
constexpr auto LOCATION_STRING
String for location.
Definition SDL3pp_dialog.h:626
constexpr auto MANY_BOOLEAN
Many enabled.
Definition SDL3pp_dialog.h:629
constexpr auto NFILTERS_NUMBER
Number of filters.
Definition SDL3pp_dialog.h:620
constexpr auto TITLE_STRING
String for title.
Definition SDL3pp_dialog.h:632
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6257
Definition SDL3pp_callbackWrapper.h:20