sdlShowSimpleMessageBox function

bool sdlShowSimpleMessageBox(
  1. int flags,
  2. String? title,
  3. String? message,
  4. Pointer<SdlWindow> window,
)

Display a simple modal message box.

If your needs aren't complex, this function is preferred over SDL_ShowMessageBox.

flags may be any of the following:

  • SDL_MESSAGEBOX_ERROR: error dialog
  • SDL_MESSAGEBOX_WARNING: warning dialog
  • SDL_MESSAGEBOX_INFORMATION: informational dialog

This function should be called on the thread that created the parent window, or on the main thread if the messagebox has no parent. It will block execution of that thread until the user clicks a button or closes the messagebox.

This function may be called at any time, even before SDL_Init(). This makes it useful for reporting errors like a failure to create a renderer or OpenGL context.

On X11, SDL rolls its own dialog box with X11 primitives instead of a formal toolkit like GTK+ or Qt.

Note that if SDL_Init() would fail because there isn't any available video target, this function is likely to fail for the same reasons. If this is a concern, check the return value from this function and fall back to writing to stderr if you can.

\param flags an SDL_MessageBoxFlags value. \param title UTF-8 title text. \param message UTF-8 message text. \param window the parent window, or NULL for no parent. \returns true on success or false on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.1.3.

\sa SDL_ShowMessageBox

extern SDL_DECLSPEC bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window)

Implementation

bool sdlShowSimpleMessageBox(
    int flags, String? title, String? message, Pointer<SdlWindow> window) {
  final sdlShowSimpleMessageBoxLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(Uint32 flags, Pointer<Utf8> title, Pointer<Utf8> message,
          Pointer<SdlWindow> window),
      int Function(int flags, Pointer<Utf8> title, Pointer<Utf8> message,
          Pointer<SdlWindow> window)>('SDL_ShowSimpleMessageBox');
  final titlePointer = title != null ? title.toNativeUtf8() : nullptr;
  final messagePointer = message != null ? message.toNativeUtf8() : nullptr;
  final result = sdlShowSimpleMessageBoxLookupFunction(
          flags, titlePointer, messagePointer, window) ==
      1;
  calloc.free(titlePointer);
  calloc.free(messagePointer);
  return result;
}