Add modals!
This commit is contained in:
78
src/main.cpp
78
src/main.cpp
@@ -65,6 +65,14 @@ struct AppState {
|
||||
char demo_text_a[128];
|
||||
char demo_text_b[128];
|
||||
int32_t demo_button_count;
|
||||
|
||||
// Modal / window demo state
|
||||
B32 show_settings_window;
|
||||
B32 show_about_window;
|
||||
B32 show_confirm_dialog;
|
||||
S32 settings_theme_sel;
|
||||
B32 settings_vsync;
|
||||
B32 settings_autosave;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -221,6 +229,31 @@ static void build_main_panel(AppState *app) {
|
||||
static const char *rate_options[] = { "44100 Hz", "48000 Hz", "88200 Hz", "96000 Hz", "192000 Hz" };
|
||||
ui_dropdown("DropRate", rate_options, 5, &app->demo_dropdown_sel);
|
||||
}
|
||||
|
||||
CLAY(CLAY_ID("Sep5"),
|
||||
.layout = { .sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_FIXED(1) } },
|
||||
.backgroundColor = g_theme.border
|
||||
) {}
|
||||
|
||||
// Section: Windows & Modals
|
||||
ui_label("LblWindows", "Windows & Modals");
|
||||
CLAY(CLAY_ID("WindowBtnRow"),
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_FIT(), .height = CLAY_SIZING_FIT() },
|
||||
.childGap = 8,
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||
}
|
||||
) {
|
||||
if (ui_button("BtnSettings", "Settings")) {
|
||||
app->show_settings_window = 1;
|
||||
}
|
||||
if (ui_button("BtnAbout", "About")) {
|
||||
app->show_about_window = 1;
|
||||
}
|
||||
if (ui_button("BtnConfirm", "Confirm Dialog")) {
|
||||
app->show_confirm_dialog = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,6 +482,31 @@ static void build_log_panel(B32 show) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Window content callbacks
|
||||
|
||||
static void settings_window_content(void *user_data) {
|
||||
AppState *app = (AppState *)user_data;
|
||||
|
||||
ui_label("SettingsLblTheme", "Theme");
|
||||
static const char *theme_options[] = { "Dark", "Light", "Solarized" };
|
||||
CLAY(CLAY_ID("SettingsThemeWrap"),
|
||||
.layout = { .sizing = { .width = CLAY_SIZING_FIXED(180), .height = CLAY_SIZING_FIT() } }
|
||||
) {
|
||||
ui_dropdown("SettingsTheme", theme_options, 3, &app->settings_theme_sel);
|
||||
}
|
||||
|
||||
ui_checkbox("SettingsVsync", "V-Sync", &app->settings_vsync);
|
||||
ui_checkbox("SettingsAutosave", "Autosave", &app->settings_autosave);
|
||||
}
|
||||
|
||||
static void about_window_content(void *user_data) {
|
||||
(void)user_data;
|
||||
ui_label("AboutLbl1", "autosample v0.1");
|
||||
ui_label("AboutLbl2", "An audio sampling workstation.");
|
||||
ui_label("AboutLbl3", "Built with Clay UI.");
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Build the full UI layout for one frame
|
||||
|
||||
@@ -485,6 +543,26 @@ static void build_ui(AppState *app) {
|
||||
|
||||
build_log_panel(app->show_log);
|
||||
}
|
||||
|
||||
// Draggable windows (rendered as floating elements above normal UI)
|
||||
ui_window("WinSettings", "Settings", &app->show_settings_window,
|
||||
Vec2F32{100, 100}, Vec2F32{280, 0},
|
||||
settings_window_content, app);
|
||||
|
||||
ui_window("WinAbout", "About", &app->show_about_window,
|
||||
Vec2F32{200, 150}, Vec2F32{260, 0},
|
||||
about_window_content, nullptr);
|
||||
|
||||
// Modal confirmation dialog
|
||||
if (app->show_confirm_dialog) {
|
||||
static const char *confirm_buttons[] = { "Cancel", "OK" };
|
||||
S32 modal_result = ui_modal("ModalConfirm", "Confirm Action",
|
||||
"Are you sure you want to proceed? This action cannot be undone.",
|
||||
confirm_buttons, 2);
|
||||
if (modal_result != -1) {
|
||||
app->show_confirm_dialog = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user