fix & improve platform popups
This commit is contained in:
102
src/main.cpp
102
src/main.cpp
@@ -102,6 +102,10 @@ struct AppState {
|
||||
B32 show_settings_window;
|
||||
B32 show_about_window;
|
||||
B32 show_confirm_dialog;
|
||||
|
||||
// Pop-out windows
|
||||
B32 show_mix_popout;
|
||||
B32 show_patch_popout;
|
||||
S32 settings_theme_sel;
|
||||
S32 settings_theme_prev;
|
||||
B32 settings_vsync;
|
||||
@@ -1165,7 +1169,39 @@ static void build_header_bar(AppState *app) {
|
||||
CLAY_TEXT(CLAY_STRING("Mix"), mix_active ? &header_btn_active_text : &g_text_config_normal);
|
||||
}
|
||||
if (mix_hovered && g_wstate.mouse_clicked) {
|
||||
app->master_layout = 1;
|
||||
PopupWindow *mix_pop = popup_find_by_flag(&app->show_mix_popout);
|
||||
if (mix_pop) {
|
||||
platform_focus_window(mix_pop->platform_window);
|
||||
} else {
|
||||
app->master_layout = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mix pop-out / pop-in button
|
||||
{
|
||||
B32 mix_popped = app->show_mix_popout;
|
||||
Clay_ElementId pop_eid = CLAY_ID("BtnMixPopOut");
|
||||
B32 pop_hovered = Clay_PointerOver(pop_eid);
|
||||
CLAY(pop_eid,
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_FIXED(uis(22)), .height = CLAY_SIZING_FIXED(uis(22)) },
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
|
||||
},
|
||||
.backgroundColor = pop_hovered ? g_theme.accent_hover : g_theme.bg_lighter,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(CORNER_RADIUS),
|
||||
) {
|
||||
ui_icon(mix_popped ? UI_ICON_POP_IN : UI_ICON_POP_OUT, uis(12), g_theme.text_dim);
|
||||
}
|
||||
if (pop_hovered && g_wstate.mouse_clicked) {
|
||||
if (mix_popped) {
|
||||
PopupWindow *p = popup_find_by_flag(&app->show_mix_popout);
|
||||
if (p) popup_close(p);
|
||||
app->master_layout = 1;
|
||||
} else {
|
||||
app->show_mix_popout = 1;
|
||||
if (app->master_layout == 1) app->master_layout = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1188,7 +1224,39 @@ static void build_header_bar(AppState *app) {
|
||||
CLAY_TEXT(CLAY_STRING("Patch"), patch_active ? &header_btn_active_text : &g_text_config_normal);
|
||||
}
|
||||
if (patch_hovered && g_wstate.mouse_clicked) {
|
||||
app->master_layout = 2;
|
||||
PopupWindow *patch_pop = popup_find_by_flag(&app->show_patch_popout);
|
||||
if (patch_pop) {
|
||||
platform_focus_window(patch_pop->platform_window);
|
||||
} else {
|
||||
app->master_layout = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Patch pop-out / pop-in button
|
||||
{
|
||||
B32 patch_popped = app->show_patch_popout;
|
||||
Clay_ElementId pop_eid = CLAY_ID("BtnPatchPopOut");
|
||||
B32 pop_hovered = Clay_PointerOver(pop_eid);
|
||||
CLAY(pop_eid,
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_FIXED(uis(22)), .height = CLAY_SIZING_FIXED(uis(22)) },
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
|
||||
},
|
||||
.backgroundColor = pop_hovered ? g_theme.accent_hover : g_theme.bg_lighter,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(CORNER_RADIUS),
|
||||
) {
|
||||
ui_icon(patch_popped ? UI_ICON_POP_IN : UI_ICON_POP_OUT, uis(12), g_theme.text_dim);
|
||||
}
|
||||
if (pop_hovered && g_wstate.mouse_clicked) {
|
||||
if (patch_popped) {
|
||||
PopupWindow *p = popup_find_by_flag(&app->show_patch_popout);
|
||||
if (p) popup_close(p);
|
||||
app->master_layout = 2;
|
||||
} else {
|
||||
app->show_patch_popout = 1;
|
||||
if (app->master_layout == 2) app->master_layout = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1676,6 +1744,17 @@ static void build_patch_view(AppState *app) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Pop-out window content callbacks
|
||||
|
||||
static void mix_popout_content(void *user_data) {
|
||||
build_mix_view((AppState *)user_data);
|
||||
}
|
||||
|
||||
static void patch_popout_content(void *user_data) {
|
||||
build_patch_view((AppState *)user_data);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Build the full UI layout for one frame
|
||||
|
||||
@@ -1736,11 +1815,15 @@ static void build_ui(AppState *app) {
|
||||
|
||||
build_log_panel(app);
|
||||
} else if (app->master_layout == 1) {
|
||||
// === MIX MODE ===
|
||||
build_mix_view(app);
|
||||
// === MIX MODE (skip if popped out) ===
|
||||
if (!app->show_mix_popout) {
|
||||
build_mix_view(app);
|
||||
}
|
||||
} else {
|
||||
// === PATCH MODE ===
|
||||
build_patch_view(app);
|
||||
// === PATCH MODE (skip if popped out) ===
|
||||
if (!app->show_patch_popout) {
|
||||
build_patch_view(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1783,6 +1866,9 @@ static void do_frame(AppState *app) {
|
||||
// Gather input
|
||||
PlatformInput input = platform_get_input(app->window);
|
||||
|
||||
// Sync scale from popups (they may have changed g_ui_scale)
|
||||
app->ui_scale = g_ui_scale;
|
||||
|
||||
// Cmd+= / Cmd+- (or Ctrl on Windows) to zoom UI, Cmd+0 to reset
|
||||
for (S32 k = 0; k < input.key_count; k++) {
|
||||
if (input.ctrl_held) {
|
||||
@@ -1973,6 +2059,10 @@ int main(int argc, char **argv) {
|
||||
popup_open(window, renderer, "Preferences", &app.show_settings_window, 480, 400, settings_window_content, &app);
|
||||
if (app.show_about_window && !popup_find_by_flag(&app.show_about_window))
|
||||
popup_open(window, renderer, "About", &app.show_about_window, 260, 200, about_window_content, nullptr);
|
||||
if (app.show_mix_popout && !popup_find_by_flag(&app.show_mix_popout))
|
||||
popup_open(window, renderer, "Mix", &app.show_mix_popout, 900, 600, mix_popout_content, &app, PLATFORM_WINDOW_STYLE_POPUP_RESIZABLE, 1);
|
||||
if (app.show_patch_popout && !popup_find_by_flag(&app.show_patch_popout))
|
||||
popup_open(window, renderer, "Patch", &app.show_patch_popout, 900, 600, patch_popout_content, &app, PLATFORM_WINDOW_STYLE_POPUP_RESIZABLE, 1);
|
||||
|
||||
// Check for OS close on popups
|
||||
popup_close_check();
|
||||
|
||||
Reference in New Issue
Block a user