24 if (files ==
nullptr) {
26 }
else if (files[0] !=
nullptr) {
34void show_message(SDL_MessageBoxFlags flags,
const std::string& title,
const std::string& message)
42 show_message(SDL_MESSAGEBOX_INFORMATION, title, message);
57 const std::array buttons {
58 SDL_MessageBoxButtonData { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0,
"No" },
59 SDL_MessageBoxButtonData { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1,
"Yes" },
62 const SDL_MessageBoxData data {
63 SDL_MESSAGEBOX_WARNING,
67 static_cast<int>(buttons.size()),
73 return SDL_ShowMessageBox(&data, &pressed) && pressed == 1;
77 FileMode mode,
const std::string& default_location,
const std::vector<FileFilter>& filters)
96 const char* location = default_location.empty() ? nullptr : default_location.c_str();
101 if (mode == FileMode::Save) {
103 filter_count, location);
106 filter_count, location,
false);
Native message boxes and file choosers.
Display and window routines for the ASW library.
Structured logging system.
std::optional< std::string > chosen_file
std::vector< asw::dialog::FileFilter > active_filters
void SDLCALL on_file_chosen(void *, const char *const *files, int)
std::atomic< bool > file_pending
void show_message(SDL_MessageBoxFlags flags, const std::string &title, const std::string &message)
std::vector< SDL_DialogFileFilter > active_sdl_filters
FileMode
Kind of file chooser.
void warn(const std::string &title, const std::string &message)
Show a warning message box. Blocks until it is closed.
void error(const std::string &title, const std::string &message)
Show an error message box. Blocks until it is closed.
bool confirm(const std::string &title, const std::string &message)
Ask a yes or no question. Blocks until it is answered.
std::optional< std::string > take_file()
Take the file the user chose. Returns it once, then empty until the next chooser.
void info(const std::string &title, const std::string &message)
Show an information message box. Blocks until it is closed.
bool is_file_pending()
Check if a file chooser is open.
bool request_file(FileMode mode, const std::string &default_location="", const std::vector< FileFilter > &filters={ })
Open a native file chooser. It does not block, the chosen file arrives later through take_file()....
asw::Window * get_window()
Get the SDL window.
void warn(const std::string &message)
Log a warning message.