Skip to content

Message Boxes

Native modal dialogs for alerts and user prompts.

Simple Message Boxes

Display basic alerts with an OK button:

laya::context ctx{laya::subsystem::video};

// Information message
laya::show_simple_messagebox(
    laya::messagebox_flags::information,
    "Success",
    "Operation completed successfully."
);

// Warning message
laya::show_simple_messagebox(
    laya::messagebox_flags::warning,
    "Warning",
    "This action cannot be undone."
);

// Error message
laya::show_simple_messagebox(
    laya::messagebox_flags::error,
    "Error",
    "Failed to load configuration file."
);

Custom Dialogs

Create dialogs with multiple buttons and custom behavior:

// Yes/No dialog
std::array<laya::messagebox_button, 2> buttons = {
    laya::messagebox_button{1, "Yes", laya::messagebox_button_flags::returnkey_default},
    laya::messagebox_button{0, "No", laya::messagebox_button_flags::escapekey_default}
};

auto result = laya::show_messagebox(
    laya::messagebox_flags::information,
    "Confirm",
    "Do you want to continue?",
    buttons
);

if (result.has_value()) {
    if (result.value() == 1) {
        // User clicked Yes
    } else {
        // User clicked No
    }
}

Button Flags

Control button behavior:

  • returnkey_default - Activated by pressing Enter/Return
  • escapekey_default - Activated by pressing Escape
std::array<laya::messagebox_button, 3> buttons = {
    laya::messagebox_button{1, "Save", laya::messagebox_button_flags::returnkey_default},
    laya::messagebox_button{0, "Don't Save"},
    laya::messagebox_button{-1, "Cancel", laya::messagebox_button_flags::escapekey_default}
};

Custom Colors

Apply custom color schemes (platform support varies):

laya::messagebox_color_scheme dark_theme{
    .background = {30, 30, 30},
    .text = {220, 220, 220},
    .button_border = {100, 100, 100},
    .button_background = {50, 50, 50},
    .button_selected = {70, 130, 180}
};

laya::show_messagebox(
    laya::messagebox_flags::information,
    "Dark Mode",
    "This dialog uses a custom color scheme.",
    buttons,
    nullptr,  // No parent window
    &dark_theme
);

Parent Windows

Attach dialogs to specific windows:

laya::window window{"App", {800, 600}};

laya::show_simple_messagebox(
    laya::messagebox_flags::information,
    "Info",
    "This dialog is attached to the main window.",
    &window
);

Return Values

  • show_simple_messagebox() returns bool (success/failure)
  • show_messagebox() returns std::optional<int> containing the button ID, or std::nullopt on failure

Notes

  • Message boxes are modal and blocking - they freeze the calling thread until dismissed
  • Can be called before SDL_Init() for startup errors
  • Use native system dialogs where available
  • Color schemes may not be supported on all platforms
  • Button order can be controlled with buttons_left_to_right or buttons_right_to_left flags