From 0ce031e32489bfb997945d50831701179aeee2b0 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 19 Dec 2025 18:46:48 -0600 Subject: [PATCH] panel resize testing --- src/pp/pp_vis/pp_vis_core.c | 82 ++++++++++++++++++++++++++++++++----- src/pp/pp_vis/pp_vis_core.h | 2 +- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index ef1bd9ed..04c7607f 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -68,6 +68,9 @@ V_WidgetTheme V_GetWidgetTheme(void) // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/fixedsys.ttf"))); // theme.font_size = 16; + // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/seguisb.ttf"))); + // theme.font_size = 16; + theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/seguisb.ttf"))); theme.font_size = 16; @@ -797,10 +800,7 @@ void V_TickForever(WaveLaneCtx *lane) V_Panel *panel = PushStruct(perm, V_Panel); panel->key = UI_TransKey(); /* TODO: Don't use transient keys for panels */ panel->axis = Axis_X; - // panel->pref_size[Axis_X] = UI_PIX(frame->ui_dims.x, 0); - // panel->pref_size[Axis_Y] = UI_PIX(frame->ui_dims.y, 0); - panel->pref_size[Axis_X] = UI_GROW(1, 0); - panel->pref_size[Axis_Y] = UI_GROW(1, 0); + panel->pref_ratio = 1; panel->is_organizing_panel = 1; V.root_panel = panel; } @@ -810,8 +810,6 @@ void V_TickForever(WaveLaneCtx *lane) panel->parent = V.root_panel; panel->key = UI_TransKey(); /* TODO: Don't use transient keys */ panel->axis = !panel->parent->axis; - panel->pref_size[Axis_X] = UI_GROW(1, 0); - panel->pref_size[Axis_Y] = UI_GROW(1, 0); DllQueuePush(panel->parent->first, panel->parent->last, panel); ++panel->parent->count; @@ -839,11 +837,11 @@ void V_TickForever(WaveLaneCtx *lane) panel->parent = V.root_panel; panel->key = UI_TransKey(); /* TODO: Don't use transient keys */ panel->axis = !panel->parent->axis; - panel->pref_size[Axis_X] = UI_GROW(1, 0); - panel->pref_size[Axis_Y] = UI_GROW(1, 0); DllQueuePush(panel->parent->first, panel->parent->last, panel); ++panel->parent->count; + panel->pref_ratio = 0.5; + { V_Window *window = PushStruct(perm, V_Window); window->panel = panel; @@ -853,6 +851,33 @@ void V_TickForever(WaveLaneCtx *lane) ++panel->windows_count; } } + + { + V_Panel *panel = PushStruct(perm, V_Panel); + panel->parent = V.root_panel; + panel->key = UI_TransKey(); /* TODO: Don't use transient keys */ + panel->axis = !panel->parent->axis; + DllQueuePush(panel->parent->first, panel->parent->last, panel); + ++panel->parent->count; + + { + V_Window *window = PushStruct(perm, V_Window); + window->panel = panel; + window->key = UI_TransKey(); /* TODO: Don't use transient keys */ + // window->is_tile_window = 1; + DllQueuePushNP(panel->first_window, panel->last_window, window, next_in_panel, prev_in_panel); + ++panel->windows_count; + } + { + V_Window *window = PushStruct(perm, V_Window); + window->panel = panel; + window->key = UI_TransKey(); /* TODO: Don't use transient keys */ + window->is_tile_window = 1; + DllQueuePushNP(panel->first_window, panel->last_window, window, next_in_panel, prev_in_panel); + ++panel->windows_count; + } + panel->active_window_idx = 1; + } } if (frame->is_editing) @@ -869,15 +894,27 @@ void V_TickForever(WaveLaneCtx *lane) if (!panel_dfs->visited) { panel_dfs->visited = 1; + + /* Push children to dfs stack */ + f32 ratio_accum = 0; for (V_Panel *child = panel->last; child; child = child->prev) { PanelDfsNode *n = PushStruct(frame->arena, PanelDfsNode); + ratio_accum += child->pref_ratio; n->panel = child; SllStackPush(first_panel_dfs, n); } - UI_SetNext(Width, panel->pref_size[Axis_X]); - UI_SetNext(Height, panel->pref_size[Axis_Y]); + /* Constrain child raitos */ + for (V_Panel *child = panel->last; child; child = child->prev) + { + child->pref_ratio += (1.0 - ratio_accum) / panel->count; + // child->pref_ratio = MaxF32(child->pref_ratio, 0.01); + } + + + UI_SetNext(AxisSize, UI_GROW(panel->pref_ratio, 0), .axis = !panel->axis); + UI_SetNext(AxisSize, UI_GROW(1, 0), .axis = panel->axis); if (panel->axis == Axis_X) { UI_BuildRowEx(panel->key); @@ -1018,6 +1055,31 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(AxisSize, UI_PIX(3, 1), .axis = !panel->axis); /* FIXME: Non-transient key */ UI_BuildBoxEx(divider_key); + + if (rep.is_m1_held) + { + UI_Report panel_rep = UI_ReportFromKey(panel->key); + UI_Report parent_rep = UI_ReportFromKey(panel->parent->key); + + /* FIXME: Height */ + f32 parent_width = DimsFromRng2(parent_rep.screen_rect).x; + + f32 old_ratio = panel->pref_ratio; + // f32 new_ratio = MaxF32((frame->ui_cursor.x - panel_rep.screen_rect.p0.x) / parent_width, 0.01); + f32 new_ratio = MaxF32(frame->ui_cursor.x - panel_rep.screen_rect.p0.x, 20) / parent_width; + f32 ratio_diff = new_ratio - old_ratio; + panel->pref_ratio = new_ratio; + + if (ratio_diff > 0.1) + { + DEBUGBREAKABLE; + } + + if (panel->next) + { + panel->next->pref_ratio -= ratio_diff; + } + } } UI_Pop(Tag); diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index cafb4e6c..3ef0227c 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -160,7 +160,7 @@ Struct(V_Panel) UI_Key key; - UI_Size pref_size[Axis_CountXY]; + f32 pref_ratio; Axis axis; b32 is_organizing_panel;