From ee4579bd2d9c71472b0048a64f1809f69ae00b7d Mon Sep 17 00:00:00 2001 From: jacob Date: Mon, 6 Apr 2026 00:36:28 -0500 Subject: [PATCH] sort profiler tracks by wave/lane priority --- src/base/base_async.c | 2 +- src/base/base_inc.h | 4 +- src/base/base_prof.c | 1 + src/base/base_prof.h | 1 + src/base/base_state.h | 1 + src/base/base_wave.c | 2 +- src/base/base_wave.h | 16 +- src/base/base_win32/base_win32.c | 9 +- src/base/base_win32/base_win32_wave.c | 37 +- src/base/base_win32/base_win32_wave.h | 3 +- src/config.h | 5 + src/gpu/gpu_dx12/gpu_dx12_core.c | 2 +- src/meta/meta.c | 2 +- src/net/net_win32/net_win32.c | 2 +- src/platform/platform_win32/platform_win32.c | 2 +- src/pp/pp_sim/pp_sim_core.c | 4 +- src/pp/pp_terms.h | 56 +- src/pp/pp_vis/pp_vis_core.c | 2563 ++++++------------ src/pp/pp_vis/pp_vis_core.h | 5 +- src/ui/ui_core.c | 47 +- src/ui/ui_core.h | 2 +- src/window/window_win32/window_win32.c | 2 +- 22 files changed, 918 insertions(+), 1850 deletions(-) diff --git a/src/base/base_async.c b/src/base/base_async.c index 3410080c..4bcd0d88 100644 --- a/src/base/base_async.c +++ b/src/base/base_async.c @@ -4,7 +4,7 @@ void BootstrapAsync(void) { // TODO: Dynamic lane counts - DispatchWave(Lit("Async"), 4, AsyncWorkerEntryPoint, 0); + DispatchWave(Lit("Async"), 4, AsyncWorkerEntryPoint, 0, PROFILER_PRIORITY_ASYNC); } //////////////////////////////////////////////////////////// diff --git a/src/base/base_inc.h b/src/base/base_inc.h index e123fc82..db902206 100644 --- a/src/base/base_inc.h +++ b/src/base/base_inc.h @@ -7,13 +7,13 @@ #if IsCpu #include "base_memory.h" #include "base_arena.h" + #include "base_math.h" + #include "base_wave.h" #include "base_prof.h" #include "base_futex.h" #include "base_sync.h" #include "base_time.h" #include "base_uid.h" - #include "base_math.h" - #include "base_wave.h" #include "base_string.h" #include "base_cmdline.h" #include "base_log.h" diff --git a/src/base/base_prof.c b/src/base/base_prof.c index d9be2fcc..82abeb2f 100644 --- a/src/base/base_prof.c +++ b/src/base/base_prof.c @@ -11,6 +11,7 @@ void BeginProfZone(char *name_cstr_lit) track = PushStruct(perm, ProfTrack); Base_tl.prof.thread_track = track; } + track->lane = CurrentLaneCtx(); LockTicketMutex(&Base.prof.register_track_tm); { u64 track_idx = Atomic32Fetch(&Base.prof.tracks_count); diff --git a/src/base/base_prof.h b/src/base/base_prof.h index a0901d59..cb87316f 100644 --- a/src/base/base_prof.h +++ b/src/base/base_prof.h @@ -21,6 +21,7 @@ Struct(ProfSample) Struct(ProfTrack) { u64 id; + WaveLaneCtx *lane; Atomic64 top_sample_seq; ProfSample samples_ring[ProfSamplesRingCap]; }; diff --git a/src/base/base_state.h b/src/base/base_state.h index 5f6e1ce2..30363ae1 100644 --- a/src/base/base_state.h +++ b/src/base/base_state.h @@ -20,6 +20,7 @@ Struct(BaseThreadLocalCtx) { ThreadLocalArenaCtx arenas; ThreadLocalProfCtx prof; + ThreadLocalWaveLaneCtx wave; }; extern ThreadLocal BaseThreadLocalCtx Base_tl; diff --git a/src/base/base_wave.c b/src/base/base_wave.c index 0f460a16..aabc88a0 100644 --- a/src/base/base_wave.c +++ b/src/base/base_wave.c @@ -108,7 +108,7 @@ void SetWaveLaneDefaultSpin(WaveLaneCtx *lane, u64 n) } //////////////////////////////////////////////////////////// -//~ Task helpers +//~ Lane helpers i32 WaveLaneIdxFromTaskIdx(WaveLaneCtx *lane, u64 task_idx) { diff --git a/src/base/base_wave.h b/src/base/base_wave.h index 1af5c52c..3d75539e 100644 --- a/src/base/base_wave.h +++ b/src/base/base_wave.h @@ -6,8 +6,11 @@ AlignedStruct(WaveCtx, IsolationSize) { - i32 lanes_count; + String name; void *udata; + i32 lanes_count; + i32 profiler_priority; + // Sync barrier IsolatedAtomic64 sync_gen; @@ -30,6 +33,11 @@ AlignedStruct(WaveLaneCtx, IsolationSize) typedef void WaveLaneEntryFunc(WaveLaneCtx *lane); +Struct(ThreadLocalWaveLaneCtx) +{ + WaveLaneCtx *lane; +}; + //////////////////////////////////////////////////////////// //~ Wave sync ops @@ -48,15 +56,17 @@ void WaveSyncBroadcastEx_(WaveLaneCtx *lane, u32 broadcast_lane_idx, void *broad void SetWaveLaneDefaultSpin(WaveLaneCtx *lane, u64 n); //////////////////////////////////////////////////////////// -//~ Task helpers +//~ Lane helers i32 WaveLaneIdxFromTaskIdx(WaveLaneCtx *lane, u64 task_idx); RngU64 WaveIdxRangeFromCount(WaveLaneCtx *lane, u64 tasks_count); +#define CurrentLaneCtx() (Base_tl.wave.lane) + //////////////////////////////////////////////////////////// //~ @hookdecl Dispatch -void DispatchWave(String name, u32 num_lanes, WaveLaneEntryFunc *entry, void *udata); +void DispatchWave(String name, u32 num_lanes, WaveLaneEntryFunc *entry, void *udata, i32 profiler_priority); //////////////////////////////////////////////////////////// //~ @hookdecl Thread diff --git a/src/base/base_win32/base_win32.c b/src/base/base_win32/base_win32.c index facfb995..d657c560 100644 --- a/src/base/base_win32/base_win32.c +++ b/src/base/base_win32/base_win32.c @@ -641,9 +641,14 @@ i32 W32_Main(void) GetSystemInfo(&W32.info); // Init main thread - W32_InitCurrentThread(Lit("Main")); + WaveCtx wave = Zi; + WaveLaneCtx lane = Zi; + wave.name = Lit("Main"); + wave.lanes_count = 1; + lane.wave = &wave; + lane.default_spin_count = DefaultWaveLaneSpinCount; + W32_InitCurrentThread(&lane); W32.main_thread_id = GetCurrentThreadId(); - SetThreadDescription(GetCurrentThread(), L"Main thread"); // Setup logging memory W32.logs_arena = AcquireArena(Gibi(64)); diff --git a/src/base/base_win32/base_win32_wave.c b/src/base/base_win32/base_win32_wave.c index cd4677fb..c9f463eb 100644 --- a/src/base/base_win32/base_win32_wave.c +++ b/src/base/base_win32/base_win32_wave.c @@ -1,9 +1,9 @@ //////////////////////////////////////////////////////////// //~ Thread -void W32_InitCurrentThread(String name) +String W32_InitCurrentThread(WaveLaneCtx *lane) { - // Init thread arenas + // Init thread state { Base_tl.arenas.perm = AcquireArena(Gibi(64)); for (i32 i = 0; i < (i32)countof(Base_tl.arenas.scratch); ++i) @@ -12,20 +12,30 @@ void W32_InitCurrentThread(String name) } } Arena *perm = PermArena(); + Base_tl.wave.lane = lane; + // Set thread name - wchar_t *thread_name_wstr = WstrFromString(perm, name); + WaveCtx *wave = lane->wave; + String thread_name = wave->name; + if (wave->lanes_count > 1) + { + thread_name = StringF(perm, "%F:%F", FmtString(wave->name), FmtUint(lane->idx)); + } + wchar_t *thread_name_wstr = WstrFromString(perm, thread_name); SetThreadDescription(GetCurrentThread(), thread_name_wstr); // Initialize COM CoInitializeEx(0, COINIT_MULTITHREADED); + + return thread_name; } DWORD WINAPI W32_ThreadProc(LPVOID thread_args_vp) { W32_ThreadArgs *thread_args = (W32_ThreadArgs *)thread_args_vp; - W32_InitCurrentThread(thread_args->name); - LogInfoF("New thread \"%F\" created with ID %F", FmtString(thread_args->name), FmtUint(ThreadId())); + String thread_name = W32_InitCurrentThread(thread_args->lane); + LogInfoF("New thread \"%F\" created with ID %F", FmtString(thread_name), FmtUint(ThreadId())); thread_args->entry(thread_args->lane); return 0; } @@ -33,12 +43,12 @@ DWORD WINAPI W32_ThreadProc(LPVOID thread_args_vp) //////////////////////////////////////////////////////////// //~ @hookimpl Dispatch -void DispatchWave(String name, u32 num_lanes, WaveLaneEntryFunc *entry, void *udata) +void DispatchWave(String name, u32 num_lanes, WaveLaneEntryFunc *entry, void *udata, i32 profiler_priority) { Arena *perm = PermArena(); PERSIST Atomic64 num_threads_allocated = Zi; - // Catch high lane count to prevent OS crash + // Catch high lane count to prevent windows BSOD i64 old_num_threads_allocated = Atomic64FetchAdd(&num_threads_allocated, num_lanes); i64 new_num_threads_allocated = old_num_threads_allocated + num_lanes; if (new_num_threads_allocated > MaxThreads) @@ -55,8 +65,10 @@ void DispatchWave(String name, u32 num_lanes, WaveLaneEntryFunc *entry, void *ud } WaveCtx *wave_ctx = PushStruct(perm, WaveCtx); + wave_ctx->name = PushString(perm, name); wave_ctx->lanes_count = num_lanes; wave_ctx->udata = udata; + wave_ctx->profiler_priority = profiler_priority; for (u32 lane_idx = 0; lane_idx < num_lanes; ++lane_idx) { @@ -65,21 +77,10 @@ void DispatchWave(String name, u32 num_lanes, WaveLaneEntryFunc *entry, void *ud lane_ctx->wave = wave_ctx; lane_ctx->default_spin_count = DefaultWaveLaneSpinCount; - String thread_name = Zi; - if (num_lanes > 1) - { - thread_name = StringF(perm, "%F:%F", FmtString(name), FmtUint(lane_idx)); - } - else - { - thread_name = PushString(perm, name); - } - W32_ThreadArgs *thread_args = PushStruct(perm, W32_ThreadArgs); thread_args->lane = lane_ctx; thread_args->udata = udata; thread_args->entry = entry; - thread_args->name = thread_name; HANDLE handle = CreateThread(0, Mebi(4), W32_ThreadProc, thread_args, 0, 0); if (!handle) diff --git a/src/base/base_win32/base_win32_wave.h b/src/base/base_win32/base_win32_wave.h index ea5a8758..bb5fb236 100644 --- a/src/base/base_win32/base_win32_wave.h +++ b/src/base/base_win32/base_win32_wave.h @@ -6,12 +6,11 @@ Struct(W32_ThreadArgs) void *udata; WaveLaneCtx *lane; WaveLaneEntryFunc *entry; - String name; }; //////////////////////////////////////////////////////////// //~ Thread -void W32_InitCurrentThread(String name); +String W32_InitCurrentThread(WaveLaneCtx *lane); DWORD WINAPI W32_ThreadProc(LPVOID thread_args_vp); diff --git a/src/config.h b/src/config.h index 176a202d..bad0410d 100644 --- a/src/config.h +++ b/src/config.h @@ -27,6 +27,11 @@ #define PROFILING_ENABLED 1 +#define PROFILER_PRIORITY_ASYNC 10 +#define PROFILER_PRIORITY_SIM 20 +#define PROFILER_PRIORITY_VIS 30 + + // TODO: Move these to user-configurable settings diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.c b/src/gpu/gpu_dx12/gpu_dx12_core.c index 8a00d877..1726284a 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.c +++ b/src/gpu/gpu_dx12/gpu_dx12_core.c @@ -611,7 +611,7 @@ void G_Bootstrap(void) OnAsyncTick(G_D12_TickAsync); - DispatchWave(Lit("Gpu collection worker"), 1, G_D12_CollectionWorkerEntryPoint, 0); + DispatchWave(Lit("Gpu collection worker"), 1, G_D12_CollectionWorkerEntryPoint, 0, 0); EndScratch(scratch); } diff --git a/src/meta/meta.c b/src/meta/meta.c index f0bc9626..92293016 100644 --- a/src/meta/meta.c +++ b/src/meta/meta.c @@ -1453,5 +1453,5 @@ void BootstrapLayers(void) { OS_Bootstrap(); i32 meta_lanes_count = 32; - DispatchWave(Lit("Meta"), MaxI32(meta_lanes_count, 1), M_BuildEntryPoint, 0); + DispatchWave(Lit("Meta"), MaxI32(meta_lanes_count, 1), M_BuildEntryPoint, 0, 0); } diff --git a/src/net/net_win32/net_win32.c b/src/net/net_win32/net_win32.c index 16ee6faf..33f932a0 100644 --- a/src/net/net_win32/net_win32.c +++ b/src/net/net_win32/net_win32.c @@ -19,7 +19,7 @@ void NET_Bootstrap(void) NET_W32.iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0); // Start worker - DispatchWave(Lit("Net"), 1, NET_W32_TickForever, 0); + DispatchWave(Lit("Net"), 1, NET_W32_TickForever, 0, 0); } //////////////////////////////////////////////////////////// diff --git a/src/platform/platform_win32/platform_win32.c b/src/platform/platform_win32/platform_win32.c index 2b1e68f5..57f8762e 100644 --- a/src/platform/platform_win32/platform_win32.c +++ b/src/platform/platform_win32/platform_win32.c @@ -9,7 +9,7 @@ void PLT_Bootstrap(void) PLT_W32.watches_arena = AcquireArena(Gibi(64)); // Init timer - DispatchWave(Lit("Win32 timer sync"), 1, PLT_W32_SyncTimerForever, 0); + DispatchWave(Lit("Win32 timer sync"), 1, PLT_W32_SyncTimerForever, 0, 0); } //////////////////////////////////////////////////////////// diff --git a/src/pp/pp_sim/pp_sim_core.c b/src/pp/pp_sim/pp_sim_core.c index d38eebb3..1849b34f 100644 --- a/src/pp/pp_sim/pp_sim_core.c +++ b/src/pp/pp_sim/pp_sim_core.c @@ -15,7 +15,7 @@ void S_Bootstrap(void) S.client_bins_count = Kibi(4); S.client_bins = PushStructsNoZero(perm, S_ClientBin, S.client_bins_count); - DispatchWave(Lit("Sim"), 1, S_TickForever, 0); + DispatchWave(Lit("Sim"), 1, S_TickForever, 0, PROFILER_PRIORITY_SIM); OnExit(S_Shutdown); } @@ -682,7 +682,7 @@ void S_TickForever(WaveLaneCtx *lane) bot->is_player = 1; bot->is_bot = 1; { - String bot_name = P_PresetPlayerNames[bots_count % countof(P_PresetPlayerNames)]; + String bot_name = P_PresetBotNames[bots_count % countof(P_PresetBotNames)]; P_SetEntString(bot, bot_name); } bots_count += 1; diff --git a/src/pp/pp_terms.h b/src/pp/pp_terms.h index fbfff33d..f48b5242 100644 --- a/src/pp/pp_terms.h +++ b/src/pp/pp_terms.h @@ -49,32 +49,32 @@ PERSIST Readonly String P_PresetHumanNames[] = { CompLit("Buck"), }; -// Taken from a random GMOD server -PERSIST Readonly String P_PresetPlayerNames[] = { - CompLit("Tidunbly"), - CompLit("lowayo"), - CompLit("_Runne_"), - CompLit("lionberg"), - CompLit("charlie main"), - CompLit("Fr0stie"), - CompLit("Mr. Bones"), - CompLit("Legs"), - CompLit("Poy"), - CompLit("frezh"), - CompLit("Kirep"), - CompLit("Cyan Crayon"), - CompLit("THE WIFE"), - CompLit("Panda"), - CompLit("KARMA"), - CompLit("adoti"), - CompLit("yoyota"), - CompLit("TaurusJ3"), - CompLit("dub"), - CompLit("Siepter"), - CompLit("Zunix"), - CompLit("Lumby"), - CompLit("Talids"), - CompLit("Train"), - CompLit("Kaitsedd"), - CompLit("jiyu"), +// Names taken from some random GMOD server +PERSIST Readonly String P_PresetBotNames[] = { + CompLit("[Bot] Tidunbly"), + CompLit("[Bot] lowayo"), + CompLit("[Bot] _Runne_"), + CompLit("[Bot] lionberg"), + CompLit("[Bot] charlie main"), + CompLit("[Bot] Fr0stie"), + CompLit("[Bot] Mr. Bones"), + CompLit("[Bot] Legs"), + CompLit("[Bot] Poy"), + CompLit("[Bot] frezh"), + CompLit("[Bot] Kirep"), + CompLit("[Bot] Cyan Crayon"), + CompLit("[Bot] THE WIFE"), + CompLit("[Bot] Panda"), + CompLit("[Bot] KARMA"), + CompLit("[Bot] adoti"), + CompLit("[Bot] yoyota"), + CompLit("[Bot] TaurusJ3"), + CompLit("[Bot] dub"), + CompLit("[Bot] Siepter"), + CompLit("[Bot] Zunix"), + CompLit("[Bot] Lumby"), + CompLit("[Bot] Talids"), + CompLit("[Bot] Train"), + CompLit("[Bot] Kaitsedd"), + CompLit("[Bot] jiyu"), }; diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index ca6c91ba..3a28606b 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -7,7 +7,7 @@ void V_Bootstrap(void) { V.transient_markers_arena = AcquireArena(Gibi(64)); V.persistent_markers_arena = AcquireArena(Gibi(64)); - DispatchWave(Lit("Vis"), 1, V_TickForever, 0); + DispatchWave(Lit("Vis"), 1, V_TickForever, 0, PROFILER_PRIORITY_VIS); OnExit(V_Shutdown); } @@ -618,7 +618,7 @@ V_WidgetTheme V_GetWidgetTheme(void) theme.icon_font = UI_BuiltinIconFont(); // theme.font_size = 14; - theme.ui_font_size = TweakFloat("UI font size", 14, 8, 24, .precision = 0); + theme.ui_font_size = TweakFloat("UI font size", 14, 8, 24, .precision = 1); theme.chat_font_size = TweakFloat("Chat font size", 16, 8, 24, .precision = 0); theme.tooltip_offset_px = VEC2(12, 0); theme.h1 = 2.00; @@ -1402,7 +1402,7 @@ void V_TickForever(WaveLaneCtx *lane) f32 max_look_radius = 5; f32 min_look_radius = 0.025; - frame->is_looking = !frame->is_editing && !frame->palette.is_showing && !frame->held_buttons[Button_Alt]; + frame->is_looking = !frame->is_editing && !frame->palette.should_show && !frame->held_buttons[Button_Alt]; frame->is_moving = !frame->is_editing; { @@ -2312,7 +2312,7 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// - //- Update local world + //- Generate locally blended world @@ -2354,7 +2354,6 @@ void V_TickForever(WaveLaneCtx *lane) } if (P_IsFrameNil(left_sim_frame) || P_IsFrameNil(right_sim_frame)) { - LogDebugF("Missing sim blend"); right_sim_frame = ack_frame; left_sim_frame = right_sim_frame; V_PushTimelineMarker(frame->blend_sim_tick, Color_Orange, 0); @@ -2377,7 +2376,6 @@ void V_TickForever(WaveLaneCtx *lane) } if (P_IsFrameNil(left_predict_frame) || P_IsFrameNil(right_predict_frame)) { - LogDebugF("Missing prediction blend"); right_predict_frame = predict_world->last_frame; left_predict_frame = right_predict_frame; V_PushTimelineMarker(frame->blend_predict_tick, Color_Red, 0); @@ -3910,6 +3908,7 @@ void V_TickForever(WaveLaneCtx *lane) zone_track = PushStruct(perm, V_ZoneTrack); zone_track->prof_track = prof_track; zone_track->id = V.zone_tracks_count++; + zone_track->lane = prof_track->lane; SllQueuePush(V.first_zone_track, V.last_zone_track, zone_track); // Push root zone @@ -4775,6 +4774,7 @@ void V_TickForever(WaveLaneCtx *lane) Struct(VisTrack) { VisTrack *next; + WaveLaneCtx *lane; u64 id; u32 rows_count; @@ -4787,16 +4787,19 @@ void V_TickForever(WaveLaneCtx *lane) f32 zone_collapse_threshold_px = 10; f32 zone_name_hide_threshold_px = UI_Top(FontSize) * 3; f32 min_zone_width_px = 6; - ProfZoneDF("Generate visible zones") + ProfZoneDF("Generate visible tracks") { + VisTrack *first_unsorted_vis_track = 0; + VisTrack *last_unsorted_vis_track = 0; for (V_ZoneTrack *zone_track = V.first_zone_track; zone_track; zone_track = zone_track->next) { // TODO: Ignore non-visible tracks // TODO: Ignore non-visible depths VisTrack *vis_track = PushStruct(frame->arena, VisTrack); - SllQueuePush(first_vis_track, last_vis_track, vis_track); + SllQueuePush(first_unsorted_vis_track, last_unsorted_vis_track, vis_track); vis_track->id = zone_track->id; + vis_track->lane = zone_track->lane; VisZone *first_bfs_vis_zone = 0; VisZone *last_bfs_vis_zone = 0; @@ -4844,14 +4847,16 @@ void V_TickForever(WaveLaneCtx *lane) i64 zone_start_ns = zone->start_ns; i64 zone_end_ns = MinI64(zone->end_ns, frame->time_ns); i64 zone_elapsed_ns = zone_end_ns - zone_start_ns; + f64 zone_start_px = zone_start_ns / profiler->ns_per_px; + f64 zone_end_px = zone_end_ns / profiler->ns_per_px; + i64 visual_zone_start_ns = MaxI64(zone_start_ns, profiler->view_ns); i64 visual_zone_end_ns = MinI64(zone_end_ns, profiler->view_ns + view_range_len_ns); - f64 visual_zone_start_px = visual_zone_start_ns / profiler->ns_per_px; f64 visual_zone_end_px = visual_zone_end_ns / profiler->ns_per_px; { - visual_zone_end_px = MaxF64(visual_zone_end_px, visual_zone_start_px + min_zone_width_px); + visual_zone_end_px = MinF64(MaxF64(visual_zone_end_px, zone_start_px + min_zone_width_px), view_end_px); { f32 overshoot = MaxF32(visual_zone_end_px - parent_vis->end_px, 0); visual_zone_start_px -= overshoot; @@ -4869,7 +4874,8 @@ void V_TickForever(WaveLaneCtx *lane) // Push vis zone if (visual_zone_end_px <= (frame->time_ns / profiler->ns_per_px)) { - b32 should_collapse_zone = (visual_zone_end_px - visual_zone_start_px) <= zone_collapse_threshold_px; + // b32 should_collapse_zone = (visual_zone_end_px - visual_zone_start_px) <= zone_collapse_threshold_px; + b32 should_collapse_zone = zone->end_ns != I64Max && ((zone->end_ns - zone->start_ns) / profiler->ns_per_px <= zone_collapse_threshold_px); String zone_name = zone->name; u64 zone_id = zone->id; @@ -4937,6 +4943,49 @@ void V_TickForever(WaveLaneCtx *lane) } } } + + // Dumb insertion sort of tracks by wave priority & lane index + for (VisTrack *unsorted = first_unsorted_vis_track; unsorted;) + { + VisTrack *next_unsorted = unsorted->next; + VisTrack *left_sorted = 0; + VisTrack *right_sorted = first_vis_track; + u32 unsorted_wave_priority = unsorted->lane->wave->profiler_priority; + u32 unsorted_lane_idx = unsorted->lane->idx; + for (; right_sorted; right_sorted = right_sorted->next) + { + b32 should_insert = 0; + u32 right_wave_priority = right_sorted->lane->wave->profiler_priority; + u32 right_lane_idx = right_sorted->lane->idx; + if (right_wave_priority > unsorted_wave_priority) + { + should_insert = 1; + } + else if (right_wave_priority == unsorted_wave_priority && right_lane_idx > unsorted_lane_idx) + { + should_insert = 1; + } + if (should_insert) + { + break; + } + left_sorted = right_sorted; + } + if (left_sorted) + { + left_sorted->next = unsorted; + } + else + { + first_vis_track = unsorted; + } + if (!right_sorted) + { + last_vis_track = unsorted; + } + unsorted->next = right_sorted; + unsorted = next_unsorted; + } } // Vec4 profiler_color = theme.col.window_bg; @@ -5016,353 +5065,331 @@ void V_TickForever(WaveLaneCtx *lane) - //- Main area - // UI_SetNext(BackgroundColor, main_color_unsampled); - UI_SetNext(Height, main_height); - UI_SetNext(Rounding, UI_Rpx(5 * theme.rounding)); - UI_SetNext(BorderSize, 1); - UI_SetNext(BorderColor, theme.col.divider); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren | UI_BoxFlag_Scissor); - UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_PushDF(Parent, UI_BuildColumnEx(main_box)) + UI_PushDF(Parent, UI_BuildRow()) { - //- Active area background - UI_PushDF(Opacity, 0.75) + UI_BuildSpacer(window_padding, Axis_X); + + //- Main area + // UI_SetNext(BackgroundColor, main_color_unsampled); + UI_SetNext(Height, main_height); + UI_SetNext(Rounding, UI_Rpx(8 * theme.rounding)); + // UI_SetNext(BackgroundColor, theme.col.window_bg); + UI_SetNext(BorderSize, 1); + UI_SetNext(BorderColor, theme.col.divider); + UI_SetNext(BackgroundColor, main_color_unsampled); + // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren | UI_BoxFlag_Scissor); + UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren); + // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); + UI_PushDF(Parent, UI_BuildColumnEx(main_box)) { - f64 aabg_left_ns = MaxF64(0, profiler->view_ns); - f64 aabg_right_ns = MinF64(frame->time_ns, view_end_ns); - - f64 aabg_len_ns = aabg_right_ns - aabg_left_ns; - f64 aabg_len_px = aabg_len_ns / profiler->ns_per_px; - - f64 aabg_cursor_offset_px = (aabg_left_ns - profiler->view_ns) / profiler->ns_per_px; - f32 aabg_offset_px = (aabg_left_ns - profiler->view_ns) / profiler->ns_per_px; - Vec2 aabg_cursor_pos = VEC2(aabg_cursor_offset_px, 0); - Vec2 aabg_pos = VEC2(aabg_offset_px, 0); - UI_Size aabg_width = UI_Px(aabg_len_px, 1); - - Vec4 aabg_color = main_color_sampled; - - // { - // // UI_SetNext(BorderSize, 1); - // // UI_SetNext(BorderColor, Color_White); - // UI_SetNext(Width, aabg_width); - // UI_SetNext(FloatingPos, aabg_pos); - // UI_SetNext(BackgroundColor, aabg_color); - // UI_SetNext(Flags, UI_BoxFlag_Floating); - // UI_BuildBoxEx(UI_KeyF("active area background")); - // } - - // { - // // UI_SetNext(BorderSize, 1); - // // UI_SetNext(BorderColor, Color_White); - // // UI_SetNext(BackgroundColor, timeline_cursor_color); - // UI_SetNext(BackgroundColor, Color_White); - // UI_SetNext(Width, UI_Px(2, 0)); - // // UI_SetNext(Width, timeline_cursor_width); - // UI_SetNext(FloatingPos, VEC2(aabg_cursor_offset_px + aabg_width.v, 0)); - // UI_SetNext(Anchor, UI_Region_Top); - // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX); - // UI_BuildBoxEx(UI_KeyF("aabg start cursor")); - // } - } - - UI_Size track_padding = UI_Px(window_padding.v * 2, 0); - - - // FIXME: Remove this - panel->bg = main_color_unsampled; - panel->opacity = 1; - - - //- Zone tracks - ProfZoneDF("Build zones") - { - for (VisTrack *vis_track = first_vis_track; vis_track; vis_track = vis_track->next) + //- Active area background + UI_PushDF(Opacity, 0.75) { - // TODO: Real wave/lane information - String wave_name = Lit("Vis wave"); - u32 lane_idx = 2; - UI_Key track_box = UI_KeyF("vis track %F", FmtUint(vis_track->id)); + f64 aabg_left_ns = MaxF64(0, profiler->view_ns); + f64 aabg_right_ns = MinF64(frame->time_ns, view_end_ns); - Vec2 track_dims_rate = VEC2(Inf, 10); + f64 aabg_len_ns = aabg_right_ns - aabg_left_ns; + f64 aabg_len_px = aabg_len_ns / profiler->ns_per_px; - UI_SetNext(Height, track_height); - UI_SetNext(DimsRate, track_dims_rate); - UI_PushDF(Tag, track_box.v) - UI_PushDF(Parent, UI_BuildColumnEx(track_box)) + f64 aabg_cursor_offset_px = (aabg_left_ns - profiler->view_ns) / profiler->ns_per_px; + f32 aabg_offset_px = (aabg_left_ns - profiler->view_ns) / profiler->ns_per_px; + Vec2 aabg_cursor_pos = VEC2(aabg_cursor_offset_px, 0); + Vec2 aabg_pos = VEC2(aabg_offset_px, 0); + UI_Size aabg_width = UI_Px(aabg_len_px, 1); + + Vec4 aabg_color = main_color_sampled; + + // { + // // UI_SetNext(BorderSize, 1); + // // UI_SetNext(BorderColor, Color_White); + // UI_SetNext(Width, aabg_width); + // UI_SetNext(FloatingPos, aabg_pos); + // UI_SetNext(BackgroundColor, aabg_color); + // UI_SetNext(Flags, UI_BoxFlag_Floating); + // UI_BuildBoxEx(UI_KeyF("active area background")); + // } + + // { + // // UI_SetNext(BorderSize, 1); + // // UI_SetNext(BorderColor, Color_White); + // // UI_SetNext(BackgroundColor, timeline_cursor_color); + // UI_SetNext(BackgroundColor, Color_White); + // UI_SetNext(Width, UI_Px(2, 0)); + // // UI_SetNext(Width, timeline_cursor_width); + // UI_SetNext(FloatingPos, VEC2(aabg_cursor_offset_px + aabg_width.v, 0)); + // UI_SetNext(Anchor, UI_Region_Top); + // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX); + // UI_BuildBoxEx(UI_KeyF("aabg start cursor")); + // } + } + + UI_Size track_padding = UI_Px(window_padding.v * 2, 0); + + + // FIXME: Remove this + // panel->bg = main_color_unsampled; + panel->opacity = 1; + + + //- Zone tracks + ProfZoneDF("Build tracks") + { + for (VisTrack *vis_track = first_vis_track; vis_track; vis_track = vis_track->next) { - // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildSpacer(window_padding, Axis_Y); + // TODO: Real wave/lane information + String wave_name = Lit("Vis wave"); + u32 lane_idx = 2; + UI_Key track_box = UI_KeyF("vis track %F", FmtUint(vis_track->id)); + + Vec2 track_dims_rate = VEC2(Inf, Inf); + if (!frame->is_resizing && !prev_frame->is_resizing) + { + track_dims_rate.y = 10; + } UI_SetNext(Height, track_height); - UI_PushDF(Parent, UI_BuildRow()) + UI_SetNext(DimsRate, track_dims_rate); + UI_PushDF(Tag, track_box.v) + UI_PushDF(Parent, UI_BuildColumnEx(track_box)) { - // UI_BuildSpacer(window_padding, Axis_X); - // UI_BuildSpacer(window_padding, Axis_X); + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildSpacer(window_padding, Axis_Y); - UI_SetNext(DimsRate, track_dims_rate); UI_SetNext(Height, track_height); - UI_PushDF(Parent, UI_BuildColumnEx(UI_KeyF("track area"))) + UI_PushDF(Parent, UI_BuildRow()) { - UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildSpacer(window_padding, Axis_X); + // UI_BuildSpacer(window_padding, Axis_X); - // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildSpacer(track_padding, Axis_Y); - // UI_BuildSpacer(track_padding, Axis_Y); - // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); - - //- Wave/lane info + UI_SetNext(DimsRate, track_dims_rate); + UI_SetNext(Height, track_height); + UI_PushDF(Parent, UI_BuildColumnEx(UI_KeyF("track area"))) { - // UI_SetNext(Height, zone_height); - UI_SetNext(Height, UI_Shrink(0, 1)); - // UI_SetNext(BackgroundColor, VEC4(0.15, 0.15, 0.15, 0.15)); - // UI_SetNext(BackgroundColor, profiler_color); - UI_SetNext(BackgroundColor, Color_Transparent); - // UI_SetNext(Text, wave_name); - UI_PushDF(Parent, UI_BuildRow()) - { - UI_PushDF(Height, UI_Shrink(0, 1)) - UI_PushDF(Width, UI_Shrink(0, 1)) - UI_PushDF(FontSize, UI_Top(FontSize) * theme.h4) - UI_PushDF(Flags, UI_BoxFlag_DrawText) - { - UI_PushDF(Text, Lit(" Async ")) - // UI_PushDF(TextColor, theme.col.hint) - UI_BuildBox(); + UI_BuildSpacer(window_padding, Axis_Y); - UI_PushDF(Text, Lit("Lane 0")) - UI_PushDF(TextColor, theme.col.hint) - UI_BuildBox(); + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildSpacer(track_padding, Axis_Y); + // UI_BuildSpacer(track_padding, Axis_Y); + // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); + + //- Wave/lane info + { + // UI_SetNext(Height, zone_height); + UI_SetNext(Height, UI_Shrink(0, 1)); + // UI_SetNext(BackgroundColor, VEC4(0.15, 0.15, 0.15, 0.15)); + // UI_SetNext(BackgroundColor, profiler_color); + UI_SetNext(BackgroundColor, Color_Transparent); + // UI_SetNext(Text, wave_name); + UI_PushDF(Parent, UI_BuildRow()) + { + UI_PushDF(Height, UI_Shrink(0, 1)) + UI_PushDF(Width, UI_Shrink(0, 1)) + UI_PushDF(FontSize, UI_Top(FontSize) * theme.h4) + UI_PushDF(Flags, UI_BoxFlag_DrawText) + { + UI_PushDF(Text, StringF(frame->arena, " %F ", FmtString(vis_track->lane->wave->name))) + // UI_PushDF(TextColor, theme.col.hint) + UI_BuildBox(); + + UI_PushDF(Text, StringF(frame->arena, "Lane %F", FmtUint(vis_track->lane->idx))) + UI_PushDF(TextColor, theme.col.hint) + UI_BuildBox(); + } } } - } - - UI_SetNext(Height, track_height); - UI_SetNext(DimsRate, track_dims_rate); - UI_SetNext(Rounding, UI_Rpx(5 * theme.rounding)); - UI_SetNext(BackgroundColor, profiler_color); - UI_SetNext(BorderColor, theme.col.window_bd); - UI_SetNext(BorderSize, 1); - UI_SetNext(Flags, UI_BoxFlag_Scissor); - UI_PushDF(Parent, UI_BuildRowEx(UI_KeyF("zone rows"))) - { - // UI_BuildSpacer(window_padding, Axis_Y); + UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); + UI_BuildSpacer(UI_Px(zone_height.v * 0.25, 0), Axis_Y); UI_SetNext(Height, track_height); - UI_PushDF(Parent, UI_BuildColumn()) + UI_SetNext(DimsRate, track_dims_rate); + // UI_SetNext(Rounding, UI_Rpx(5 * theme.rounding)); + // UI_SetNext(BackgroundColor, profiler_color); + // UI_SetNext(BackgroundColor, theme.col.panel_bg); + UI_SetNext(BorderColor, theme.col.window_bd); + // UI_SetNext(BorderSize, 1); + // UI_SetNext(Flags, UI_BoxFlag_Scissor); + UI_PushDF(Parent, UI_BuildRowEx(UI_KeyF("zone rows"))) { - - // UI_BuildSpacer(UI_Px(10, 0), Axis_Y); - // UI_BuildSpacer(UI_Grow(1, 0), Axis_Y); - - //- Zone rows - UI_Key *zone_row_boxes = PushStructs(frame->arena, UI_Key, vis_track->rows_count); - for (u64 zone_row_box_idx = 0; zone_row_box_idx < vis_track->rows_count; ++zone_row_box_idx) - { - UI_Key zone_row_box = UI_KeyF("zone row %F", FmtUint(zone_row_box_idx)); - zone_row_boxes[zone_row_box_idx] = zone_row_box; - // UI_SetNext(Height, zone_height); - UI_SetNext(Height, zone_height); - UI_PushDF(Parent, UI_BuildRowEx(zone_row_box)) - { - } - } - - // End-of-rows padding - // TODO: We want this, but seems to maybe cause 1px vertical overlap on zones? // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildSpacer(UI_Px(zone_height.v * 1, 0), Axis_Y); - //- Zones - for (VisZone *zone = vis_track->first_zone; zone; zone = zone->next) + UI_SetNext(Height, track_height); + UI_PushDF(Parent, UI_BuildColumn()) { - UI_Key zone_row_box = zone_row_boxes[zone->depth - 1]; - b32 can_hover = profiler->unsnap; - UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id)); - b32 is_hovered = can_hover && UI_HoveredAbsolute(zone_box) && UI_HotAbsolute(main_box); - if (is_hovered) + // UI_BuildSpacer(UI_Px(10, 0), Axis_Y); + // UI_BuildSpacer(UI_Grow(1, 0), Axis_Y); + + //- Zone rows + UI_Key *zone_row_boxes = PushStructs(frame->arena, UI_Key, vis_track->rows_count); + for (u64 zone_row_box_idx = 0; zone_row_box_idx < vis_track->rows_count; ++zone_row_box_idx) { - hovered_zone_box = zone_box; - hovered_zone = zone; - } - f32 zone_hovered = can_hover * UI_Hovered(zone_box) * UI_Hot(main_box); - - f64 zone_offset_px = zone->start_px - view_start_px; - f64 zone_len_px = zone->end_px - zone->start_px; - - Vec2 zone_pos = VEC2(zone_offset_px, 0); - UI_Size zone_width = UI_Px(zone_len_px, 1); - - Vec4 zone_color = zone->color; - Vec4 zone_color_bd = zone_color; - - zone_color_bd = MulVec4(zone_color_bd, 0.65); - zone_color_bd.a = 1; - - Vec4 zone_text_color = UI_Top(TextColor); - zone_text_color.a *= 0.75; - - Vec4 zone_line_color = Zi; - - // b32 is_collapsed = zone->is_collapsed; - b32 is_collapsed = zone->collapsed_count > 0; - // b32 is_collapsed = zone->collapsed_count > 0 || zone_len_px <= min_zone_width_px; - - // UI_Size collapsed_line_size = UI_Px(2, 1); - UI_Size collapsed_line_size = UI_Px(1.5, 1); - // Vec4 collapsed_text_color = theme.col.positive; - // Vec4 collapsed_line_color = theme.col.negative; - // Vec4 collapsed_line_color = SrgbFromHsv(TweakFloat("RAAAAAAAAAH H", 100, 0, 360), TweakFloat("RAAAAAAAAAH S", 0.50, 0, 1), TweakFloat("RAAAAAAAAAH V", 1.00, 0, 1)); - // Vec4 collapsed_line_color = Color_Black; - // Vec4 collapsed_line_color = theme.col.hint; - // Vec4 collapsed_text_color = theme.col.positive; - // Vec4 collapsed_text_color = SrgbFromHsv(TweakFloat("RAAAAAAAAAH H", 100, 0, 360), TweakFloat("RAAAAAAAAAH S", 0.50, 0, 1), TweakFloat("RAAAAAAAAAH V", 1.00, 0, 1)); - - // Vec4 collapsed_line_color = SrgbFromHsv(32, 1, 0.5); - // Vec4 collapsed_text_color = SrgbFromHsv(32, 1, 1); - - // Vec4 collapsed_line_color = SrgbFromHsv(64, 1, 0.5); - // Vec4 collapsed_text_color = SrgbFromHsv(64, 1, 0.75); - - // collapsed_text_color = LerpSrgb(collapsed_text_color, Color_White, zone_hovered); - // collapsed_line_color = LerpSrgb(collapsed_line_color, Color_White, zone_hovered); - - - - - - String zone_text = zone->name; - if (is_collapsed) - { - zone_text = StringF(frame->arena, "%F", FmtUint(zone->collapsed_count)); - zone_text_color = collapsed_text_color; - zone_line_color = collapsed_line_color; - - // zone_color = VEC4(0, 0, 0, 0); - // zone_color = VEC4(1, 0, 1, 1); - // zone_color = VEC4(0.15, 0.15, 0.15, 0.5); - // zone_color = VEC4(0.20, 0.20, 0.20, 0.5); - - - zone_color = VEC4(0.25, 0.25, 0.25, 0.5); - - - // if (zone->collapsed_count > 1) - // { - // zone_color = VEC4(0.25, 0.25, 0.25, 0.5); - // } - // else - // { - // zone_color = Color_White; - // } - - - - // zone_color = VEC4(0.4, 0.4, 0.4, 0.5); - zone_color_bd = VEC4(0, 0, 0, 0); - - // zone_color = LerpSrgb(zone_color, Color_Transparent, zone_hovered); - + UI_Key zone_row_box = UI_KeyF("zone row %F", FmtUint(zone_row_box_idx)); + zone_row_boxes[zone_row_box_idx] = zone_row_box; + // UI_SetNext(Height, zone_height); + UI_SetNext(Height, zone_height); + UI_PushDF(Parent, UI_BuildRowEx(zone_row_box)) + { + } } - if (zone_len_px < zone_name_hide_threshold_px) + // End-of-rows padding + // TODO: We want this, but seems to maybe cause 1px vertical overlap on zones? + UI_BuildSpacer(window_padding, Axis_Y); + UI_BuildSpacer(UI_Px(zone_height.v * 1, 0), Axis_Y); + + //- Zones + for (VisZone *zone = vis_track->first_zone; zone; zone = zone->next) { - zone_text.len = 0; - } + UI_Key zone_row_box = zone_row_boxes[zone->depth - 1]; + b32 can_hover = profiler->unsnap; - zone_color_bd = LerpSrgb(zone_color_bd, Color_White, zone_hovered * !is_collapsed); - zone_text_color = LerpSrgb(zone_text_color, Color_White, zone_hovered); - zone_line_color = LerpSrgb(zone_line_color, Color_White, zone_hovered); + UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id)); + b32 is_hovered = can_hover && UI_HoveredAbsolute(zone_box) && UI_HotAbsolute(main_box); + if (is_hovered) + { + hovered_zone_box = zone_box; + hovered_zone = zone; + } + f32 zone_hovered = can_hover * UI_Hovered(zone_box) * UI_Hot(main_box); + + f64 zone_offset_px = zone->start_px - view_start_px; + f64 zone_len_px = zone->end_px - zone->start_px; + + Vec2 zone_pos = VEC2(zone_offset_px, 0); + UI_Size zone_width = UI_Px(zone_len_px, 1); + + Vec4 zone_color = zone->color; + Vec4 zone_color_bd = zone_color; + + zone_color_bd = MulVec4(zone_color_bd, 0.65); + zone_color_bd.a = 1; + + Vec4 zone_text_color = UI_Top(TextColor); + zone_text_color.a *= 0.75; + + Vec4 zone_line_color = Zi; + + // b32 is_collapsed = zone->is_collapsed; + b32 is_collapsed = zone->collapsed_count > 0; + // b32 is_collapsed = zone->collapsed_count > 0 || zone_len_px <= min_zone_width_px; + + // UI_Size collapsed_line_size = UI_Px(2, 1); + UI_Size collapsed_line_size = UI_Px(1.5, 1); + // Vec4 collapsed_text_color = theme.col.positive; + // Vec4 collapsed_line_color = theme.col.negative; + // Vec4 collapsed_line_color = SrgbFromHsv(TweakFloat("RAAAAAAAAAH H", 100, 0, 360), TweakFloat("RAAAAAAAAAH S", 0.50, 0, 1), TweakFloat("RAAAAAAAAAH V", 1.00, 0, 1)); + // Vec4 collapsed_line_color = Color_Black; + // Vec4 collapsed_line_color = theme.col.hint; + // Vec4 collapsed_text_color = theme.col.positive; + // Vec4 collapsed_text_color = SrgbFromHsv(TweakFloat("RAAAAAAAAAH H", 100, 0, 360), TweakFloat("RAAAAAAAAAH S", 0.50, 0, 1), TweakFloat("RAAAAAAAAAH V", 1.00, 0, 1)); + + // Vec4 collapsed_line_color = SrgbFromHsv(32, 1, 0.5); + // Vec4 collapsed_text_color = SrgbFromHsv(32, 1, 1); + + // Vec4 collapsed_line_color = SrgbFromHsv(64, 1, 0.5); + // Vec4 collapsed_text_color = SrgbFromHsv(64, 1, 0.75); + + // collapsed_text_color = LerpSrgb(collapsed_text_color, Color_White, zone_hovered); + // collapsed_line_color = LerpSrgb(collapsed_line_color, Color_White, zone_hovered); - f32 collapsed_zones_per_px = zone->collapsed_count / zone_len_px; - // f32 zag_intensity = 50 / collapsed_zones_per_px; - // zag_intensity = MaxF32(zag_intensity, 5); - // f32 top_zag_information_density = 10; - f32 top_zag_information_density = zone_collapse_threshold_px; - f32 zag_intensity = SmoothstepF32(0, top_zag_information_density, collapsed_zones_per_px); - // f32 zag_intensity = 1; - // f32 zag_intensity = TweakFloat("RAAAAAAAAAAAAAH", 1, 0, 1); - // f32 zag_intensity = 0.3; - f32 period_max = 20; - f32 period_min = 5; - f32 zag_period = LerpF32(period_max, period_min, zag_intensity); - - f32 amplitude_max = UI_Top(FontSize) * 0.15; - f32 amplitude_min = UI_Top(FontSize) * 0.05; - f32 zag_amplitude = LerpF32(amplitude_max, amplitude_min, zag_intensity); - - UI_SetNext(Width, zone_width); - UI_SetNext(Height, UI_Grow(1, 0)); - UI_SetNext(BackgroundColor, zone_color); - UI_SetNext(BorderColor, zone_color_bd); - UI_SetNext(BorderSize, 1); - UI_SetNext(FloatingPos, zone_pos); - UI_SetNext(ChildAlignment, UI_Region_Center); - UI_SetNext( - Flags, - UI_BoxFlag_Floating | - UI_BoxFlag_DontClampFloatingX | - UI_BoxFlag_DontClampFloatingY | - UI_BoxFlag_CaptureMouse | - UI_BoxFlag_Scissor - ); - UI_SetNext(Parent, zone_row_box); - // UI_PushDF(OrFlags, UI_Top(OrFlags) | (UI_BoxFlag_DontTruncateText * !!(is_collapsed))) - // UI_PushDF(OmitFlags, UI_Top(OmitFlags) | (UI_BoxFlag_Scissor * !!(is_collapsed))) - // UI_PushDF(ZagPeriod, UI_Top(FontSize) * 1) - // UI_PushDF(ZagPeriod, (collapsed_zones_per_px * UI_Top(FontSize)) * 0.1) - // UI_PushDF(ZagPeriod, collapsed_zones_per_px / (UI_Top(FontSize) * 1)) - UI_PushDF(ZagPeriod, zag_period) - UI_PushDF(ZagThickness, 1.5) - UI_PushDF(ZagRoundness, 1) - UI_PushDF(ZagAmplitude, zag_amplitude) - UI_PushDF(Parent, UI_BuildRowEx(zone_box)) - { + String zone_text = zone->name; if (is_collapsed) { - // Left zag - UI_SetNext(Width, UI_Grow(1, 0)); - UI_SetNext(ZagColor, zone_line_color); - UI_BuildBox(); - } - else - { - UI_SetNext(Width, UI_Px(3, 1)); - UI_BuildBox(); + zone_text = StringF(frame->arena, "%F", FmtUint(zone->collapsed_count)); + zone_text_color = collapsed_text_color; + zone_line_color = collapsed_line_color; + + // zone_color = VEC4(0, 0, 0, 0); + // zone_color = VEC4(1, 0, 1, 1); + // zone_color = VEC4(0.15, 0.15, 0.15, 0.5); + // zone_color = VEC4(0.20, 0.20, 0.20, 0.5); + + + zone_color = VEC4(0.25, 0.25, 0.25, 0.5); + + + // if (zone->collapsed_count > 1) + // { + // zone_color = VEC4(0.25, 0.25, 0.25, 0.5); + // } + // else + // { + // zone_color = Color_White; + // } + + + + // zone_color = VEC4(0.4, 0.4, 0.4, 0.5); + zone_color_bd = VEC4(0, 0, 0, 0); + + // zone_color = LerpSrgb(zone_color, Color_Transparent, zone_hovered); + } - if (zone_text.len > 0) + if (zone_len_px < zone_name_hide_threshold_px) { - // Zone name - // if (zone_len_px > zone_collapse_threshold_px * 3) - { - if (is_collapsed) - { - UI_SetNext(Width, UI_Shrink(0, 1)); - UI_SetNext(ChildAlignment, UI_Region_Center); - } - else - { - UI_SetNext(ChildAlignment, UI_Region_Left); - UI_SetNext(Width, UI_Grow(1, 0)); - } - UI_SetNext(FontSize, UI_Top(FontSize) * theme.h5); - UI_SetNext(TextColor, zone_text_color); - UI_SetNext(Text, zone_text); - UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText); - UI_BuildRow(); - } + zone_text.len = 0; + } - // Right collapsed lines + zone_color_bd = LerpSrgb(zone_color_bd, Color_White, zone_hovered * !is_collapsed); + zone_text_color = LerpSrgb(zone_text_color, Color_White, zone_hovered); + zone_line_color = LerpSrgb(zone_line_color, Color_White, zone_hovered); + + + f32 collapsed_zones_per_px = zone->collapsed_count / zone_len_px; + // f32 zag_intensity = 50 / collapsed_zones_per_px; + // zag_intensity = MaxF32(zag_intensity, 5); + + // f32 top_zag_information_density = 10; + f32 top_zag_information_density = zone_collapse_threshold_px; + f32 zag_intensity = SmoothstepF32(0, top_zag_information_density, collapsed_zones_per_px); + // f32 zag_intensity = 1; + // f32 zag_intensity = TweakFloat("RAAAAAAAAAAAAAH", 1, 0, 1); + + // f32 zag_intensity = 0.3; + + f32 period_max = 20; + f32 period_min = 5; + f32 zag_period = LerpF32(period_max, period_min, zag_intensity); + + f32 amplitude_max = UI_Top(FontSize) * 0.15; + f32 amplitude_min = UI_Top(FontSize) * 0.05; + f32 zag_amplitude = LerpF32(amplitude_max, amplitude_min, zag_intensity); + + UI_SetNext(Width, zone_width); + UI_SetNext(Height, UI_Grow(1, 0)); + UI_SetNext(BackgroundColor, zone_color); + UI_SetNext(BorderColor, zone_color_bd); + UI_SetNext(BorderSize, 1); + UI_SetNext(FloatingPos, zone_pos); + UI_SetNext(ChildAlignment, UI_Region_Center); + UI_SetNext( + Flags, + UI_BoxFlag_Floating | + UI_BoxFlag_DontClampFloatingX | + UI_BoxFlag_DontClampFloatingY | + UI_BoxFlag_CaptureMouse | + UI_BoxFlag_Scissor + ); + UI_SetNext(Parent, zone_row_box); + // UI_PushDF(OrFlags, UI_Top(OrFlags) | (UI_BoxFlag_DontTruncateText * !!(is_collapsed))) + // UI_PushDF(OmitFlags, UI_Top(OmitFlags) | (UI_BoxFlag_Scissor * !!(is_collapsed))) + // UI_PushDF(ZagPeriod, UI_Top(FontSize) * 1) + // UI_PushDF(ZagPeriod, (collapsed_zones_per_px * UI_Top(FontSize)) * 0.1) + // UI_PushDF(ZagPeriod, collapsed_zones_per_px / (UI_Top(FontSize) * 1)) + UI_PushDF(ZagPeriod, zag_period) + UI_PushDF(ZagThickness, 1.5) + UI_PushDF(ZagRoundness, 1) + UI_PushDF(ZagAmplitude, zag_amplitude) + UI_PushDF(Parent, UI_BuildRowEx(zone_box)) + { if (is_collapsed) { + // Left zag UI_SetNext(Width, UI_Grow(1, 0)); UI_SetNext(ZagColor, zone_line_color); UI_BuildBox(); @@ -5372,201 +5399,238 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Width, UI_Px(3, 1)); UI_BuildBox(); } + + if (zone_text.len > 0) + { + // Zone name + // if (zone_len_px > zone_collapse_threshold_px * 3) + { + if (is_collapsed) + { + UI_SetNext(Width, UI_Shrink(0, 1)); + UI_SetNext(ChildAlignment, UI_Region_Center); + } + else + { + UI_SetNext(ChildAlignment, UI_Region_Left); + UI_SetNext(Width, UI_Grow(1, 0)); + } + UI_SetNext(FontSize, UI_Top(FontSize) * theme.h5); + UI_SetNext(TextColor, zone_text_color); + UI_SetNext(Text, zone_text); + UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText); + UI_BuildRow(); + } + + // Right collapsed lines + if (is_collapsed) + { + UI_SetNext(Width, UI_Grow(1, 0)); + UI_SetNext(ZagColor, zone_line_color); + UI_BuildBox(); + } + else + { + UI_SetNext(Width, UI_Px(3, 1)); + UI_BuildBox(); + } + } } } } + + // UI_BuildSpacer(window_padding, Axis_Y); } - // UI_BuildSpacer(window_padding, Axis_Y); + UI_BuildSpacer(window_padding, Axis_Y); + } + + // UI_BuildSpacer(window_padding, Axis_X); + // UI_BuildSpacer(window_padding, Axis_X); + } + + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildSpacer(window_padding, Axis_Y); + } + } + } + + + + + + //- Ruler + UI_PushDF(Opacity, profiler->ruler_opacity) + { + { + f64 ruler_left_ns = MinF64(profiler->ruler_start_ns, profiler->cursor_ns); + f64 ruler_right_ns = MaxF64(profiler->ruler_start_ns, profiler->cursor_ns); + ruler_left_ns = ClampF64(ruler_left_ns, view_start_ns, view_end_ns); + ruler_right_ns = ClampF64(ruler_right_ns, view_start_ns, view_end_ns); + + ruler_len_ns = ruler_right_ns - ruler_left_ns; + f64 ruler_len_px = ruler_len_ns / profiler->ns_per_px; + + f64 ruler_cursor_offset_px = (profiler->ruler_start_ns - profiler->view_ns) / profiler->ns_per_px; + f32 ruler_offset_px = (ruler_left_ns - profiler->view_ns) / profiler->ns_per_px; + Vec2 ruler_cursor_pos = VEC2(ruler_cursor_offset_px, 0); + Vec2 ruler_pos = VEC2(ruler_offset_px, 0); + UI_Size ruler_width = UI_Px(ruler_len_px, 1); + + // Vec4 ruler_color = VEC4(0.25, 0.25, 0.25, 0.25); + Vec4 ruler_color = VEC4(0.20, 0.20, 0.20, 0.25); + + // Ruler rect + { + // UI_SetNext(BorderSize, 1); + // UI_SetNext(BorderColor, Color_White); + // UI_PushDF(Opacity, profiler->ruler_opacity) + UI_SetNext(Width, ruler_width); + UI_SetNext(FloatingPos, ruler_pos); + UI_SetNext(BackgroundColor, ruler_color); + UI_SetNext(Flags, UI_BoxFlag_Floating); + UI_BuildBoxEx(UI_KeyF("ruler")); + } + + // Ruler cursor + { + // UI_SetNext(BorderSize, 1); + // UI_SetNext(BorderColor, Color_White); + // UI_SetNext(BackgroundColor, timeline_cursor_color); + UI_SetNext(BackgroundColor, ruler_color); + UI_SetNext(Width, timeline_cursor_width); + UI_SetNext(FloatingPos, ruler_cursor_pos); + UI_SetNext(Anchor, UI_Region_Top); + UI_SetNext(Flags, UI_BoxFlag_Floating); + UI_BuildBoxEx(UI_KeyF("ruler cursor")); + } + } + } + + //- Timeline cursor + { + // Vec2 timeline_cursor_pos = VEC2(old_cursor_offset_px, 0); + Vec2 timeline_cursor_pos = VEC2((profiler->cursor_ns - profiler->view_ns) / profiler->ns_per_px, 0); + + UI_SetNext(Width, timeline_cursor_width); + UI_SetNext(Height, UI_Grow(1, 0)); + UI_SetNext(BackgroundColor, timeline_cursor_color); + UI_SetNext(FloatingPos, timeline_cursor_pos); + UI_SetNext(Flags, UI_BoxFlag_Floating); + UI_BuildBox(); + } + + //- Timeline tooltop + { + b32 show_ruler_time = is_measuring && ruler_len_ns != 0; + b32 show_hovered_zone = hovered_zone != 0; + if (show_ruler_time || show_hovered_zone) + { + UI_Key tooltip_box = UI_KeyF("tooltip"); + Vec2 tooltip_pos = SubVec2(frame->screen_cursor, UI_Anchor(main_box)); + tooltip_pos = AddVec2(tooltip_pos, theme.tooltip_offset_px); + f32 tooltip_opacity = 0.95; + + UI_SetNext(Opacity, tooltip_opacity); + UI_SetNext(BackgroundColor, theme.col.window_bg); + UI_SetNext(BorderColor, theme.col.window_bd); + UI_SetNext(Rounding, UI_Rpx(theme.rounding * 5)); + UI_SetNext(BorderSize, 1); + UI_SetNext(Anchor, UI_Region_TopLeft); + UI_SetNext(FloatingPos, tooltip_pos); + UI_SetNext(Flags, UI_BoxFlag_Floating); + UI_PushDF(Width, UI_Shrink(0, 1)) + UI_PushDF(Height, UI_Shrink(0, 1)) + UI_PushDF(Parent, UI_BuildRowEx(tooltip_box)) + { + UI_BuildSpacer(window_padding, Axis_X); + + UI_SetNext(Width, UI_Shrink(0, 1)); + UI_SetNext(Height, UI_Shrink(0, 1)); + UI_PushDF(Parent, UI_BuildColumn()) + { + UI_BuildSpacer(window_padding, Axis_Y); + + if (show_ruler_time) + { + // UI_SetNext(TextColor, theme.col.positive); + // UI_SetNext(TextColor, theme.col.button_active); + + UI_SetNext(TextColor, theme.col.button_selected); + UI_BuildLabelF("%F", FmtTimeNs(ruler_len_ns, .p = 2)); + + // UI_SetNext(TextColor, theme.col.button_selected); + // UI_BuildLabelF("Ruler"); + + if (show_hovered_zone) + { + UI_BuildSpacer(minor_padding, Axis_Y); + UI_BuildSpacer(minor_padding, Axis_Y); + UI_BuildDivider(UI_Px(1, 0), theme.col.divider, Axis_Y); + UI_BuildSpacer(minor_padding, Axis_Y); + } + } + + if (show_hovered_zone) + { + VisZone *zone = hovered_zone; + UI_PushDF(Parent, UI_BuildRow()) + { + i64 elapsed_ns = zone->end_ns - zone->start_ns; + UI_PushDF(Parent, UI_BuildColumn()) + { + UI_BuildLabelF("%F ", FmtTimeNs(elapsed_ns, .p = 2)); + + if (zone->collapsed_count > 0) + { + UI_PushDF(Parent, UI_BuildRow()) + { + if (zone->collapsed_count == 1) + { + // // UI_BuildLabelF(" (%F)", FmtUint(zone->collapsed_count)); + // UI_SetNext(TextColor, theme.col.hint); + // UI_BuildLabelF("%F", FmtString(zone->name)); + + // UI_SetNext(TextColor, collapsed_text_color); + // UI_BuildLabelF(" (Too small to display)"); + + UI_SetNext(TextColor, collapsed_text_color); + UI_BuildLabelF("1 zone too small to display: "); + UI_SetNext(TextColor, theme.col.hint); + UI_BuildLabelF("%F", FmtString(zone->name)); + } + else + { + // UI_SetNext(TextColor, theme.col.hint); + // UI_BuildLabelF("Zones too small to display"); + + // UI_SetNext(TextColor, collapsed_text_color); + // UI_BuildLabelF(" (%F)", FmtUint(zone->collapsed_count)); + + + // UI_SetNext(TextColor, theme.col.hint); + UI_SetNext(TextColor, collapsed_text_color); + UI_BuildLabelF("%F zones too small to display", FmtUint(zone->collapsed_count)); + } + } + } + else + { + UI_SetNext(TextColor, theme.col.hint); + UI_BuildLabelF("%F", FmtString(zone->name)); + } + } + } } UI_BuildSpacer(window_padding, Axis_Y); } - - // UI_BuildSpacer(window_padding, Axis_X); - // UI_BuildSpacer(window_padding, Axis_X); + UI_BuildSpacer(window_padding, Axis_X); } - - // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildSpacer(window_padding, Axis_Y); - } - } - } - - - - - - //- Ruler - UI_PushDF(Opacity, profiler->ruler_opacity) - { - { - f64 ruler_left_ns = MinF64(profiler->ruler_start_ns, profiler->cursor_ns); - f64 ruler_right_ns = MaxF64(profiler->ruler_start_ns, profiler->cursor_ns); - ruler_left_ns = ClampF64(ruler_left_ns, view_start_ns, view_end_ns); - ruler_right_ns = ClampF64(ruler_right_ns, view_start_ns, view_end_ns); - - ruler_len_ns = ruler_right_ns - ruler_left_ns; - f64 ruler_len_px = ruler_len_ns / profiler->ns_per_px; - - f64 ruler_cursor_offset_px = (profiler->ruler_start_ns - profiler->view_ns) / profiler->ns_per_px; - f32 ruler_offset_px = (ruler_left_ns - profiler->view_ns) / profiler->ns_per_px; - Vec2 ruler_cursor_pos = VEC2(ruler_cursor_offset_px, 0); - Vec2 ruler_pos = VEC2(ruler_offset_px, 0); - UI_Size ruler_width = UI_Px(ruler_len_px, 1); - - // Vec4 ruler_color = VEC4(0.25, 0.25, 0.25, 0.25); - Vec4 ruler_color = VEC4(0.20, 0.20, 0.20, 0.25); - - // Ruler rect - { - // UI_SetNext(BorderSize, 1); - // UI_SetNext(BorderColor, Color_White); - // UI_PushDF(Opacity, profiler->ruler_opacity) - UI_SetNext(Width, ruler_width); - UI_SetNext(FloatingPos, ruler_pos); - UI_SetNext(BackgroundColor, ruler_color); - UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_BuildBoxEx(UI_KeyF("ruler")); - } - - // Ruler cursor - { - // UI_SetNext(BorderSize, 1); - // UI_SetNext(BorderColor, Color_White); - // UI_SetNext(BackgroundColor, timeline_cursor_color); - UI_SetNext(BackgroundColor, ruler_color); - UI_SetNext(Width, timeline_cursor_width); - UI_SetNext(FloatingPos, ruler_cursor_pos); - UI_SetNext(Anchor, UI_Region_Top); - UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_BuildBoxEx(UI_KeyF("ruler cursor")); - } - } - } - - //- Timeline cursor - { - // Vec2 timeline_cursor_pos = VEC2(old_cursor_offset_px, 0); - Vec2 timeline_cursor_pos = VEC2((profiler->cursor_ns - profiler->view_ns) / profiler->ns_per_px, 0); - - UI_SetNext(Width, timeline_cursor_width); - UI_SetNext(Height, UI_Grow(1, 0)); - UI_SetNext(BackgroundColor, timeline_cursor_color); - UI_SetNext(FloatingPos, timeline_cursor_pos); - UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_BuildBox(); - } - - //- Timeline tooltop - { - b32 show_ruler_time = is_measuring && ruler_len_ns != 0; - b32 show_hovered_zone = hovered_zone != 0; - if (show_ruler_time || show_hovered_zone) - { - UI_Key tooltip_box = UI_KeyF("tooltip"); - Vec2 tooltip_pos = SubVec2(frame->screen_cursor, UI_Anchor(main_box)); - tooltip_pos = AddVec2(tooltip_pos, theme.tooltip_offset_px); - f32 tooltip_opacity = 0.95; - - UI_SetNext(Opacity, tooltip_opacity); - UI_SetNext(BackgroundColor, theme.col.window_bg); - UI_SetNext(BorderColor, theme.col.window_bd); - UI_SetNext(Rounding, UI_Rpx(theme.rounding * 5)); - UI_SetNext(BorderSize, 1); - UI_SetNext(Anchor, UI_Region_TopLeft); - UI_SetNext(FloatingPos, tooltip_pos); - UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_PushDF(Width, UI_Shrink(0, 1)) - UI_PushDF(Height, UI_Shrink(0, 1)) - UI_PushDF(Parent, UI_BuildRowEx(tooltip_box)) - { - UI_BuildSpacer(window_padding, Axis_X); - - UI_SetNext(Width, UI_Shrink(0, 1)); - UI_SetNext(Height, UI_Shrink(0, 1)); - UI_PushDF(Parent, UI_BuildColumn()) - { - UI_BuildSpacer(window_padding, Axis_Y); - - if (show_ruler_time) - { - // UI_SetNext(TextColor, theme.col.positive); - // UI_SetNext(TextColor, theme.col.button_active); - - UI_SetNext(TextColor, theme.col.button_selected); - UI_BuildLabelF("%F", FmtTimeNs(ruler_len_ns, .p = 2)); - - // UI_SetNext(TextColor, theme.col.button_selected); - // UI_BuildLabelF("Ruler"); - - if (show_hovered_zone) - { - UI_BuildSpacer(minor_padding, Axis_Y); - UI_BuildSpacer(minor_padding, Axis_Y); - UI_BuildDivider(UI_Px(1, 0), theme.col.divider, Axis_Y); - UI_BuildSpacer(minor_padding, Axis_Y); - } - } - - if (show_hovered_zone) - { - VisZone *zone = hovered_zone; - UI_PushDF(Parent, UI_BuildRow()) - { - i64 elapsed_ns = zone->end_ns - zone->start_ns; - UI_PushDF(Parent, UI_BuildColumn()) - { - UI_BuildLabelF("%F ", FmtTimeNs(elapsed_ns, .p = 2)); - - if (zone->collapsed_count > 0) - { - UI_PushDF(Parent, UI_BuildRow()) - { - if (zone->collapsed_count == 1) - { - // // UI_BuildLabelF(" (%F)", FmtUint(zone->collapsed_count)); - // UI_SetNext(TextColor, theme.col.hint); - // UI_BuildLabelF("%F", FmtString(zone->name)); - - // UI_SetNext(TextColor, collapsed_text_color); - // UI_BuildLabelF(" (Too small to display)"); - - UI_SetNext(TextColor, collapsed_text_color); - UI_BuildLabelF("1 zone too small to display: "); - UI_SetNext(TextColor, theme.col.hint); - UI_BuildLabelF("%F", FmtString(zone->name)); - } - else - { - // UI_SetNext(TextColor, theme.col.hint); - // UI_BuildLabelF("Zones too small to display"); - - // UI_SetNext(TextColor, collapsed_text_color); - // UI_BuildLabelF(" (%F)", FmtUint(zone->collapsed_count)); - - - // UI_SetNext(TextColor, theme.col.hint); - UI_SetNext(TextColor, collapsed_text_color); - UI_BuildLabelF("%F zones too small to display", FmtUint(zone->collapsed_count)); - } - } - } - else - { - UI_SetNext(TextColor, theme.col.hint); - UI_BuildLabelF("%F", FmtString(zone->name)); - } - } - } - } - - UI_BuildSpacer(window_padding, Axis_Y); - } - UI_BuildSpacer(window_padding, Axis_X); } } } + UI_BuildSpacer(window_padding, Axis_X); } // UI_BuildSpacer(window_padding, Axis_Y); @@ -5620,6 +5684,142 @@ void V_TickForever(WaveLaneCtx *lane) + + + + + + + + + + + + // ////////////////////////////// + // //- Init panel layout + + // // TODO: Allow for custom layouts stored in config files + // // TODO: Don't use rand keys for panels + + // if (!V.root_panel) + // { + // V.root_panel = PushStruct(perm, V_Panel); + // V_Panel *left_panel = PushStruct(perm, V_Panel); + // V_Panel *right_panel = PushStruct(perm, V_Panel); + + // //- Root panel + // { + // { + // V_Panel *panel = V.root_panel; + // panel->box = UI_KeyF("test root panel"); + // panel->contents_box = vis_panels_box; + // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // panel->pct = 1; + // panel->is_organizational = 1; + // panel->axis = Axis_X; + // V.root_panel = panel; + // } + + // //- Left panel + // { + // V_Panel *panel = left_panel; + // panel->parent = V.root_panel; + // panel->axis = Axis_X; + // DllQueuePush(panel->parent->first, panel->parent->last, panel); + // panel->box = UI_RandKey(); + // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // panel->pct = 0.10; + // panel->is_organizational = 1; + // } + + // //- Right panel + // { + // V_Panel *panel = right_panel; + // panel->parent = V.root_panel; + // panel->axis = Axis_Y; + // DllQueuePush(panel->parent->first, panel->parent->last, panel); + // panel->box = UI_RandKey(); + // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // panel->pct = 0.90; + // panel->is_organizational = 1; + // } + // } + + // //- Test spawn panel + // { + // V_Panel *panel = PushStruct(perm, V_Panel); + // panel->parent = left_panel; + // panel->axis = Axis_X; + // DllQueuePush(panel->parent->first, panel->parent->last, panel); + // panel->box = UI_RandKey(); + // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // panel->flags |= V_PanelFlag_Spawn; + // panel->pct = 0.25; + // } + + // // //- Test profiler panel + // // { + // // V_Panel *panel = PushStruct(perm, V_Panel); + // // panel->parent = right_panel; + // // panel->axis = Axis_X; + // // DllQueuePush(panel->parent->first, panel->parent->last, panel); + // // panel->box = UI_RandKey(); + // // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + // // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // // panel->flags |= V_PanelFlag_Profiler; + // // panel->pct = 0.5; + // // } + + // //- Vis screen panel + // { + // V_Panel *panel = PushStruct(perm, V_Panel); + // panel->parent = right_panel; + // panel->axis = Axis_X; + // DllQueuePush(panel->parent->first, panel->parent->last, panel); + // panel->box = UI_RandKey(); + // panel->contents_box = vis_screen_panel_box; + // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // panel->flags |= V_PanelFlag_Screen; + // panel->pct = 1; + // } + + // // //- Test console panel + // // { + // // V_Panel *parent = right_panel; + // // V_Panel *panel = PushStruct(perm, V_Panel); + // // panel->axis = Axis_X; + // // DllQueuePush(parent->first, parent->last, panel); + // // panel->box = UI_KeyF("test raah console panel"); + // // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + // // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + // // panel->flags |= V_PanelFlag_Console; + // // // panel->flags |= V_PanelFlag_Spawn; + // // panel->pct = 0.25; + // // } + // } + + + + + + + + + + + + + + + + + + + + @@ -5632,7 +5832,21 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// - //- Init panel layout + //- + //- PROFILER DEMO panel layout + //- + + // FIXME: Remove this + + + + + + + + + + // TODO: Allow for custom layouts stored in config files // TODO: Don't use rand keys for panels @@ -5696,18 +5910,18 @@ void V_TickForever(WaveLaneCtx *lane) panel->pct = 0.25; } - // //- Test profiler panel - // { - // V_Panel *panel = PushStruct(perm, V_Panel); - // panel->parent = right_panel; - // panel->axis = Axis_X; - // DllQueuePush(panel->parent->first, panel->parent->last, panel); - // panel->box = UI_RandKey(); - // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); - // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); - // panel->flags |= V_PanelFlag_Profiler; - // panel->pct = 0.5; - // } + //- Test profiler panel + { + V_Panel *panel = PushStruct(perm, V_Panel); + panel->parent = right_panel; + panel->axis = Axis_X; + DllQueuePush(panel->parent->first, panel->parent->last, panel); + panel->box = UI_RandKey(); + panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + panel->flags |= V_PanelFlag_Profiler; + panel->pct = 0.75; + } //- Vis screen panel { @@ -5719,22 +5933,22 @@ void V_TickForever(WaveLaneCtx *lane) panel->contents_box = vis_screen_panel_box; panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); panel->flags |= V_PanelFlag_Screen; - panel->pct = 1; + panel->pct = 0.25; } - // //- Test console panel - // { - // V_Panel *parent = right_panel; - // V_Panel *panel = PushStruct(perm, V_Panel); - // panel->axis = Axis_X; - // DllQueuePush(parent->first, parent->last, panel); - // panel->box = UI_KeyF("test raah console panel"); - // panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); - // panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); - // panel->flags |= V_PanelFlag_Console; - // // panel->flags |= V_PanelFlag_Spawn; - // panel->pct = 0.25; - // } + //- Test console panel + { + V_Panel *parent = right_panel; + V_Panel *panel = PushStruct(perm, V_Panel); + panel->axis = Axis_X; + DllQueuePush(parent->first, parent->last, panel); + panel->box = UI_KeyF("test raah console panel"); + panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v)); + panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v)); + panel->flags |= V_PanelFlag_Console; + // panel->flags |= V_PanelFlag_Spawn; + panel->pct = 0.25; + } } @@ -5742,6 +5956,12 @@ void V_TickForever(WaveLaneCtx *lane) + + + + + + ////////////////////////////// //- Build vis panel contents @@ -5758,6 +5978,7 @@ void V_TickForever(WaveLaneCtx *lane) PanelBfs *last_panel_bfs = first_panel_bfs; first_panel_bfs->panel = V.root_panel; + b32 is_resizing = 0; for (PanelBfs *bfs_parent = first_panel_bfs; bfs_parent; bfs_parent = first_panel_bfs) { SllQueuePop(first_panel_bfs, last_panel_bfs); @@ -5789,6 +6010,7 @@ void V_TickForever(WaveLaneCtx *lane) } if (UI_Held(panel->resizer_box, Button_M1)) { + frame->is_resizing = 1; f32 drag_delta_px = UI_CursorPos().v[parent_axis] - UI_DragCursorPos().v[parent_axis]; f32 drag_delta_pct = drag_delta_px * panel->drag_resize_pct_per_px; @@ -5801,10 +6023,6 @@ void V_TickForever(WaveLaneCtx *lane) f32 desired_new_sibling_pct = panel->next->pct - (new_pct - old_pct); new_sibling_pct = MaxF32(desired_new_sibling_pct, minimum_panel_pct); new_pct -= (new_sibling_pct - desired_new_sibling_pct); - } - - if (panel->next) - { panel->next->pct = new_sibling_pct; } panel->pct = new_pct; @@ -5902,6 +6120,12 @@ void V_TickForever(WaveLaneCtx *lane) resizer_color.a *= theme.col.panel_resizer_opacity; panel_bd.a *= theme.col.panel_border_opacity; + Vec2 dims_rate = VEC2(Inf, Inf); + if (!frame->is_resizing && !prev_frame->is_resizing) + { + dims_rate.y = 20; + } + // f32 panel_pct = panel->pct; // UI_SetNext(AxisSize, UI_Grow(panel_pct, 1), .axis = parent_axis); @@ -5911,6 +6135,8 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(AxisSize, UI_Px(panel_pct * parent_contents_size_px, 0), .axis = parent_axis); UI_SetNext(AxisSize, UI_Grow(1, 0), .axis = !parent_axis); UI_SetNext(ChildLayoutAxis, parent_axis); + // UI_SetNext(DimsRate, dims_rate); + // UI_PushDF(DimsRate, dims_rate) UI_PushDF(Tag, panel_box.v) UI_PushDF(Parent, UI_BuildBoxEx(panel_box)) { @@ -5947,6 +6173,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(BackgroundColor, panel_bg); UI_SetNext(BorderColor, panel_bd); UI_SetNext(BorderSize, 2); + UI_SetNext(DimsRate, dims_rate); // UI_SetNext(Rounding, UI_Rpx(10 * theme.rounding)); UI_SetNext(Flags, UI_BoxFlag_Scissor | (UI_BoxFlag_CaptureMouse * (!is_screen_panel_box && !panel->is_organizational))); UI_PushDF(Parent, UI_BuildBoxEx(contents_box)) @@ -6004,1144 +6231,6 @@ 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")); - - // // FIXME: Remove this - // if (frame->tick == 1) - // { - // palette->pos = VEC2(1000, 1000); - // } - - // UI_Size total_width = UI_Fnt(40, 1); - // UI_Size total_height = UI_Fnt(30, 1); - // UI_Size header_height = UI_Fnt(1.3, 1); - // UI_Size window_padding = UI_Fnt(0.5, 1); - // UI_Size icon_col_width = UI_Fnt(1.75, 1); - // UI_Size item_col_width = UI_Fnt(30, 1); - // // UI_Size col2_width = UI_Fnt(10, 1); - // UI_Size scrollbar_width = UI_Fnt(1, 1); - // f32 item_size_px = UI_Fnt(1.5, 1).v; - - // UI_Key scissor_key = UI_KeyF("scissor"); - // UI_Key lister_key = UI_KeyF("lister"); - // UI_Key scrollbar_key = UI_KeyF("scrollbar"); - // UI_Key thumb_key = UI_KeyF("scrollbar thumb"); - // UI_Key scrollbar_up_key = UI_KeyF("scrollbar up"); - // UI_Key scrollbar_down_key = UI_KeyF("scrollbar down"); - // UI_Key track_key = UI_KeyF("scrollbar track"); - - // f32 lister_start = UI_Rect(lister_key).p0.y; - // f32 lister_end = UI_Rect(lister_key).p1.y; - // f32 lister_height = MaxF32(lister_end - lister_start, 1); - - // f32 scissor_start = UI_Rect(scissor_key).p0.y; - // f32 scissor_end = UI_Rect(scissor_key).p1.y; - // f32 scissor_height = MaxF32(scissor_end - scissor_start, 1); - - // f32 track_start = UI_Rect(track_key).p0.y; - // f32 track_end = UI_Rect(track_key).p1.y; - // f32 track_height = MaxF32(track_end - track_start, 1); - - // f32 thumb_start = UI_Rect(thumb_key).p0.y; - // f32 thumb_end = UI_Rect(thumb_key).p1.y; - // f32 thumb_height = MaxF32(thumb_end - thumb_start, 1); - - // f32 wheel_scroll_amount = 3 * item_size_px; - // f32 button_scroll_amount = 20 * item_size_px * frame->dt; - // f32 scroll_height = MaxF32(lister_height - scissor_height, 1); - // { - // f32 wheel_scrolls = UI_Downs(lister_key, Button_WheelDown) - UI_Downs(lister_key, Button_WheelUp); - // f32 button_scrolls = UI_Held(scrollbar_down_key, Button_M1) - UI_Held(scrollbar_up_key, Button_M1); - // if (UI_Downs(thumb_key, Button_M1)) - // { - // palette->drag_lister = UI_Rect(lister_key); - // palette->drag_scissor = UI_Rect(scissor_key); - // palette->drag_track = UI_Rect(track_key); - // palette->drag_thumb = UI_Rect(thumb_key); - // palette->drag_cursor = UI_CursorPos(); - - // palette->drag_scroll = palette->scroll; - // } - // if (UI_Held(thumb_key, Button_M1)) - // { - // f32 drag_track_height = palette->drag_track.p1.y - palette->drag_track.p0.y; - // f32 drag_thumb_height = palette->drag_thumb.p1.y - palette->drag_thumb.p0.y; - // f32 drag_scroll_height = (palette->drag_lister.p1.y - palette->drag_lister.p0.y) - (palette->drag_scissor.p1.y - palette->drag_scissor.p0.y); - // f32 delta_ratio = (UI_CursorPos().y - palette->drag_cursor.y) / (drag_track_height - drag_thumb_height); - // palette->scroll = palette->drag_scroll + delta_ratio * drag_scroll_height; - // palette->target_scroll = palette->scroll; - // } - // palette->target_scroll += wheel_scrolls * wheel_scroll_amount; - // palette->target_scroll += button_scrolls * button_scroll_amount; - // palette->target_scroll = ClampF32(palette->target_scroll, 0, scroll_height); - // palette->scroll = LerpF32(palette->scroll, palette->target_scroll, SaturateF32(20 * frame->dt)); - // palette->scroll = ClampF32(palette->scroll, 0, scroll_height); - // } - - // f32 scroll_ratio = palette->scroll / scroll_height; - // f32 lister_offset = scroll_ratio * scroll_height; - - // f32 new_thumb_height = track_height * (scissor_height / lister_height); - // f32 new_thumb_start = scroll_ratio * track_height - scroll_ratio * thumb_height; - - // b32 scrollbar_visible = new_thumb_height < track_height; - - // { - // f32 ease_rate = TweakFloat("Debug palette ease rate", 20, 1, 100) * frame->dt; - // f32 ease_in_target = TweakFloat("Debug palette ease-in target", 1.3, 0, 2); - // f32 pref_show = palette->is_showing ? ease_in_target : 0; - // palette->show = SaturateF32(LerpF32(palette->show, pref_show, ease_rate)); - // } - - // if (palette->is_showing || palette->show > 0.001) - // { - // 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_Push(Tag, palette->key.v); - // UI_Key titlebar_key = UI_KeyF("title bar"); - - // Vec4 window_background_color = theme.col.window_bg; - // Vec4 window_border_color = theme.col.window_bd; - // Vec4 titlebar_color = Zi; - // Vec4 titlebar_border_color = Zi; - // Vec4 divider_color = theme.col.divider; - // if (UI_Held(titlebar_key, Button_M1)) - // { - // Vec2 drag_offset = SubVec2(ui_frame->drag_cursor_pos, UI_DragAnchor(palette->key)); - // palette->pos = SubVec2(UI_CursorPos(), drag_offset); - // } - // window_border_color = LerpSrgb(window_border_color, theme.col.button_active, UI_Hot(titlebar_key)); - - // f32 scale = LerpF32(0.85, 1, palette->show); - // UI_Push(Tint, VEC4(1, 1, 1, palette->show)); - // UI_SetNext(Scale, VEC2(scale, scale)); - - // UI_SetNext(BackgroundColor, window_background_color); - // UI_SetNext(BorderColor, window_border_color); - // // UI_SetNext(BorderSize, theme.window_bd_sz); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Rounding, UI_Rgrow(0.06 * theme.rounding)); - // UI_SetNext(Width, total_width); - // UI_SetNext(Height, total_height); - // UI_SetNext(FloatingPos, palette->pos); - // 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)); - // { - // ////////////////////////////// - // //- Build title bar - - // UI_PushCp(UI_NilKey); - // { - // UI_Push(BackgroundColor, titlebar_color); - // UI_Push(BorderColor, titlebar_border_color); - // UI_Push(Rounding, UI_Rpx(0)); - // UI_Push(ChildLayoutAxis, Axis_X); - // 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_PushDF(FontSize, UI_Top(FontSize) * theme.h5) - // UI_PushDF(TextColor, theme.col.hint) - // UI_PushDF(ChildAlignment, UI_Region_Center) - // UI_PushDF(Parent, UI_BuildBoxEx(titlebar_key)) - // { - // UI_Push(Width, UI_Grow(1, 0)); - // UI_Push(BorderColor, 0); - - // // Left title box - // UI_BuildRow(); - - // UI_SetNext(Width, UI_Shrink(0, 1)); - // UI_BuildIcon(theme.icon_font, UI_Icon_Wrench); - - // // Title box - // // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h3); - // UI_SetNext(Width, UI_Shrink(0, 1)); - // UI_SetNext(Text, Lit(" Developer Palette")); - // UI_SetNext(Flags, UI_BoxFlag_DrawText); - // UI_BuildBox(); - - // // Right title box - // UI_BuildRow(); - // } - // } - // 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_BuildSpacer(window_padding, Axis_X); - - // 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_BuildColumn()); - // { - // ////////////////////////////// - // //- Build searchbox - - // b32 is_searching = 0; - // String search_pattern = Zi; - // { - // UI_Size search_height = UI_Px(item_size_px * 1.25, 1); - - // UI_SetNext(BackgroundColor, 0); - // UI_SetNext(ChildAlignment, UI_Region_Left); - // UI_SetNext(Width, UI_Grow(1, 0)); - // UI_SetNext(Height, search_height); - // UI_PushCp(UI_BuildRow()); - // { - // //- Search icon - // { - // f32 size_px = UI_Top(FontSize) * 1.25; - - // UI_SetNext(Rounding, UI_Rgrow(0.75 * theme.rounding)); - // UI_SetNext(ChildAlignment, UI_Region_Center); - // UI_SetNext(BackgroundColor, 0); - // // UI_SetNext(BorderColor, reset_bd); - // UI_SetNext(BorderSize, 0); - // UI_SetNext(Rounding, 0); - // UI_SetNext(TextColor, theme.col.hint); - // UI_SetNext(Width, icon_col_width); - // UI_SetNext(Height, UI_Px(size_px * 1.5, 1)); - // // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_SetNext(FontSize, size_px * theme.h6); - // UI_BuildIcon(theme.icon_font, UI_Icon_Search); - // // UI_BuildRow(); - // } - - // //- Search box - // { - // UI_Key search_box = UI_KeyF("search box"); - // UI_Key search_scroll_box = UI_KeyF("search scroll box"); - // V_TextboxState *search_state = &palette->search_state; - - // f32 font_size = UI_Top(FontSize); - // GC_FontKey font = UI_Top(Font); - - // // Vec4 search_color = Color_Black; - // Vec4 search_color = Zi; - - // b32 has_focus = UI_MatchKey(search_box, prev_frame->text_input_focus); - // { - // // FIXME: Remove this - // has_focus = 1; - // if (UI_Downs(search_box, Button_M1)) - // { - // has_focus = 1; - // V.text_input_ns = frame->time_ns; - // } - // if (!palette->is_showing) - // { - // has_focus = 0; - // } - // } - - // if (UI_HotAbsolute(search_box)) - // { - // WND_SetCursor(window_frame, WND_CursorKind_Text); - // } - - // V_TextboxDeltaFlag tb_applied_flags = 0; - - // // Apply text input deltas - // { - // frame->text_input_focus = search_box; - // if (text_input_deltas.first) - // { - // V.text_input_ns = frame->time_ns; - // tb_applied_flags |= V_ApplyTextboxDeltas(search_state, text_input_deltas); - // } - // } - - // String search_text = V_StringFromTextbox(frame->arena, search_state); - // search_pattern = LowerString(frame->arena, search_text); - // is_searching = search_text.len != 0; - - // String display_text = search_text; - // Vec4 display_text_color = Color_White; - // if (!is_searching) - // { - // display_text_color = theme.col.hint; - // display_text = Lit(" Search..."); - // } - - // // TODO: Cache run for UI - // String32 codepoints = String32FromString(frame->arena, search_text); - // GC_Run run = GC_RunFromString32(frame->arena, codepoints, font, font_size); - - // b32 started_dragging_text = 0; - // b32 is_dragging_text = 0; - // if (has_focus) - // { - // // Generate & apply mouse selection delta - // if (UI_Held(search_box, Button_M1)) - // { - // V.text_input_ns = frame->time_ns; - // is_dragging_text = 1; - // f32 mouse_text_px = UI_CursorPos().x - UI_Anchor(search_scroll_box).x; - // i64 rect_idx = 0; - // for (; rect_idx < (i64)run.rects_count; ++rect_idx) - // { - // GC_RunRect rect = run.rects[rect_idx]; - // if (rect.baseline_pos + rect.advance / 2 > mouse_text_px) - // { - // break; - // } - // } - // { - // V_TextboxDelta delta = Zi; - // delta.flags |= V_TextboxDeltaFlag_NavDirectEnd; - // delta.flags |= V_TextboxDeltaFlag_NavSelect; - // delta.direct_end = rect_idx; - // if (UI_Downs(search_box, Button_M1)) - // { - // delta.flags |= V_TextboxDeltaFlag_NavDirectStart; - // delta.direct_start = delta.direct_end; - // started_dragging_text = 1; - // } - // tb_applied_flags |= V_ApplyTextboxDelta(search_state, delta); - // } - // } - // } - - - - - - - - - - // UI_SetNext(Width, UI_Grow(1, 0)); - // UI_SetNext(Height, search_height); - // UI_SetNext(BackgroundColor, search_color); - // UI_SetNext(ChildAlignment, UI_Region_Right); - // // UI_SetNext(BorderColor, item_border_color); - // // UI_SetNext(Rounding, UI_Rpx(5)); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Scissor); - // // UI_PushDF(BorderSize, 0) - // UI_PushDF(Parent, UI_BuildRowEx(search_box)) - // { - // //- Compute caret / selection pos - // { - // // TODO: Cache result of caret search when textbox - // f32 target_caret_start_px = 0; - // f32 target_caret_end_px = 0; - // if (search_text.len > 0) - // { - // for (i64 rect_idx = 0; rect_idx < (i64)run.rects_count; ++rect_idx) - // { - // GC_RunRect rect = run.rects[rect_idx]; - // if (rect_idx < search_state->start) - // { - // target_caret_start_px = rect.baseline_pos + rect.advance; - // } - // if (rect_idx < search_state->end) - // { - // target_caret_end_px = rect.baseline_pos + rect.advance; - // } - // if (rect_idx >= search_state->start && rect_idx >= search_state->end) - // { - // break; - // } - // } - // } - - // f32 caret_start_lerp_rate = 20 * frame->dt; - // f32 caret_end_lerp_rate = 50 * frame->dt; - // { - // if (started_dragging_text) - // { - // caret_start_lerp_rate = 1; - // caret_end_lerp_rate = 1; - // } - // // if (tb_applied_flags & V_TextboxDeltaFlag_UpdateText) - // // { - // // caret_end_lerp_rate = 1; - // // } - // caret_start_lerp_rate = SaturateF32(caret_start_lerp_rate); - // caret_end_lerp_rate = SaturateF32(caret_end_lerp_rate); - // } - // palette->caret_start_px = LerpF32(palette->caret_start_px, target_caret_start_px, caret_start_lerp_rate); - // palette->caret_end_px = LerpF32(palette->caret_end_px, target_caret_end_px, caret_end_lerp_rate); - // } - - // //- Determine text scroll pos - // f32 search_box_width = DimsFromRng2(UI_Rect(search_box)).x; - // { - // { - // f32 new_text_scroll_px = palette->caret_end_px - 10; - // palette->text_scroll_px = MinF32(palette->text_scroll_px, new_text_scroll_px); - // } - // { - // f32 new_text_scroll_px = palette->caret_end_px - search_box_width + 10; - // palette->text_scroll_px = MaxF32(palette->text_scroll_px, new_text_scroll_px); - // } - // palette->text_scroll_px = MaxF32(palette->text_scroll_px, 0); - // } - - // UI_Size caret_width = UI_Px(1, 1); - // UI_Size caret_height = UI_Px(search_height.v, 1); - // f32 h = TweakFloat("Text selection hue", 200, 0, 360); - // f32 s = TweakFloat("Text selection saturation", 1, 0, 1); - // f32 v = TweakFloat("Text selection brightness", 0.6, 0, 1); - // Vec4 selection_color = SrgbFromHsv(h, s, v); - // // Vec4 selection_color = theme.col.button_active; - // // selection_color.a = 1; - - // Vec4 caret_color = VEC4(1, 1, 1, 0.75); - // caret_color.a *= AbsF32(CosF32(SecondsFromNs(frame->time_ns - V.text_input_ns) * 3)); - - // //- Text region - // UI_SetNext(FloatingPos, VEC2(-palette->text_scroll_px, 0)); - // UI_SetNext(Anchor, UI_Region_Left); - // UI_SetNext(ChildAlignment, UI_Region_Left); - // UI_SetNext(Width, UI_Shrink(0, 1)); - // UI_SetNext( - // Flags, - // UI_BoxFlag_DrawText | - // UI_BoxFlag_Floating | - // UI_BoxFlag_DontClampFloatingX - // ); - // // UI_PushDF(Parent, UI_BuildRowEx(search_scroll_box)) - // UI_PushDF(Parent, UI_BuildRowEx(search_scroll_box)) - // { - // UI_Key caret_box = UI_KeyF("search caret"); - // UI_Key selection_box = UI_KeyF("search selection"); - - // //- Selection - // { - // f32 min = MinF32(palette->caret_end_px, palette->caret_start_px); - // f32 max = MaxF32(palette->caret_end_px, palette->caret_start_px); - // UI_SetNext(Width, UI_Px(max - min, 1)); - // UI_SetNext(Height, caret_height); - // UI_SetNext(FloatingPos, VEC2(min, 0)); - // UI_SetNext(Anchor, UI_Region_Left); - // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX); - // UI_SetNext(BackgroundColor, selection_color); - // UI_SetNext(FontSize, font_size); - // UI_BuildBoxEx(selection_box); - // } - - // //- Text - // { - // UI_SetNext(ChildAlignment, UI_Region_Left); - // UI_SetNext(Width, UI_Shrink(0, 1)); - // UI_SetNext(TextColor, display_text_color); - // UI_SetNext(Text, display_text); - // UI_SetNext( - // Flags, - // UI_BoxFlag_DrawText | - // UI_BoxFlag_DontTruncateText - // ); - // UI_BuildBox(); - // } - - // //- Caret - // if (has_focus) - // { - // UI_SetNext(Width, caret_width); - // UI_SetNext(Height, caret_height); - // UI_SetNext(FloatingPos, VEC2(palette->caret_end_px, 0)); - // UI_SetNext(Anchor, UI_Region_Left); - // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX); - // UI_SetNext(BorderSize, 0); - // UI_SetNext(BackgroundColor, caret_color); - // UI_SetNext(FontSize, font_size); - // UI_BuildBoxEx(caret_box); - // } - // } - // } - // } - // } - // UI_PopCp(UI_TopCp()); - // } - - // UI_BuildDivider(UI_Px(1, 1), divider_color, Axis_Y); - - // ////////////////////////////// - // //- Build palette items list - - // // Scissor box - // UI_SetNext(BackgroundColor, 0); - // UI_SetNext(Rounding, 0); - // 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)); - // { - // // Items & Scrollbar group - // UI_SetNext(Tint, 0); - // UI_SetNext(Rounding, 0); - // UI_PushCp(UI_BuildRow()); - // { - // // Items box - // UI_SetNext(BackgroundColor, 0); - // UI_SetNext(Rounding, 0); - // UI_SetNext(Width, UI_Grow(1, 0)); - // UI_SetNext(Height, UI_Shrink(0, 1)); - // UI_SetNext(FloatingPos, VEC2(0, -lister_offset)); - // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren); - // 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()); - // { - // Enum(PaletteItemFlag) - // { - // PaletteItemFlag_None = 0, - // PaletteItemFlag_IsCmd = (1 << 0), - // PaletteItemFlag_IsTweakVar = (2 << 0), - // }; - - // Struct(PaletteItem) - // { - // PaletteItem *next; - // PaletteItem *prev; - - // UI_Key key; - // PaletteItemFlag flags; - - // V_Hotkey hotkeys[8]; - // String display_name; - - // V_CmdDesc cmd_desc; - // TweakVar tweak_var; - // }; - // PaletteItem *first_item = 0; - // PaletteItem *last_item = 0; - - // ////////////////////////////// - // //- Push command items - - // { - // for (u64 cmd_desc_idx = 0; cmd_desc_idx < countof(V_cmd_descs); ++cmd_desc_idx) - // { - // V_CmdDesc cmd_desc = V_cmd_descs[cmd_desc_idx]; - // if (!(cmd_desc.flags & V_CmdDescFlag_HideFromPalette)) - // { - // PaletteItem *item = PushStruct(frame->arena, PaletteItem); - // { - // item->key = UI_KeyF("cmd palette item %F", FmtString(cmd_desc.name)); - // item->display_name = cmd_desc.display_name; - // item->flags |= PaletteItemFlag_IsCmd; - // item->cmd_desc = cmd_desc; - // // FIXME: Attach active shortcuts instead of default hotkeys - // CopyStructs(item->hotkeys, cmd_desc.default_hotkeys, MinU32(countof(item->hotkeys), countof(cmd_desc.default_hotkeys))); - // } - // DllQueuePush(first_item, last_item, item); - // } - // } - // } - - // ////////////////////////////// - // //- Push tweak variables - - // TweakVarArray tweak_vars = GetAllTweakVars(frame->arena); - - // { - // for (i64 tweak_idx = 0; tweak_idx < tweak_vars.count; ++tweak_idx) - // { - // TweakVar tweak_var = tweak_vars.v[tweak_idx]; - // PaletteItem *item = PushStruct(frame->arena, PaletteItem); - // { - // item->key = UI_KeyF("tweak var palette item %F", FmtString(tweak_var.name)); - // item->display_name = tweak_var.name; - // item->flags |= PaletteItemFlag_IsTweakVar; - // item->tweak_var = tweak_var; - // } - // DllQueuePush(first_item, last_item, item); - // } - // } - - // ////////////////////////////// - // //- Prune non-matching items - - // if (is_searching) - // { - // for (PaletteItem *item = first_item; item;) - // { - // PaletteItem *next = item->next; - // { - // b32 prune = !StringContains(LowerString(frame->arena, item->display_name), search_pattern); - // if (prune) - // { - // DllQueueRemove(first_item, last_item, item); - // } - // } - // item = next; - // } - // } - - // ////////////////////////////// - // //- Build items - - // for (PaletteItem *item = first_item; item; item = item->next) - // { - // // Divider - // if (item != first_item) - // { - // UI_BuildDivider(UI_Px(1, 1), divider_color, Axis_Y); - // } - - // if (UI_Presses(item->key, Button_M1)) - // { - // if (item->flags & PaletteItemFlag_IsCmd) - // { - // String cmd_name = item->cmd_desc.name; - // V_PushVisCmd(cmd_name); - // } - // } - - // // Vec4 item_color = theme.col.window_bg; - // Vec4 item_color = Zi; - // // Vec4 item_color = theme.col.hint; - // Vec4 item_border_color = Zi; - // if (item->flags & PaletteItemFlag_IsCmd) - // { - // item_color = LerpSrgb(item_color, theme.col.button_hot, UI_Hot(item->key)); - // item_color = LerpSrgb(item_color, theme.col.button_active, UI_Active(item->key)); - // item_border_color = LerpSrgb(item_border_color, theme.col.button_active, UI_Hot(item->key)); - // } - // else - // { - // item_border_color = LerpSrgb(item_border_color, theme.col.button_active, UI_Hot(item->key)); - // } - - // UI_SetNext(Tint, 0); - // // UI_SetNext(Width, UI_Px(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_SetNext(BackgroundColor, item_color); - // UI_SetNext(BorderColor, item_border_color); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Rounding, UI_Rpx(5)); - // // UI_SetNext(Width, item_col_width); - // UI_SetNext(Width, UI_Grow(1, 0)); - // // UI_SetNext(Height, UI_Px(item_size_px, 1)); - // // 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_Push(Tag, item->key.v); - - // UI_BuildSpacer(icon_col_width, Axis_X); - - // // Command label - // UI_SetNext(ChildAlignment, UI_Region_Left); - // UI_BuildLabel(item->display_name); - - // // Middle spacer - // UI_BuildSpacer(UI_Grow(1, 0), Axis_X); - - // // Tweak - // if (item->flags & PaletteItemFlag_IsTweakVar) - // { - // TweakVar tweak_var = item->tweak_var; - // String old_tweak_str = tweak_var.value; - // String new_tweak_str = tweak_var.value; - // b32 is_default = MatchString(new_tweak_str, tweak_var.initial); - - // // Reset button - // if (!is_default) - // { - // // UI_BuildSpacer(UI_Px(spacing * 0.5, 1), Axis_X); - // UI_Key reset_key = UI_KeyF("reset"); - - // if (UI_Downs(reset_key, Button_M1)) - // { - // new_tweak_str = tweak_var.initial; - // } - // if (UI_HotAbsolute(reset_key)) - // { - // WND_SetCursor(window_frame, WND_CursorKind_Hand); - // } - - // Vec4 reset_bg = Zi; - // // reset_bg = LerpSrgb(reset_bg, theme.col.button_hot, UI_Hot(reset_key)); - // // reset_bg = LerpSrgb(reset_bg, theme.col.button_active, UI_Active(reset_key)); - - // Vec4 reset_bd = Zi; - // // reset_bd = LerpSrgb(reset_bd, theme.col.button_active, UI_Hot(reset_key)); - // // reset_bd = LerpSrgb(reset_bd, theme.col.text, UI_Hot(reset_key)); - - // Vec4 reset_text_col = theme.col.hint; - // reset_text_col = LerpSrgb(reset_text_col, theme.col.text, UI_Hot(reset_key)); - - // UI_SetNext(Rounding, UI_Rgrow(0.75 * theme.rounding)); - // UI_SetNext(ChildAlignment, UI_Region_Bottom); - // UI_SetNext(BackgroundColor, reset_bg); - // UI_SetNext(BorderColor, reset_bd); - // UI_SetNext(BorderSize, 0); - // UI_SetNext(TextColor, reset_text_col); - // UI_SetNext(Width, UI_Shrink(0, 1)); - // UI_SetNext(Height, UI_Shrink(0, 1)); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h6); - // UI_BuildIconEx(reset_key, theme.icon_font, UI_Icon_Loop2); - // } - - // // Tweak label - // { - // UI_BuildSpacer(icon_col_width, Axis_X); - // if (is_default) - // { - // UI_SetNext(TextColor, theme.col.hint); - // } - // else - // { - // UI_SetNext(TextColor, Color_White); - // } - // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h5); - // UI_SetNext(ChildAlignment, UI_Region_Left); - // UI_SetNext(Width, UI_Shrink(0, 1)); - // UI_SetNext(Height, UI_Shrink(0, 1)); - // UI_SetNext(Text, new_tweak_str); - // UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText); - // UI_SetNext(BackgroundColor, 0); - // UI_SetNext(BorderColor, 0); - // UI_BuildBox(); - // } - - // UI_BuildSpacer(icon_col_width, Axis_X); - - // switch (tweak_var.kind) - // { - // // Boolean tweak - // case TweakKind_Bool: - // { - // UI_Key cb_key = UI_KeyF("tweak checkbox"); - - // b32 tweak_bool = CR_BoolFromString(new_tweak_str); - // if (UI_Downs(cb_key, Button_M1)) - // { - // tweak_bool = !tweak_bool; - // new_tweak_str = StringFromBool(frame->arena, tweak_bool); - // } - - // // Tweak checkbox - // Vec4 cb_bg_color = Zi; - // Vec4 cb_border_color = theme.col.window_bd; - // cb_bg_color = LerpSrgb(cb_bg_color, theme.col.positive, tweak_bool); - // cb_border_color = LerpSrgb(cb_border_color, theme.col.button_active, UI_Hot(cb_key)); - - // UI_SetNext(BackgroundColor, cb_bg_color); - // UI_SetNext(BorderColor, cb_border_color); - // UI_SetNext(Rounding, UI_Rgrow(theme.rounding)); - // UI_SetNext(BorderSize, 1); - // 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_PopCp(UI_TopCp()); - // } break; - - // // Float tweak - // case TweakKind_Float: - // { - // UI_Key slider_key = UI_KeyF("tweak slider"); - // UI_Key marker_key = UI_KeyF("tweak slider marker"); - - // b32 is_hot = UI_HotAbsolute(slider_key) || UI_HotAbsolute(marker_key); - // b32 is_active = UI_Held(slider_key, Button_M1) || UI_Held(marker_key, Button_M1); - // f32 hot = MaxF32(UI_Hot(slider_key), UI_Hot(marker_key)); - - // Vec2 slider_pos = UI_Rect(slider_key).p0; - // Vec2 slider_dims = DimsFromRng2(UI_Rect(slider_key)); - // Vec2 marker_dims = DimsFromRng2(UI_Rect(marker_key)); - // Vec2 half_marker_dims = MulVec2(marker_dims, 0.5); - - // f64 range_min = tweak_var.range.min; - // f64 range_max = tweak_var.range.max; - // if (range_max <= range_min) - // { - // range_max = range_min + 1; - // } - - // f64 tweak_float = CR_FloatFromString(new_tweak_str); - // { - // if (is_active) - // { - // f64 initial_slider_pos = UI_DragRect(slider_key).p0.x; - // f64 initial_marker_width = DimsFromRng2(UI_DragRect(marker_key)).x; - // f64 initial_slider_width = DimsFromRng2(UI_DragRect(slider_key)).x - initial_marker_width; - // f64 initial_cursor = ui_frame->drag_cursor_pos.x; - // f64 initial_ratio = UI_DragMisc(slider_key); - - // f64 virtual_slider_start = initial_cursor - (initial_slider_width * initial_ratio); - // f64 virtual_slider_end = virtual_slider_start + initial_slider_width; - // f64 virtual_cursor_ratio = (frame->ui_cursor.x - virtual_slider_start) / (virtual_slider_end - virtual_slider_start); - - // tweak_float = LerpF64(range_min, range_max, virtual_cursor_ratio); - // tweak_float = ClampF64(tweak_float, range_min, range_max); - // if (frame->ui_cursor.x != prev_frame->ui_cursor.x) - // { - // new_tweak_str = StringFromFloat(frame->arena, tweak_float, tweak_var.precision); - // } - // } - // if (is_hot) - // { - // WND_SetCursor(window_frame, WND_CursorKind_HorizontalResize); - // } - // } - // f32 ratio = 0; - // ratio = (tweak_float - range_min) / (range_max - range_min); - // ratio = ClampF32(ratio, 0, 1); - - // Vec4 slider_bg_color = theme.col.window_bg; - // Vec4 slider_border_color = theme.col.window_bd; - // Vec4 slider_progress_color = theme.col.positive; - // Vec4 marker_bg_color = slider_progress_color; - // slider_border_color = LerpSrgb(slider_border_color, theme.col.button_active, hot); - // marker_bg_color = LerpSrgb(marker_bg_color, theme.col.text, hot); - - // UI_SetNext(BackgroundColor, slider_bg_color); - // UI_SetNext(BorderColor, slider_border_color); - // UI_SetNext(Rounding, UI_Rgrow(theme.rounding)); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Width, UI_Fnt(10, 1)); - // UI_SetNext(Height, UI_Px(tweak_size_px * 0.75, 1)); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_SetNext(Misc, ratio); - // UI_PushCp(UI_BuildRowEx(slider_key)); - // { - // f32 marker_pos = ratio * (slider_dims.x - marker_dims.x); - - // // Slider progress - // { - // UI_SetNext(BackgroundColor, slider_progress_color); - // // UI_SetNext(Rounding, UI_Rgrow(theme.rounding)); - // UI_SetNext(Rounding, 0); - // UI_SetNext(BorderColor, 0); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Width, UI_Px(marker_pos + half_marker_dims.x, 0)); - // UI_SetNext(Height, UI_Px(tweak_size_px * 0.75, 1)); - // UI_BuildBox(); - // } - - // // Slider marker - // { - // UI_SetNext(BackgroundColor, marker_bg_color); - // UI_SetNext(BorderColor, slider_border_color); - // UI_SetNext(Rounding, UI_Rgrow(theme.rounding)); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Width, UI_Px(tweak_size_px, 1)); - // UI_SetNext(Height, UI_Px(tweak_size_px, 1)); - // // UI_SetNext(Anchor, UI_Region_Center); - // // UI_SetNext(FloatingPos, VEC2(marker_pos, (marker_size_px * 0.5))); - // UI_SetNext(FloatingPos, VEC2(marker_pos, -marker_dims.y * 0.125)); - // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse); - // UI_BuildBoxEx(marker_key); - // } - // } - // UI_PopCp(UI_TopCp()); - // } break; - // } - - // if (!MatchString(old_tweak_str, new_tweak_str)) - // { - // TweakVar new_tweak_var = tweak_var; - // new_tweak_var.value = new_tweak_str; - // TweakEx(frame->arena, new_tweak_var, 1); - // } - // } - - // // Command hotkey buttons - // for (u64 i = 0; i < countof(item->hotkeys); ++i) - // { - // UI_Key hotkey_box = UI_KeyF("hotkey%F", FmtUint(i)); - - // Vec4 hotkey_color = Zi; - // Vec4 hotkey_border_color = Zi; - // { - // Vec4 hovered_color = Rgb32(0x103c4c); - // Vec4 pressed_color = hovered_color; - // pressed_color.w = 0.2; - // f32 hotkey_hot = UI_Hot(hotkey_box); - // f32 hotkey_active = UI_Active(hotkey_box); - // f32 hotkey_hovered = UI_HotAbsolute(hotkey_box); - // hotkey_color = LerpSrgb(hotkey_color, hovered_color, hotkey_hot); - // hotkey_color = LerpSrgb(hotkey_color, pressed_color, hotkey_active * hotkey_hovered); - // hotkey_border_color = LerpSrgb(hotkey_border_color, Rgb32(0x0078a6), hotkey_hot); - // } - - // V_Hotkey hotkey = item->hotkeys[i]; - // if (hotkey.button == Button_None) - // { - // break; - // } - // else - // { - // UI_BuildSpacer(UI_Px(10, 1), Axis_X); - - // String hotkey_name = V_StringFromHotkey(UI_FrameArena(), hotkey); - // UI_SetNext(BackgroundColor, hotkey_color); - // UI_SetNext(BorderColor, hotkey_border_color); - // UI_SetNext(Text, hotkey_name); - // UI_SetNext(Width, UI_Shrink(theme.text_padding_x, 1)); - // UI_SetNext(Height, UI_Grow(1, 0)); - // UI_SetNext(Rounding, UI_Rpx(5)); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(ChildAlignment, UI_Region_Center); - // UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_CaptureMouse); - // UI_PushCp(UI_BuildRowEx(hotkey_box)); - // { - // } - // 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()); - - - - - - - - - - // //- Scrollbar - // if (scrollbar_visible) - // { - // UI_BuildSpacer(window_padding, Axis_X); - - // UI_SetNext(Width, scrollbar_width); - // UI_PushCp(UI_BuildBoxEx(scrollbar_key)); - // { - // //- Scrollbar up button - // { - // Vec4 col = theme.col.hint; - // Vec4 bd_col = Zi; - // col = LerpSrgb(col, theme.col.button_active, UI_Active(scrollbar_up_key)); - // bd_col = LerpSrgb(bd_col, theme.col.button_hot, UI_Hot(scrollbar_up_key)); - // bd_col = LerpSrgb(bd_col, theme.col.button_active, UI_Active(scrollbar_up_key)); - // UI_SetNext(ChildAlignment, UI_Region_Center); - // UI_SetNext(BorderColor, bd_col); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Rounding, UI_Rgrow(theme.rounding * 0.5)); - // UI_SetNext(TextColor, col); - // UI_SetNext(Width, UI_Grow(1, 1)); - // UI_SetNext(Height, UI_Fnt(1.5, 1)); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h6); - // UI_BuildIconEx(scrollbar_up_key, theme.icon_font, UI_Icon_ArrowUp2); - // } - - // //- Scrollbar thumb - // { - // UI_SetNext(Height, UI_Grow(1, 0)); - // UI_PushCp(UI_BuildBoxEx(track_key)); - // { - // Vec4 bg = theme.col.button_hot; - // Vec4 bd = bg; - // bg = LerpSrgb(bg, theme.col.button_active, UI_Active(thumb_key)); - // bd = LerpSrgb(bg, theme.col.button_active, UI_Hot(thumb_key)); - - // UI_SetNext(BackgroundColor, bg); - // UI_SetNext(Width, UI_Grow(1, 0)); - // UI_SetNext(Height, UI_Px(new_thumb_height, 1)); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(BorderColor, bd); - // UI_SetNext(Rounding, UI_Rgrow(0.75 * theme.rounding)); - // UI_SetNext(FloatingPos, VEC2(0, new_thumb_start)); - // UI_SetNext(Anchor, UI_Region_Center); - // UI_SetNext(Anchor, UI_Region_Top); - // // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Floating); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingY); - // UI_SetNext(Anchor, UI_Region_Top); - // UI_BuildBoxEx(thumb_key); - // } - // UI_PopCp(UI_TopCp()); - // } - - // //- Scrollbar down button - // { - // Vec4 col = theme.col.hint; - // Vec4 bd_col = Zi; - // col = LerpSrgb(col, theme.col.button_active, UI_Active(scrollbar_down_key)); - // bd_col = LerpSrgb(bd_col, theme.col.button_hot, UI_Hot(scrollbar_down_key)); - // bd_col = LerpSrgb(bd_col, theme.col.button_active, UI_Active(scrollbar_down_key)); - // UI_SetNext(ChildAlignment, UI_Region_Center); - // UI_SetNext(BorderColor, bd_col); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(Rounding, UI_Rgrow(theme.rounding * 0.5)); - // UI_SetNext(TextColor, col); - // UI_SetNext(Width, UI_Grow(1, 1)); - // UI_SetNext(Height, UI_Fnt(1.5, 1)); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h6); - // UI_BuildIconEx(scrollbar_down_key, theme.icon_font, UI_Icon_ArrowDown2); - // } - // } - // UI_PopCp(UI_TopCp()); - // } - // } - // UI_PopCp(UI_TopCp()); - - // UI_BuildDivider(UI_Px(1, 1), divider_color, Axis_Y); - // } - // UI_PopCp(UI_TopCp()); - - // UI_BuildSpacer(window_padding, Axis_X); - // // UI_BuildSpacer(UI_Fnt(100, 1), Axis_Y); - - - - // // FIXME: Remove this - // // if (scrollbar_visible) - // // { - - // // Vec2 scrollbar_pos = scrollbar_reps.UI_Rect().p0; - // // Vec2 scrollbar_dims = DimsFromRng2(scrollbar_reps.UI_Rect()); - // // Vec2 thumb_dims = DimsFromRng2(UI_Rect(thumb_key)); - // // // Vec2 half_thumb_dims = MulVec2(thumb_dims, 0.5); - - - // // // f32 range_min = tweak_var.range.min; - // // // f32 range_max = tweak_var.range.max; - // // // if (range_max <= range_min) - // // // { - // // // range_max = range_min + 1; - // // // } - - - - - - - // // // f32 ratio = 0; - // // // ratio = (tweak_float - range_min) / (range_max - range_min); - // // // ratio = ClampF32(ratio, 0, 1); - - // // if (thumb_reps.draw.buttons[Button_M1].downs) - // // { - // // palette->scroll_begin = palette->scroll; - // // } - // // if (thumb_reps.draw.buttons[Button_M1].held) - // // { - // // palette->scroll = palette->scroll_begin + (frame->screen_cursor.y - ui_frame->drag_cursor_pos.y); - // // } - // // palette->scroll = MaxF32(palette->scroll, 0); - - // // // f32 thumb_offset = 50; - // // f32 thumb_offset = palette->scroll; - - - - - - - // // UI_SetNext(Width, scrollbar_width); - // // UI_PushCp(UI_BuildBoxEx(scrollbar_key)); - // // { - // // UI_Size thumb_height = UI_Fnt(10, 1); - - // // Vec4 thumb_color = VEC4(0, 0.5, 1, 1); - // // thumb_color.a = thumb_reps.UI_Hot() * 0.5 + 0.5; - - // // UI_SetNext(BackgroundColor, thumb_color); - // // UI_SetNext(Width, UI_Grow(1, 0)); - // // UI_SetNext(Height, thumb_height); - // // UI_SetNext(Rounding, UI_Rgrow(1 * theme.rounding)); - // // UI_SetNext(FloatingPos, VEC2(0, thumb_offset)); - // // // UI_SetNext(Anchor, UI_Region_Center); - // // UI_SetNext(Anchor, UI_Region_Top); - // // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Floating); - // // UI_SetNext(Anchor, UI_Region_Top); - // // UI_BuildBoxEx(thumb_key); - // // } - // // UI_PopCp(UI_TopCp()); - // // } - // } - // UI_PopCp(UI_TopCp()); - // // UI_BuildSpacer(window_padding, Axis_Y); - - // // UI_BuildDivider(UI_Px(1, 1), divider_color, Axis_Y); - - // UI_BuildSpacer(header_height, Axis_Y); - // } - // UI_PopCp(UI_TopCp()); - // } - // // UI_PopCp(UI_TopCp()); - // UI_PopCp(palette_cp); - // } - - // UI_Pop(Tag); - // } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -7244,11 +6333,11 @@ void V_TickForever(WaveLaneCtx *lane) { f32 ease_rate = TweakFloat("Debug palette ease rate", 20, 1, 100) * frame->dt; f32 ease_in_target = TweakFloat("Debug palette ease-in target", 1.3, 0, 2); - f32 pref_show = palette->is_showing ? ease_in_target : 0; + f32 pref_show = palette->should_show ? ease_in_target : 0; palette->show = SaturateF32(LerpF32(palette->show, pref_show, ease_rate)); } - if (palette->is_showing || palette->show > 0.001) + if (palette->should_show || palette->show > 0.001) { f32 tweak_size_px = UI_Fnt(1.25, 1).v; @@ -7284,54 +6373,48 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(FloatingPos, palette->pos); 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_SetNext(Flags, UI_BoxFlag_Floating | (UI_BoxFlag_CaptureMouse * !!palette->should_show)); + UI_PushDF(Parent, UI_BuildBoxEx(palette->key)) { - ////////////////////////////// - //- Build title bar - - UI_PushCp(UI_NilKey); + //- Title bar + UI_SetNext(Flags, UI_BoxFlag_DrawText | (UI_BoxFlag_CaptureMouse * !!palette->should_show)); + UI_PushDF(BackgroundColor, titlebar_color) + UI_PushDF(BorderColor, titlebar_border_color) + UI_PushDF(Rounding, UI_Rpx(0)) + UI_PushDF(ChildLayoutAxis, Axis_X) + UI_PushDF(Width, UI_Grow(1, 0)) + UI_PushDF(Height, header_height) + UI_PushDF(FontSize, UI_Top(FontSize) * theme.h5) + UI_PushDF(TextColor, theme.col.hint) + UI_PushDF(ChildAlignment, UI_Region_Center) + UI_PushDF(Parent, UI_BuildBoxEx(titlebar_key)) { - UI_Push(BackgroundColor, titlebar_color); - UI_Push(BorderColor, titlebar_border_color); - UI_Push(Rounding, UI_Rpx(0)); - UI_Push(ChildLayoutAxis, Axis_X); 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_PushDF(FontSize, UI_Top(FontSize) * theme.h5) - UI_PushDF(TextColor, theme.col.hint) - UI_PushDF(ChildAlignment, UI_Region_Center) - UI_PushDF(Parent, UI_BuildBoxEx(titlebar_key)) - { - UI_Push(Width, UI_Grow(1, 0)); - UI_Push(BorderColor, 0); + UI_Push(BorderColor, 0); - // Left title box - UI_BuildRow(); + // Left title box + UI_BuildRow(); - UI_SetNext(Width, UI_Shrink(0, 1)); - UI_BuildIcon(theme.icon_font, UI_Icon_Wrench); + UI_SetNext(Width, UI_Shrink(0, 1)); + UI_BuildIcon(theme.icon_font, UI_Icon_Wrench); - // Title box - // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h3); - UI_SetNext(Width, UI_Shrink(0, 1)); - UI_SetNext(Text, Lit(" Developer Palette")); - UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_BuildBox(); + // Title box + // UI_SetNext(FontSize, UI_Top(FontSize) * theme.h3); + UI_SetNext(Width, UI_Shrink(0, 1)); + UI_SetNext(Text, Lit(" Developer Palette")); + UI_SetNext(Flags, UI_BoxFlag_DrawText); + UI_BuildBox(); - // Right title box - UI_BuildRow(); - } + // Right title box + UI_BuildRow(); } - 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_PushDF(Parent, UI_BuildRow()) { UI_BuildSpacer(window_padding, Axis_X); @@ -7339,7 +6422,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_PushDF(Parent, UI_BuildColumn()) { ////////////////////////////// //- Build searchbox @@ -7395,7 +6478,7 @@ void V_TickForever(WaveLaneCtx *lane) has_focus = 1; V.text_input_ns = frame->time_ns; } - if (!palette->is_showing) + if (!palette->should_show) { has_focus = 0; } @@ -7489,7 +6572,6 @@ void V_TickForever(WaveLaneCtx *lane) { //- Compute caret / selection pos { - // TODO: Cache result of caret search when textbox f32 target_caret_start_px = 0; f32 target_caret_end_px = 0; if (search_text.len > 0) @@ -7531,15 +6613,20 @@ void V_TickForever(WaveLaneCtx *lane) palette->caret_end_px = LerpF32(palette->caret_end_px, target_caret_end_px, caret_end_lerp_rate); } + // Calculate textbox width if we're not scaling up + if (palette->show > 0.99) + { + palette->text_scroll_view_width_px = DimsFromRng2(UI_Rect(search_box)).x; + } + //- Determine text scroll pos - f32 search_box_width = DimsFromRng2(UI_Rect(search_box)).x; { { f32 new_text_scroll_px = palette->caret_end_px - 10; palette->text_scroll_px = MinF32(palette->text_scroll_px, new_text_scroll_px); } { - f32 new_text_scroll_px = palette->caret_end_px - search_box_width + 10; + f32 new_text_scroll_px = palette->caret_end_px - palette->text_scroll_view_width_px + 10; palette->text_scroll_px = MaxF32(palette->text_scroll_px, new_text_scroll_px); } palette->text_scroll_px = MaxF32(palette->text_scroll_px, 0); @@ -7633,12 +6720,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_PushDF(Parent, UI_BuildRowEx(scissor_key)) { // Items & Scrollbar group UI_SetNext(Tint, 0); UI_SetNext(Rounding, 0); - UI_PushCp(UI_BuildRow()); + UI_PushDF(Parent, UI_BuildRow()) { // Items box UI_SetNext(BackgroundColor, 0); @@ -7647,13 +6734,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_DontClampFloatingY | UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren); - UI_PushCp(UI_BuildRowEx(lister_key)); + UI_PushDF(Parent, 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_PushDF(Parent, UI_BuildColumn()) { Enum(PaletteItemFlag) { @@ -7780,7 +6867,7 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(Width, UI_Px(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_PushDF(Parent, UI_BuildRow()) { UI_SetNext(BackgroundColor, item_color); UI_SetNext(BorderColor, item_border_color); @@ -7792,7 +6879,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_PushDF(Parent, UI_BuildRowEx(item->key)) { UI_Push(Tag, item->key.v); @@ -7903,10 +6990,7 @@ 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_PopCp(UI_TopCp()); + UI_BuildRowEx(cb_key); } break; // Float tweak @@ -7976,7 +7060,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Height, UI_Px(tweak_size_px * 0.75, 1)); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); UI_SetNext(Misc, ratio); - UI_PushCp(UI_BuildRowEx(slider_key)); + UI_PushDF(Parent, UI_BuildRowEx(slider_key)) { f32 marker_pos = ratio * (slider_dims.x - marker_dims.x); @@ -8007,7 +7091,6 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildBoxEx(marker_key); } } - UI_PopCp(UI_TopCp()); } break; } @@ -8057,25 +7140,17 @@ 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_box)); - { - } - UI_PopCp(UI_TopCp()); + UI_BuildRowEx(hotkey_box); } } // 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()); @@ -8091,7 +7166,7 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildSpacer(window_padding, Axis_X); UI_SetNext(Width, scrollbar_width); - UI_PushCp(UI_BuildBoxEx(scrollbar_key)); + UI_PushDF(Parent, UI_BuildBoxEx(scrollbar_key)) { //- Scrollbar up button { @@ -8158,14 +7233,10 @@ 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_BuildDivider(UI_Px(1, 1), divider_color, Axis_Y); } - UI_PopCp(UI_TopCp()); UI_BuildSpacer(window_padding, Axis_X); // UI_BuildSpacer(UI_Fnt(100, 1), Axis_Y); @@ -8238,14 +7309,12 @@ void V_TickForever(WaveLaneCtx *lane) // UI_PopCp(UI_TopCp()); // } } - UI_PopCp(UI_TopCp()); // UI_BuildSpacer(window_padding, Axis_Y); // UI_BuildDivider(UI_Px(1, 1), divider_color, Axis_Y); UI_BuildSpacer(header_height, Axis_Y); } - UI_PopCp(UI_TopCp()); } // UI_PopCp(UI_TopCp()); UI_PopCp(palette_cp); @@ -8263,6 +7332,22 @@ void V_TickForever(WaveLaneCtx *lane) + + + + + + + + + + + + + + + + @@ -8930,6 +8015,8 @@ void V_TickForever(WaveLaneCtx *lane) String name = P_StringFromEnt(player); if (guy->is_guy && name.len > 0) { + String display_text = name; + Vec2 guy_world_pos = guy->xf.t; // guy_world_pos.y -= UI_Top(FontSize) * 0.01; guy_world_pos.y -= 0.25; @@ -8946,7 +8033,7 @@ void V_TickForever(WaveLaneCtx *lane) // UI_SetNext(TextColor, Color_Transparent); UI_SetNext(FloatingPos, text_pos); UI_PushDF(Parent, UI_BuildBox()) - UI_PushDF(Text, name) + UI_PushDF(Text, display_text) { // Drop-shadow UI_SetNext(TextColor, Color_Black); @@ -8974,7 +8061,7 @@ void V_TickForever(WaveLaneCtx *lane) if (V_CountVisCmds(V_CmdKind_toggle_palette)) { - frame->palette.is_showing = !frame->palette.is_showing; + frame->palette.should_show = !frame->palette.should_show; } if (V_CountVisCmds(V_CmdKind_zoom_in)) diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index c7358b67..a4d2a592 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -234,7 +234,7 @@ Struct(V_Palette) { Vec2 pos; UI_Key key; - b32 is_showing; + b32 should_show; f32 show; f32 scroll; @@ -250,6 +250,7 @@ Struct(V_Palette) f32 caret_start_px; f32 caret_end_px; f32 text_scroll_px; + f32 text_scroll_view_width_px; V_TextboxState search_state; }; @@ -287,6 +288,7 @@ Struct(V_ZoneTrack) { V_ZoneTrack *next; V_Zone *root_zone; + WaveLaneCtx *lane; u64 id; ProfTrack *prof_track; @@ -432,6 +434,7 @@ Struct(V_Frame) f64 blend_sim_tick; f64 blend_predict_tick; + b32 is_resizing; b32 held_buttons[Button_COUNT]; // User input state captured for gameplay b32 real_held_buttons[Button_COUNT]; // Actual state of user input regardless of keyboard / mouse focus V_Palette palette; diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 2c500a9d..e654d868 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -826,8 +826,6 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) } break; } } - - //- Update mouse capture tree top_hot_box = top_active_box ? top_active_box : top_hovered_box; //- Update box feedback @@ -866,55 +864,12 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) f32 target_exists = feedback->exists_absolute ? upper_target : lower_target; f64 target_misc = box->desc.misc; - // f32 delta_active_rate = box->desc.active_rate * frame->dt; - // f32 delta_hot_rate = box->desc.hot_rate * frame->dt; - // f32 delta_hovered_rate = box->desc.hovered_rate * frame->dt; - // f32 delta_exists_rate = box->desc.exists_rate * frame->dt; - // f32 delta_misc_rate = box->desc.misc_rate * frame->dt; - // // delta_active_rate = IsNan(delta_active_rate) ? 1 : delta_active_rate; - // // delta_hot_rate = IsNan(delta_hot_rate) ? 1 : delta_hot_rate; - // // delta_hovered_rate = IsNan(delta_hovered_rate) ? 1 : delta_hovered_rate; - // // delta_exists_rate = IsNan(delta_exists_rate) ? 1 : delta_exists_rate; - // // delta_misc_rate = IsNan(delta_misc_rate) ? 1 : delta_misc_rate; - - // feedback->active_smooth = SaturateF32(LerpF32(feedback->active_smooth, target_active, delta_active_rate)); - // feedback->hot_smooth = SaturateF32(LerpF32(feedback->hot_smooth, target_hot, delta_hot_rate)); - // feedback->hovered_smooth = SaturateF32(LerpF32(feedback->hovered_smooth, target_hovered, delta_hovered_rate)); - // feedback->exists_smooth = SaturateF32(LerpF32(feedback->exists_smooth, target_exists, delta_exists_rate)); - // feedback->misc_smooth = SaturateF64(LerpF64(feedback->misc_smooth, target_misc, delta_misc_rate)); - - - - - - - - feedback->active_smooth = SaturateF32(LerpF32(feedback->active_smooth, target_active, box->desc.active_rate * frame->dt)); feedback->hot_smooth = SaturateF32(LerpF32(feedback->hot_smooth, target_hot, box->desc.hot_rate * frame->dt)); feedback->hovered_smooth = SaturateF32(LerpF32(feedback->hovered_smooth, target_hovered, box->desc.hovered_rate * frame->dt)); feedback->exists_smooth = SaturateF32(LerpF32(feedback->exists_smooth, target_exists, box->desc.exists_rate * frame->dt)); - feedback->misc_smooth = SaturateF64(LerpF64(feedback->misc_smooth, target_misc, box->desc.misc_rate * frame->dt)); - - - - - - // f32 active_blend_rate = (15 * frame->dt); - // f32 hot_blend_rate = (15 * frame->dt); - // f32 hovered_blend_rate = (15 * frame->dt); - // f32 exists_blend_rate = (30 * frame->dt); - // // f64 misc_blend_rate = (30 * frame->dt); - // f64 misc_blend_rate = 1; - - // feedback->active_smooth = SaturateF32(LerpF32(feedback->active_smooth, target_active, active_blend_rate)); - // feedback->hot_smooth = SaturateF32(LerpF32(feedback->hot_smooth, target_hot, hot_blend_rate)); - // feedback->hovered_smooth = SaturateF32(LerpF32(feedback->hovered_smooth, target_hovered, hovered_blend_rate)); - // feedback->exists_smooth = SaturateF32(LerpF32(feedback->exists_smooth, target_exists, exists_blend_rate)); - // feedback->misc_smooth = SaturateF32(LerpF32(feedback->misc_smooth, target_misc, misc_blend_rate)); - - + feedback->misc_smooth = LerpF64(feedback->misc_smooth, target_misc, SaturateF64(box->desc.misc_rate * frame->dt)); feedback->screen_rect = box->screen_rect; feedback->screen_anchor = box->screen_anchor; diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 7e99718b..c2faf9b4 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -314,7 +314,7 @@ Struct(UI_BoxDesc) f32 hot_rate; f32 hovered_rate; f32 exists_rate; - f32 misc_rate; + f64 misc_rate; Vec2 dims_rate; }; diff --git a/src/window/window_win32/window_win32.c b/src/window/window_win32/window_win32.c index db15b43d..446d6310 100644 --- a/src/window/window_win32/window_win32.c +++ b/src/window/window_win32/window_win32.c @@ -111,7 +111,7 @@ void WND_Bootstrap(void) ////////////////////////////// //- Dispatch msg processor - DispatchWave(Lit("Win32 msg loop"), 1, WND_W32_ProcessMessagesForever, 0); + DispatchWave(Lit("Win32 msg loop"), 1, WND_W32_ProcessMessagesForever, 0, 0); } ////////////////////////////////////////////////////////////