diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index bbfe088b..6cd77785 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -1044,18 +1044,22 @@ void V_TickForever(WaveLaneCtx *lane) // Set widget theme V_PushWidgetThemeStyles(theme); - UI_Key vis_box = UI_KeyF("vis box"); - UI_BoxReports vis_box_reps = UI_ReportsFromKey(vis_box); + UI_Push(ChildLayoutAxis, Axis_Y); + UI_Push(Width, UI_GROW(1, 0)); + UI_Push(Height, UI_GROW(1, 0)); + UI_Key vis_game_box = UI_KeyF("vis game box"); + UI_Key vis_ui_box = UI_KeyF("vis ui box"); + UI_BoxReports vis_game_box_reps = UI_ReportsFromKey(vis_game_box); { - UI_Push(ChildLayoutAxis, Axis_Y); - UI_Push(Width, UI_GROW(1, 0)); - UI_Push(Height, UI_GROW(1, 0)); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_Push(Parent, UI_BuildColumnEx(vis_box)); + UI_BuildColumnEx(vis_game_box); + + // NOTE: Vis ui box is built by panel tree + UI_Push(Parent, vis_ui_box); } // TODO: Don't rely on ui report for draw size since it introduces one frame of delay when resizing - frame->screen_dims = RoundVec2(DimsFromRng2(vis_box_reps.draw.screen_rect)); + frame->screen_dims = RoundVec2(DimsFromRng2(vis_game_box_reps.draw.screen_rect)); frame->screen_dims.x = MaxF32(frame->screen_dims.x, 64); frame->screen_dims.y = MaxF32(frame->screen_dims.y, 64); @@ -1113,7 +1117,7 @@ void V_TickForever(WaveLaneCtx *lane) V_TextboxDeltaList text_input_deltas = Zi; - frame->has_mouse_focus = UI_IsKeyNil(ui_frame->hot_box) || UI_MatchKey(ui_frame->hot_box, vis_box); + frame->has_mouse_focus = UI_IsKeyNil(ui_frame->hot_box) || UI_MatchKey(ui_frame->hot_box, vis_game_box); frame->has_keyboard_focus = 1; Vec2 mouse_delta = Zi; { @@ -3494,131 +3498,6 @@ void V_TickForever(WaveLaneCtx *lane) P_tl.debug_draw_nodes_count = 0; } - ////////////////////////////// - //- Build notifications - - { - i64 duration_ns = NsFromSeconds(10); - i64 min_notif_time_ns = frame->time_ns - duration_ns; - i64 max_notifs = 10; - - // Collect recent notifications - i64 draw_notifs_count = 0; - V_Notif **draw_notifs = PushStructs(frame->arena, V_Notif *, max_notifs); - { - i64 notif_idx = 0; - for (V_Notif *notif = V.first_notif; notif; notif = notif->next) - { - if (notif_idx < max_notifs && notif->time_ns > min_notif_time_ns) - { - draw_notifs[draw_notifs_count] = notif; - draw_notifs_count += 1; - } - else - { - break; - } - notif_idx += 1; - } - } - - // Build notification UI - { - UI_Key notifs_key = UI_KeyF("notifs"); - UI_BoxReport notifs_rep = UI_ReportsFromKey(notifs_key).draw; - - f32 width = 600; - - Vec2 pos = Zi; - pos.x = 10; - // pos.y = frame->screen_dims.y * 0.5 - DimsFromRng2(notifs_rep.screen_rect).y * 0.5; - pos.y = 10; - - // Vec4 bg = VEC4(0, 0, 0, 0.25); - Vec4 bg = VEC4(0, 0, 0, 0); - - UI_SetNext(Width, UI_PIX(width, 0)); - // UI_SetNext(Height, UI_PIX(height, 0)); - // UI_SetNext(Width, UI_GROW(0.9, 0)); - // UI_SetNext(Width, UI_SHRINK(0, 0)); - UI_SetNext(Height, UI_SHRINK(0, 0)); - UI_SetNext(FloatingPos, pos); - UI_SetNext(BackgroundColor, bg); - UI_SetNext(Rounding, 0); - UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_PushCP(UI_BuildColumnEx(notifs_key)); - { - UI_Push(ChildAlignment, UI_Region_Left); - UI_Push(Font, theme.chat_font); - UI_Push(FontSize, theme.chat_font_size); - for (i64 notif_idx = draw_notifs_count - 1; notif_idx >= 0; --notif_idx) - { - V_Notif *notif = draw_notifs[notif_idx]; - - f32 opacity = 1.0; - f32 fade_curve = 0.8; - { - i64 remaining_ns = notif->time_ns - min_notif_time_ns; - opacity = PowF64(((f64)remaining_ns / (f64)duration_ns), fade_curve); - } - - UI_SetNext(Tint, 0); - UI_SetNext(Width, UI_SHRINK(0, 0)); - UI_SetNext(Height, UI_SHRINK(0, 0)); - UI_PushCP(UI_BuildRow()); - { - UI_Push(Tint, VEC4(1, 1, 1, opacity)); - UI_Push(Width, UI_SHRINK(0, 0)); - UI_Push(Height, UI_SHRINK(0, 0)); - { - String msg = StringF( - frame->arena, - "[%F:%F:%F] ", - FmtUint(notif->datetime.hour % 12, .z = 2), - FmtUint(notif->datetime.minute, .z = 2), - FmtUint(notif->datetime.second, .z = 2) - ); - Vec4 col = UI_Top(TextColor); - if (notif->seq % 2 == 0) - { - col.x = 0.55; - col.y = 0.52; - col.z = 0.49; - } - else - { - col.x = 0.49; - col.y = 0.52; - col.z = 0.55; - } - - UI_SetNext(TextColor, col); - UI_SetNext(Text, msg); - UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_BuildRow(); - } - { - String msg = notif->msg; - UI_SetNext(Text, msg); - UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_BuildRow(); - } - } - UI_PopCP(UI_TopCP()); - - if (notif_idx != 0) - { - UI_BuildSpacer(UI_PIX(5, 0), Axis_Y); - } - } - } - - UI_PopCP(UI_TopCP()); - } - - - } - ////////////////////////////// //- Init test layout @@ -3642,6 +3521,7 @@ void V_TickForever(WaveLaneCtx *lane) panel->key = UI_RandKey(); // TODO: Don't use random keys panel->axis = !panel->parent->axis; panel->pref_ratio = 0.15; + panel->is_editor_panel = 1; DllQueuePush(panel->parent->first, panel->parent->last, panel); ++panel->parent->count; ++V.panels_count; @@ -3679,14 +3559,14 @@ void V_TickForever(WaveLaneCtx *lane) { V_Panel *panel = PushStruct(perm, V_Panel); panel->parent = V.root_panel; - panel->key = UI_RandKey(); // TODO: Don't use random keys + panel->key = vis_ui_box; panel->axis = !panel->parent->axis; DllQueuePush(panel->parent->first, panel->parent->last, panel); ++panel->parent->count; ++V.panels_count; panel->pref_ratio = 0.85; - panel->is_viewport_panel = 1; + panel->is_vis_ui_panel = 1; // { // V_Window *window = PushStruct(perm, V_Window); @@ -3733,7 +3613,8 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Build panels - if (show_editor_ui && frame->is_editing) + UI_PushDF(Parent, vis_game_box) + // if (show_editor_ui && frame->is_editing) { Struct(PanelDfsNode) { PanelDfsNode *next; b32 visited; V_Panel *panel; UI_Checkpoint cp; }; PanelDfsNode *first_panel_dfs = PushStruct(frame->arena, PanelDfsNode); @@ -3746,6 +3627,24 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Walk panel tree + + + + + + + + + // FIXME: Remove this + #define V_ShouldSkipPanel(panel) (panel->is_editor_panel && (!frame->is_editing || !show_editor_ui)) + + + + + + + + while (first_panel_dfs) { PanelDfsNode *panel_dfs = first_panel_dfs; @@ -3769,12 +3668,15 @@ void V_TickForever(WaveLaneCtx *lane) V_Panel *resize_panel = 0; for (V_Panel *child = panel->last; child; child = child->prev) { - PanelDfsNode *n = PushStruct(frame->arena, PanelDfsNode); - n->panel = child; - SllStackPush(first_panel_dfs, n); - if (child->resizing) + if (!V_ShouldSkipPanel(child)) { - resize_panel = child; + PanelDfsNode *n = PushStruct(frame->arena, PanelDfsNode); + n->panel = child; + SllStackPush(first_panel_dfs, n); + if (child->resizing) + { + resize_panel = child; + } } } @@ -3812,12 +3714,18 @@ void V_TickForever(WaveLaneCtx *lane) } for (V_Panel *child = panel->last; child; child = child->prev) { - child->pref_ratio = MaxF32(child->pref_ratio, 0.01); - ratio_accum += child->pref_ratio; + if (!V_ShouldSkipPanel(child)) + { + child->pref_ratio = MaxF32(child->pref_ratio, 0.01); + ratio_accum += child->pref_ratio; + } } for (V_Panel *child = panel->last; child; child = child->prev) { - child->pref_ratio += (1.0 - ratio_accum) / panel->count; + if (!V_ShouldSkipPanel(child)) + { + child->pref_ratio += (1.0 - ratio_accum) / panel->count; + } } UI_SetNext(AxisSize, UI_GROW(panel->pref_ratio, 0), .axis = !panel->axis); @@ -3831,12 +3739,12 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildColumnEx(panel->key); } UI_Push(Tag, panel->key.v); - panel_dfs->cp = UI_PushCP(panel->key); + panel_dfs->cp = UI_PushCp(panel->key); - if (!panel->is_organizing_panel && !panel->is_viewport_panel) + if (!panel->is_organizing_panel && !panel->is_vis_ui_panel) { i64 new_active_window_idx = panel->active_window_idx; - UI_PushCP(UI_BuildColumn()); + UI_PushCp(UI_BuildColumn()); { UI_Push(Tint, VEC4(1, 1, 1, 0.90 * panel_rep.exists)); @@ -3855,7 +3763,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_SHRINK(0, 1)); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(tab_row_key)); + UI_PushCp(UI_BuildRowEx(tab_row_key)); ////////////////////////////// //- Prep drawable tabs @@ -4009,7 +3917,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(ChildAlignment, UI_Region_Left); UI_SetNext(Misc, window == active_window); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(tab->key)); + UI_PushCp(UI_BuildRowEx(tab->key)); { UI_BuildSpacer(UI_PIX(tab_spacing, 0), Axis_X); @@ -4042,7 +3950,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); UI_SetNext(Width, UI_SHRINK(0, 0)); UI_SetNext(Height, UI_GROW(1, 0)); - UI_PushCP(UI_BuildRowEx(close_key)); + UI_PushCp(UI_BuildRowEx(close_key)); { UI_BuildSpacer(UI_PIX(tab_spacing * 2, 0), Axis_X); @@ -4053,7 +3961,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildSpacer(UI_PIX(tab_spacing * 2, 0), Axis_X); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); if (close_rep.m1.presses) { @@ -4062,7 +3970,7 @@ void V_TickForever(WaveLaneCtx *lane) } } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } UI_Pop(Tag); } break; @@ -4091,10 +3999,10 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Height, UI_GROW(1, 0)); UI_SetNext(ChildAlignment, UI_Region_Center); // UI_SetNext(FontSize, theme.font_size * 1.5); - UI_PushCP(UI_BuildRowEx(tab->key)); + UI_PushCp(UI_BuildRowEx(tab->key)); { } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } break; ////////////////////////////// @@ -4119,19 +4027,19 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(ChildAlignment, UI_Region_Center); // UI_SetNext(FontSize, theme.font_size * 1.5); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(key)); + UI_PushCp(UI_BuildRowEx(key)); { UI_SetNext(Width, UI_SHRINK(0, 1)); UI_SetNext(Height, UI_SHRINK(0, 1)); UI_SetNext(FontSize, UI_Top(FontSize) * theme.micro); UI_BuildIcon(theme.icon_font, UI_Icon_Plus); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } UI_BuildSpacer(UI_PIX(tab_spacing, 0), Axis_X); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } ////////////////////////////// @@ -4149,7 +4057,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_GROW(1, 0)); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildColumn()); + UI_PushCp(UI_BuildColumn()); { UI_Push(Tag, window->key.v); @@ -4191,7 +4099,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Misc, is_selected); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); UI_SetNext(ChildAlignment, UI_Region_Left); - UI_PushCP(UI_BuildRowEx(key)); + UI_PushCp(UI_BuildRowEx(key)); { UI_BuildSpacer(UI_FNT(0.25, 0), Axis_X); @@ -4220,7 +4128,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildRow(); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } @@ -4265,7 +4173,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Misc, is_selected); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); UI_SetNext(ChildAlignment, UI_Region_Left); - UI_PushCP(UI_BuildRowEx(key)); + UI_PushCp(UI_BuildRowEx(key)); { UI_BuildSpacer(UI_FNT(0.25, 0), Axis_X); @@ -4294,21 +4202,21 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildRow(); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); panel->active_window_idx = new_active_window_idx; } } else { - UI_PopCP(panel_dfs->cp); + UI_PopCp(panel_dfs->cp); SllStackPop(first_panel_dfs); ////////////////////////////// @@ -4408,6 +4316,7 @@ void V_TickForever(WaveLaneCtx *lane) //- Build command palette V_Palette *palette = &frame->palette; + UI_PushDF(Parent, UI_RootKey) { UI_Push(Tag, HashF("developer command palette")); @@ -4498,7 +4407,7 @@ void V_TickForever(WaveLaneCtx *lane) f32 tweak_size_px = UI_FNT(1.25, 1).v; palette->key = UI_KeyF("command palette"); - UI_Checkpoint palette_cp = UI_PushCP(UI_NilKey); + UI_Checkpoint palette_cp = UI_PushCp(UI_NilKey); { UI_Push(Tag, palette->key.v); UI_Key titlebar_key = UI_KeyF("title bar"); @@ -4532,12 +4441,12 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(ChildLayoutAxis, Axis_Y); UI_SetNext(Anchor, UI_Region_Center); UI_SetNext(Flags, UI_BoxFlag_Floating | (UI_BoxFlag_CaptureMouse * !!palette->is_showing)); - UI_PushCP(UI_BuildBoxEx(palette->key)); + UI_PushCp(UI_BuildBoxEx(palette->key)); { ////////////////////////////// //- Build title bar - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { UI_Push(BackgroundColor, titlebar_color); UI_Push(BorderColor, titlebar_border_color); @@ -4546,7 +4455,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_Push(Width, UI_GROW(1, 0)); UI_Push(Height, header_height); UI_SetNext(Flags, UI_BoxFlag_DrawText | (UI_BoxFlag_CaptureMouse * !!palette->is_showing)); - UI_PushCP(UI_BuildBoxEx(titlebar_key)); + UI_PushCp(UI_BuildBoxEx(titlebar_key)); { UI_Push(Width, UI_GROW(1, 0)); UI_Push(BorderColor, 0); @@ -4567,16 +4476,16 @@ void V_TickForever(WaveLaneCtx *lane) // Right title box UI_BuildRow(); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); //- Window box UI_SetNext(BackgroundColor, 0); UI_SetNext(Rounding, 0); UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_GROW(1, 0)); - UI_PushCP(UI_BuildRow()); + UI_PushCp(UI_BuildRow()); { UI_BuildSpacer(window_padding, Axis_X); @@ -4584,7 +4493,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Rounding, 0); UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_GROW(1, 0)); - UI_PushCP(UI_BuildColumn()); + UI_PushCp(UI_BuildColumn()); { ////////////////////////////// //- Build searchbox @@ -4598,7 +4507,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(ChildAlignment, UI_Region_Left); UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, search_height); - UI_PushCP(UI_BuildRow()); + UI_PushCp(UI_BuildRow()); { //- Search icon { @@ -4710,7 +4619,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(TextColor, display_text_color); UI_SetNext(Text, display_text); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(search_box)); + UI_PushCp(UI_BuildRowEx(search_box)); { f32 font_size = UI_Top(FontSize); GC_FontKey font = UI_Top(Font); @@ -4813,10 +4722,10 @@ void V_TickForever(WaveLaneCtx *lane) } } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } UI_BuildDivider(UI_PIX(1, 1), divider_color, Axis_Y); @@ -4830,12 +4739,12 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_GROW(1, 0)); UI_SetNext(Flags, UI_BoxFlag_Scissor); - UI_PushCP(UI_BuildRowEx(scissor_key)); + UI_PushCp(UI_BuildRowEx(scissor_key)); { // Items & Scrollbar group UI_SetNext(Tint, 0); UI_SetNext(Rounding, 0); - UI_PushCP(UI_BuildRow()); + UI_PushCp(UI_BuildRow()); { // Items box UI_SetNext(BackgroundColor, 0); @@ -4844,13 +4753,13 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Height, UI_SHRINK(0, 1)); UI_SetNext(FloatingPos, VEC2(0, -lister_offset)); UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampY); - UI_PushCP(UI_BuildRowEx(lister_key)); + UI_PushCp(UI_BuildRowEx(lister_key)); { UI_SetNext(Tint, 0); UI_SetNext(Rounding, 0); UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_SHRINK(0, 1)); - UI_PushCP(UI_BuildColumn()); + UI_PushCp(UI_BuildColumn()); { Enum(PaletteItemFlag) { @@ -4978,7 +4887,7 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Width, UI_PIX(total_width.v - window_padding.v * 2, 1)); UI_SetNext(Width, UI_GROW(1, 0)); UI_SetNext(Height, UI_FNT(1.5, 1)); - UI_PushCP(UI_BuildRow()); + UI_PushCp(UI_BuildRow()); { UI_SetNext(BackgroundColor, item_color); UI_SetNext(BorderColor, item_border_color); @@ -4990,7 +4899,7 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Height, UI_FNT(1, 0)); UI_SetNext(ChildAlignment, UI_Region_Left); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(item->key)); + UI_PushCp(UI_BuildRowEx(item->key)); { UI_Push(Tag, item->key.v); @@ -5103,10 +5012,10 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Width, UI_FNT(1.25, 1)); UI_SetNext(Height, UI_FNT(1.25, 1)); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(cb_key)); + UI_PushCp(UI_BuildRowEx(cb_key)); { } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } break; // Float tweak @@ -5179,7 +5088,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Height, UI_PIX(tweak_size_px * 0.75, 1)); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); UI_SetNext(Misc, ratio); - UI_PushCP(UI_BuildRowEx(slider_key)); + UI_PushCp(UI_BuildRowEx(slider_key)); { f32 marker_pos = ratio * (slider_dims.x - marker_dims.x); @@ -5210,7 +5119,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildBoxEx(marker_key); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } break; } @@ -5261,25 +5170,25 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(BorderSize, 1); UI_SetNext(ChildAlignment, UI_Region_Center); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_CaptureMouse); - UI_PushCP(UI_BuildRowEx(hotkey_key)); + UI_PushCp(UI_BuildRowEx(hotkey_key)); { } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } // UI_BuildSpacer(icon_col_width, Axis_X); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); @@ -5295,7 +5204,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildSpacer(window_padding, Axis_X); UI_SetNext(Width, scrollbar_width); - UI_PushCP(UI_BuildBoxEx(scrollbar_key)); + UI_PushCp(UI_BuildBoxEx(scrollbar_key)); { //- Scrollbar up button { @@ -5319,7 +5228,7 @@ void V_TickForever(WaveLaneCtx *lane) //- Scrollbar thumb { UI_SetNext(Height, UI_GROW(1, 0)); - UI_PushCP(UI_BuildBoxEx(track_key)); + UI_PushCp(UI_BuildBoxEx(track_key)); { Vec4 bg = theme.col.button_hot; Vec4 bd = bg; @@ -5340,7 +5249,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Anchor, UI_Region_Top); UI_BuildBoxEx(thumb_key); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } //- Scrollbar down button @@ -5362,14 +5271,14 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildIconEx(scrollbar_down_key, theme.icon_font, UI_Icon_ArrowDown2); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); UI_BuildDivider(UI_PIX(1, 1), divider_color, Axis_Y); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); UI_BuildSpacer(window_padding, Axis_X); // UI_BuildSpacer(UI_FNT(100, 1), Axis_Y); @@ -5421,7 +5330,7 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Width, scrollbar_width); - // UI_PushCP(UI_BuildBoxEx(scrollbar_key)); + // UI_PushCp(UI_BuildBoxEx(scrollbar_key)); // { // UI_Size thumb_height = UI_FNT(10, 1); @@ -5439,20 +5348,20 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Anchor, UI_Region_Top); // UI_BuildBoxEx(thumb_key); // } - // UI_PopCP(UI_TopCP()); + // UI_PopCp(UI_TopCp()); // } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); // UI_BuildSpacer(window_padding, Axis_Y); // UI_BuildDivider(UI_PIX(1, 1), divider_color, Axis_Y); UI_BuildSpacer(header_height, Axis_Y); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - // UI_PopCP(UI_TopCP()); - UI_PopCP(palette_cp); + // UI_PopCp(UI_TopCp()); + UI_PopCp(palette_cp); } UI_Pop(Tag); @@ -5467,6 +5376,116 @@ void V_TickForever(WaveLaneCtx *lane) + + + + + + + + + + + ////////////////////////////// + //- Build profiler + + + + + // FIXME: Finalize + + + + { + //- Init test samples + // FIXME: Remove this + Struct(SampleState) + { + i64 ready_samples_count; + Arena *samples_arena; + }; + Struct(Sample) + { + u64 zone_id; + u64 thread_id; + i64 start_ns; + i64 end_ns; + }; + PERSIST i64 sample_states_count = 1; + PERSIST SampleState *sample_states = 0; + if (!sample_states) + { + sample_states = PushStructs(perm, SampleState, sample_states_count); + for (i64 sample_state_idx = 0; sample_state_idx < sample_states_count; ++sample_state_idx) + { + SampleState *ss = &sample_states[sample_state_idx]; + ss->samples_arena = AcquireArena(Gibi(64)); + + + + + + + ss->ready_samples_count = 128; + for (i64 sample_idx = 0; sample_idx < ss->ready_samples_count; ++sample_idx) + { + Sample *sample = PushStruct(ss->samples_arena, Sample); + sample->zone_id = (u64)"Hello there"; + sample->thread_id = 0; + sample->start_ns = NsFromSeconds(sample_idx); + sample->end_ns = NsFromSeconds(sample_idx + 1); + } + } + } + + + + + //- Build profiler + UI_PushDF(Tag, HashF("profiler")) + { + UI_Size profiler_height = UI_FNT(20, 1); + UI_Size header_height = UI_FNT(1, 1); + + Vec4 profiler_color = theme.col.window_bg; + + UI_Key profiler_key = UI_KeyF("profiler"); + + UI_SetNext(BackgroundColor, profiler_color); + UI_PushDF(Width, UI_GROW(1, 0)) + UI_PushDF(Height, profiler_height) + UI_PushDF(Parent, UI_BuildBoxEx(profiler_key)) + { + // UI_PushDF(BackgroundColor, Color_Red) + UI_SetNext(BorderColor, Color_Red); + UI_SetNext(BorderSize, 1); + UI_PushDF(Height, header_height) + UI_PushDF(Parent, UI_BuildBox()) + { + } + } + } + } + + + + + + + + + + + + + + + + + + + + @@ -5602,14 +5621,14 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Anchor, UI_Region_Top); // // UI_SetNext(Flags, UI_BoxFlag_Floating | (UI_BoxFlag_CaptureMouse * !!is_showing)); // UI_SetNext(Flags, UI_BoxFlag_Floating); - // UI_PushCP(UI_BuildBoxEx(bla_box)); + // UI_PushCp(UI_BuildBoxEx(bla_box)); // { - // UI_PushCP(UI_BuildBoxEx(bla_tex_box)); + // UI_PushCp(UI_BuildBoxEx(bla_tex_box)); // { // } - // UI_PopCP(UI_TopCP()); + // UI_PopCp(UI_TopCp()); // } - // UI_PopCP(UI_TopCP()); + // UI_PopCp(UI_TopCp()); // } // UI_Pop(Tag); @@ -5621,7 +5640,7 @@ void V_TickForever(WaveLaneCtx *lane) // // f32 tweak_size_px = UI_FNT(1.25, 1).v; // // palette->key = UI_KeyF("command palette"); - // // UI_Checkpoint palette_cp = UI_PushCP(UI_NilKey); + // // UI_Checkpoint palette_cp = UI_PushCp(UI_NilKey); // // { // // UI_Push(Tag, palette->key.v); // // UI_Key titlebar_key = UI_KeyF("title bar"); @@ -5655,7 +5674,7 @@ void V_TickForever(WaveLaneCtx *lane) // // UI_Push(FloatingPos, palette->pos); // // UI_SetNext(Anchor, UI_Region_Center); // // UI_SetNext(Flags, UI_BoxFlag_Floating | (UI_BoxFlag_CaptureMouse * !!palette->is_showing)); - // // UI_PushCP(UI_BuildBoxEx(palette->key)); + // // UI_PushCp(UI_BuildBoxEx(palette->key)); // // } // } // } @@ -5670,6 +5689,145 @@ void V_TickForever(WaveLaneCtx *lane) + ////////////////////////////// + //- Build notifications + + { + i64 duration_ns = NsFromSeconds(10); + i64 min_notif_time_ns = frame->time_ns - duration_ns; + i64 max_notifs = 10; + + // Collect recent notifications + i64 draw_notifs_count = 0; + V_Notif **draw_notifs = PushStructs(frame->arena, V_Notif *, max_notifs); + { + i64 notif_idx = 0; + for (V_Notif *notif = V.first_notif; notif; notif = notif->next) + { + if (notif_idx < max_notifs && notif->time_ns > min_notif_time_ns) + { + draw_notifs[draw_notifs_count] = notif; + draw_notifs_count += 1; + } + else + { + break; + } + notif_idx += 1; + } + } + + // Build notification UI + { + UI_Key notifs_key = UI_KeyF("notifs"); + UI_BoxReport notifs_rep = UI_ReportsFromKey(notifs_key).draw; + + f32 width = 600; + + Vec2 pos = Zi; + pos.x = 10; + // pos.y = frame->screen_dims.y * 0.5 - DimsFromRng2(notifs_rep.screen_rect).y * 0.5; + pos.y = 10; + + // Vec4 bg = VEC4(0, 0, 0, 0.25); + Vec4 bg = VEC4(0, 0, 0, 0); + + UI_SetNext(Width, UI_PIX(width, 0)); + // UI_SetNext(Height, UI_PIX(height, 0)); + // UI_SetNext(Width, UI_GROW(0.9, 0)); + // UI_SetNext(Width, UI_SHRINK(0, 0)); + UI_SetNext(Height, UI_SHRINK(0, 0)); + // UI_SetNext(FloatingPos, pos); + UI_SetNext(BackgroundColor, bg); + UI_SetNext(Rounding, 0); + // UI_SetNext(Flags, UI_BoxFlag_Floating); + UI_PushCp(UI_BuildColumnEx(notifs_key)); + { + UI_Push(ChildAlignment, UI_Region_Left); + UI_Push(Font, theme.chat_font); + UI_Push(FontSize, theme.chat_font_size); + for (i64 notif_idx = draw_notifs_count - 1; notif_idx >= 0; --notif_idx) + { + V_Notif *notif = draw_notifs[notif_idx]; + + f32 opacity = 1.0; + f32 fade_curve = 0.8; + { + i64 remaining_ns = notif->time_ns - min_notif_time_ns; + opacity = PowF64(((f64)remaining_ns / (f64)duration_ns), fade_curve); + } + + UI_SetNext(Tint, 0); + UI_SetNext(Width, UI_SHRINK(0, 0)); + UI_SetNext(Height, UI_SHRINK(0, 0)); + UI_PushCp(UI_BuildRow()); + { + UI_Push(Tint, VEC4(1, 1, 1, opacity)); + UI_Push(Width, UI_SHRINK(0, 0)); + UI_Push(Height, UI_SHRINK(0, 0)); + { + String msg = StringF( + frame->arena, + "[%F:%F:%F] ", + FmtUint(notif->datetime.hour % 12, .z = 2), + FmtUint(notif->datetime.minute, .z = 2), + FmtUint(notif->datetime.second, .z = 2) + ); + Vec4 col = UI_Top(TextColor); + if (notif->seq % 2 == 0) + { + col.x = 0.55; + col.y = 0.52; + col.z = 0.49; + } + else + { + col.x = 0.49; + col.y = 0.52; + col.z = 0.55; + } + + UI_SetNext(TextColor, col); + UI_SetNext(Text, msg); + UI_SetNext(Flags, UI_BoxFlag_DrawText); + UI_BuildRow(); + } + { + String msg = notif->msg; + UI_SetNext(Text, msg); + UI_SetNext(Flags, UI_BoxFlag_DrawText); + UI_BuildRow(); + } + } + UI_PopCp(UI_TopCp()); + + if (notif_idx != 0) + { + UI_BuildSpacer(UI_PIX(5, 0), Axis_Y); + } + } + } + + UI_PopCp(UI_TopCp()); + } + + + } + + + + + + + + + + + + + + + ////////////////////////////// //- Build debug info UI @@ -5690,7 +5848,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Height, UI_SHRINK(0, 1)); UI_SetNext(BackgroundColor, color); UI_SetNext(Rounding, UI_RPIX(rounding)); - UI_PushCP(UI_BuildColumn()); + UI_PushCp(UI_BuildColumn()); { // UI_BuildSpacer(UI_PIX(10, 1), Axis_X); // UI_Push(ChildAlignment, UI_Region_Center); @@ -5698,12 +5856,12 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Height, UI_SHRINK(0, 1)); UI_SetNext(Width, UI_SHRINK(0, 1)); UI_SetNext(Height, UI_SHRINK(0, 1)); - UI_PushCP(UI_BuildRow()); + UI_PushCp(UI_BuildRow()); { UI_BuildSpacer(UI_PIX(padding, 1), Axis_X); UI_SetNext(Width, UI_SHRINK(0, 1)); UI_SetNext(Height, UI_SHRINK(0, 1)); - UI_PushCP(UI_BuildColumn()); + UI_PushCp(UI_BuildColumn()); { UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y); { @@ -5761,7 +5919,7 @@ void V_TickForever(WaveLaneCtx *lane) { { UI_Push(FontSize, UI_Top(FontSize) * theme.h2); - UI_BuildLabelF("CPU:"); + UI_BuildLabelF("CpU:"); UI_Pop(FontSize); } UI_BuildLabelF(" Arenas: %F", FmtSint(GetGstat(NumArenas))); @@ -5782,12 +5940,12 @@ void V_TickForever(WaveLaneCtx *lane) } UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); UI_BuildSpacer(UI_PIX(padding, 1), Axis_X); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } @@ -5842,7 +6000,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_Size persistent_marker_width = UI_FNT(0.1, 1); UI_Size persistent_marker_height = timeline_height; - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { UI_Push(Tint, VEC4(1, 1, 1, timeline_opacity)); @@ -5855,10 +6013,10 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(FloatingPos, timeline_pos); UI_SetNext(BackgroundColor, tmld_bg); UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY); - UI_PushCP(UI_BuildRowEx(timeline_key)); + UI_PushCp(UI_BuildRowEx(timeline_key)); { } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } Vec2 marker_offset = Zi; @@ -5925,7 +6083,7 @@ void V_TickForever(WaveLaneCtx *lane) } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } i64 reset_span_ns = (timeline_span_ticks * SIM_TICK_INTERVAL_NS) * 0.5; @@ -5939,7 +6097,7 @@ void V_TickForever(WaveLaneCtx *lane) is_first_ack ) ); - if (!is_locked && should_reset || is_first_ack || is_showing != was_showing) + if (!is_locked && (should_reset || is_first_ack || is_showing != was_showing)) { last_timeline_matchup_ns = frame->time_ns; timeline_start_tick = frame->predict_tick_accum; @@ -6023,7 +6181,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_Size board_width = UI_SHRINK(0, 0); UI_Size board_height = UI_SHRINK(0, 0); Vec2 pos = VEC2(frame->screen_dims.x / 2, 50); - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { UI_Push(Tint, VEC4(1, 1, 1, opacity)); UI_SetNext(Anchor, UI_Region_Top); @@ -6032,7 +6190,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(FloatingPos, pos); UI_SetNext(BackgroundColor, board_bg); UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_PushCP(UI_BuildColumnEx(board_key)); + UI_PushCp(UI_BuildColumnEx(board_key)); { // UI_BuildSpacer(spacing_sz, Axis_Y); for (BoardRow *board_row = first_board_row; board_row; board_row = board_row->next) @@ -6050,7 +6208,7 @@ void V_TickForever(WaveLaneCtx *lane) } UI_SetNext(Tint, 0); UI_SetNext(ChildAlignment, UI_Region_Left); - UI_PushCP(UI_BuildRow()); // Scoreboard row + UI_PushCp(UI_BuildRow()); // Scoreboard row { UI_Push(ChildAlignment, UI_Region_Left); @@ -6065,7 +6223,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildSpacer(spacing_sz, Axis_X); UI_SetNext(Width, name_sz); - UI_PushCP(UI_BuildColumn()); // Player name column + UI_PushCp(UI_BuildColumn()); // Player name column { if (is_header) { @@ -6076,12 +6234,12 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildLabelF("%F", FmtString(board_row->name)); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_X); UI_BuildSpacer(spacing_sz, Axis_X); UI_SetNext(Width, kills_sz); - UI_PushCP(UI_BuildColumn()); // Kills column + UI_PushCp(UI_BuildColumn()); // Kills column { if (is_header) { @@ -6092,12 +6250,12 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildLabelF("%F", FmtFloat(board_row->kills, .p = 2)); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_X); UI_BuildSpacer(spacing_sz, Axis_X); UI_SetNext(Width, deaths_sz); - UI_PushCP(UI_BuildColumn()); // Deaths column + UI_PushCp(UI_BuildColumn()); // Deaths column { if (is_header) { @@ -6108,12 +6266,12 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildLabelF("%F", FmtFloat(board_row->deaths, .p = 2)); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_X); UI_BuildSpacer(spacing_sz, Axis_X); UI_SetNext(Width, ping_sz); - UI_PushCP(UI_BuildColumn()); // Ping column + UI_PushCp(UI_BuildColumn()); // Ping column { if (is_header) { @@ -6124,9 +6282,9 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildLabelF("%F", FmtFloat(board_row->ping, .p = 2)); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); if (is_header) { @@ -6142,9 +6300,9 @@ void V_TickForever(WaveLaneCtx *lane) } // UI_BuildSpacer(spacing_sz, Axis_Y); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } ////////////////////////////// @@ -6205,7 +6363,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Height, UI_SHRINK(0, 1)); } UI_Key console_box = UI_BuildColumnEx(UI_KeyF("Console box")); - UI_PushCP(console_box); + UI_PushCp(console_box); { // Gather display logs u64 max = 20; @@ -6256,7 +6414,7 @@ void V_TickForever(WaveLaneCtx *lane) FmtString(text) ); } - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { Vec4 tint = VEC4(1, 1, 1, opacity); UI_Push(Tint, tint); @@ -6268,7 +6426,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_Push(Rounding, UI_RPIX(0)); UI_Push(BorderSize, 0); UI_Push(ChildAlignment, UI_Region_Left); - UI_PushCP(UI_BuildRow()); + UI_PushCp(UI_BuildRow()); { // UI_SetNext(Height, UI_PIX(100, 0)); UI_BuildSpacer(UI_PIX(10, 0), Axis_X); @@ -6280,13 +6438,13 @@ void V_TickForever(WaveLaneCtx *lane) UI_Push(Flags, UI_BoxFlag_DrawText); UI_BuildBox(); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); } } @@ -6823,14 +6981,14 @@ void V_TickForever(WaveLaneCtx *lane) } ////////////////////////////// - //- Set UI box texture + //- Set game box texture { Rng2 uv = Zi; uv.p0 = Vec2FromVec(screen_viewport.p0); uv.p1 = Vec2FromVec(screen_viewport.p1); uv = DivRng2Vec2(uv, Vec2FromVec(frame->screen_dims)); - UI_SetRawTexture(vis_box, frame->screen, uv); + UI_SetRawTexture(vis_game_box, frame->screen, uv); } } diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index 71412d84..07a4ad94 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -258,7 +258,8 @@ Struct(V_Panel) Axis axis; b32 is_organizing_panel; - b32 is_viewport_panel; + b32 is_vis_ui_panel; + b32 is_editor_panel; i64 active_window_idx; i64 windows_count; diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 1efd1d32..99c9c755 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -271,7 +271,7 @@ String UI_StringF_(String fmt, ...) //////////////////////////////////////////////////////////// //~ Checkpoint helpers -UI_Checkpoint UI_PushCP(UI_Key parent) +UI_Checkpoint UI_PushCp(UI_Key parent) { UI_Frame *frame = UI_CurrentFrame(); UI_Stack *stack = frame->top_stack; @@ -283,7 +283,7 @@ UI_Checkpoint UI_PushCP(UI_Key parent) return stack->top_checkpoint; } -void UI_PopCP(UI_Checkpoint cp) +void UI_PopCp(UI_Checkpoint cp) { UI_Frame *frame = UI_CurrentFrame(); UI_Stack *stack = frame->top_stack; @@ -302,7 +302,7 @@ void UI_PopCP(UI_Checkpoint cp) stack->top_checkpoint.v = cp.v - 1; } -UI_Checkpoint UI_TopCP(void) +UI_Checkpoint UI_TopCp(void) { UI_Frame *frame = UI_CurrentFrame(); UI_Stack *stack = frame->top_stack; diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 36574d38..81b6759c 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -158,7 +158,7 @@ Enum(UI_DebugBreakFlag) Enum(UI_StyleKind) { -#define X(name, type) UI_StyleKind_##name, +#define X(name, type) CAT(UI_StyleKind_,name), UI_StyleKind_None, UI_StyleKindsXList(X) UI_StyleKind_COUNT, @@ -479,14 +479,6 @@ UI_BoxIterResult UI_NextBox(Arena *arena, UI_BoxIter *iter); String UI_StringF_(String fmt, ...); #define UI_StringF(fmt_cstr, ...) UI_StringF_(StringFromCstrNoLimit(fmt_cstr), __VA_ARGS__, FmtEnd) -//////////////////////////////////////////////////////////// -//~ Checkpoint helpers - -UI_Checkpoint UI_PushCP(UI_Key parent); -void UI_PopCP(UI_Checkpoint pop_to); - -UI_Checkpoint UI_TopCP(void); - //////////////////////////////////////////////////////////// //~ Style stack helpers @@ -495,7 +487,7 @@ void UI_PushDefaults(void); void UI_PushStyle(UI_StyleDesc desc); UI_Style UI_PopStyle(UI_StyleDesc desc); -#define UI_STYLEDESC(name, ...) (UI_StyleDesc) { .style.kind = UI_StyleKind_##name, __VA_ARGS__ } +#define UI_STYLEDESC(name, ...) (UI_StyleDesc) { .style.kind = CAT(UI_StyleKind_,name), __VA_ARGS__ } #define UI_SetNext(name, ...) UI_PushStyle(UI_STYLEDESC(name, .pop_when_used = 1, .style.name = __VA_ARGS__)) #define UI_Push(name, ...) UI_PushStyle(UI_STYLEDESC(name, .style.name = __VA_ARGS__)) @@ -505,13 +497,23 @@ UI_Style UI_PopStyle(UI_StyleDesc desc); #define UI_PeekTop(name, ...) UI_PopStyle(UI_STYLEDESC(name, __VA_ARGS__)).name #define UI_Top(name, ...) UI_PopStyle(UI_STYLEDESC(name, .use = 1, __VA_ARGS__)).name -#define UI_PushCopy(name, src, ...) do { \ - UI_StyleDesc _new = src; \ - _new.style.kind = UI_StyleKind_##name; \ - _new.style.name = __VA_ARGS__; \ - UI_PushStyle(_new); \ +#define UI_PushDF(name, ...) DeferFor(UI_Push(name, __VA_ARGS__), UI_Pop(name)) + +#define UI_PushCopy(name, src, ...) do { \ + UI_StyleDesc _new = src; \ + _new.style.kind = CAT(UI_StyleKind_,name); \ + _new.style.name = __VA_ARGS__; \ + UI_PushStyle(_new); \ } while (0) +//////////////////////////////////////////////////////////// +//~ Checkpoint helpers + +UI_Checkpoint UI_PushCp(UI_Key parent); +void UI_PopCp(UI_Checkpoint pop_to); + +UI_Checkpoint UI_TopCp(void); + //////////////////////////////////////////////////////////// //~ Size helpers @@ -535,6 +537,7 @@ UI_Style UI_PopStyle(UI_StyleDesc desc); UI_Key UI_BuildBoxEx(UI_Key semantic_key); #define UI_BuildBox() UI_BuildBoxEx(UI_NilKey) +#define UI_BuildBoxF(...) UI_BuildBoxEx(UI_KeyF(__VA_ARGS__)) void UI_SetRawTexture(UI_Key key, G_TextureRef tex, Rng2 uv); diff --git a/src/ui/ui_extras.c b/src/ui/ui_extras.c index 14f164f9..96c4abfa 100644 --- a/src/ui/ui_extras.c +++ b/src/ui/ui_extras.c @@ -25,7 +25,7 @@ UI_Key UI_BuildLabel(String text) UI_Region alignment = UI_Top(ChildAlignment); UI_Key key = Zi; - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { UI_PushDefaults(); UI_Push(Parent, parent); @@ -41,7 +41,7 @@ UI_Key UI_BuildLabel(String text) UI_Push(Flags, UI_BoxFlag_DrawText); key = UI_BuildBox(); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); return key; } @@ -80,7 +80,7 @@ UI_Key UI_BuildSpacer(UI_Size size, Axis axis) UI_Key parent = UI_Top(Parent); UI_Key key = Zi; Vec2 scale = UI_Top(Scale); - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { UI_PushDefaults(); UI_Push(Parent, parent); @@ -90,7 +90,7 @@ UI_Key UI_BuildSpacer(UI_Size size, Axis axis) UI_Push(AxisSize, size, .axis = axis); key = UI_BuildBox(); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); return key; } @@ -100,7 +100,7 @@ UI_Key UI_BuildDivider(UI_Size size, Vec4 color, Axis axis) UI_Key parent = UI_Top(Parent); Vec2 scale = UI_Top(Scale); Vec4 tint = UI_Top(Tint); - UI_PushCP(UI_NilKey); + UI_PushCp(UI_NilKey); { UI_PushDefaults(); UI_Push(Parent, parent); @@ -111,7 +111,7 @@ UI_Key UI_BuildDivider(UI_Size size, Vec4 color, Axis axis) UI_Push(AxisSize, size, .axis = axis); key = UI_BuildBox(); } - UI_PopCP(UI_TopCP()); + UI_PopCp(UI_TopCp()); return key; } diff --git a/src/ui/ui_extras.h b/src/ui/ui_extras.h index a75b52d7..71d3b57c 100644 --- a/src/ui/ui_extras.h +++ b/src/ui/ui_extras.h @@ -31,3 +31,6 @@ UI_Key UI_BuildColumnEx(UI_Key key); #define UI_BuildRow() UI_BuildRowEx(UI_NilKey) #define UI_BuildColumn() UI_BuildColumnEx(UI_NilKey) + +#define UI_BuildRowF(...) UI_BuildRowEx(UI_KeyF(__VA_ARGS__)) +#define UI_BuildColumnF(...) UI_BuildColumnEx(UI_KeyF(__VA_ARGS__))