diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index b06b11a6..8ea67e3d 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -583,14 +583,6 @@ String V_StringFromTextboxSelection(Arena *arena, V_TextboxState *tb) return StringFromString32(arena, (String32) { .len = max - min, .text = tb->text32 + min }); } -//////////////////////////////////////////////////////////// -//~ Panel - -b32 V_ShouldIgnorePanel(V_Panel *panel) -{ - return panel->flags & V_PanelFlag_Ignore; -} - //////////////////////////////////////////////////////////// //~ Timeline helpers @@ -3675,11 +3667,9 @@ void V_TickForever(WaveLaneCtx *lane) // f32 speed = 100; f32 speed_spread = speed * 2; - f32 particles_per_meter_per_second = Kibi(128); emitter.pos.p0 = prev_frame->world_cursor; emitter.pos.p1 = frame->world_cursor; - f32 len_meters = MaxF32(Vec2Len(SubVec2(emitter.pos.p1, emitter.pos.p0)), 1); - emitter.count = particles_per_meter_per_second * len_meters * frame->dt; + emitter.count = Kibi(128) * frame->dt; emitter.speed.min = speed - speed_spread * 0.5; emitter.speed.max = speed + speed_spread * 0.5; @@ -3744,12 +3734,9 @@ void V_TickForever(WaveLaneCtx *lane) f32 speed = 100; f32 speed_spread = speed * 2; - f32 particles_per_meter_per_second = Kibi(128); - emitter.pos.p0 = prev_frame->world_cursor; emitter.pos.p1 = frame->world_cursor; - f32 len_meters = MaxF32(Vec2Len(SubVec2(emitter.pos.p1, emitter.pos.p0)), 1); - emitter.count = particles_per_meter_per_second * len_meters * frame->dt; + emitter.count = Kibi(128) * frame->dt; emitter.speed.min = speed - speed_spread * 0.5; emitter.speed.max = speed + speed_spread * 0.5; @@ -3988,6 +3975,49 @@ void V_TickForever(WaveLaneCtx *lane) + ////////////////////////////// + //- Update panels from cmds + + + + + // TODO: Remove this + // if (frame->tick == 1) + // { + // frame->show_consoles = 1; + // } + + + + + + // b32 show_editor_panels = (frame->is_editing && !hide_editor_ui) || TweakBool("Show panels when not editing", 0); + // { + // Struct(PanelBfs) { PanelBfs *next; V_Panel *panel; }; + // PanelBfs *first_panel_bfs = PushStruct(frame->arena, PanelBfs); + // PanelBfs *last_panel_bfs = first_panel_bfs; + // first_panel_bfs->panel = V.root_panel; + // for (PanelBfs *bfs_parent = first_panel_bfs; bfs_parent; bfs_parent = first_panel_bfs) + // { + // SllQueuePop(first_panel_bfs, last_panel_bfs); + // V_Panel *parent_panel = bfs_parent->panel; + // for (V_Panel *panel = parent_panel->first; panel; panel = panel->next) + // { + // PanelBfs *bfs_panel = PushStruct(frame->arena, PanelBfs); + // bfs_panel->panel = panel; + // SllQueuePush(first_panel_bfs, last_panel_bfs, bfs_panel); + // { + // b32 should_show = 1; + // b32 is_editor_panel = !panel->is_organizational && !AnyBit(panel->flags, V_PanelFlag_Screen | V_PanelFlag_Console); + // should_show = should_show && (!is_editor_panel || show_editor_panels); + // should_show = should_show && (!AnyBit(panel->flags, V_PanelFlag_Console) || frame->show_consoles); + // should_show = should_show && (!AnyBit(panel->flags, V_PanelFlag_Profiler) || frame->show_profilers); + // panel->flags = SetBit(panel->flags, V_PanelFlag_Ignore, !should_show); + // } + // } + // } + // } + @@ -4036,177 +4066,250 @@ void V_TickForever(WaveLaneCtx *lane) for (V_Panel *panel = parent_panel->first; panel; panel = panel->next) { - if (!V_ShouldIgnorePanel(panel)) + BfsPanel *panel_bfs = PushStruct(frame->arena, BfsPanel); + panel_bfs->panel = panel; + SllQueuePush(first_bfs_panel, last_bfs_panel, panel_bfs); + panel->bg = theme.col.panel_bg; + panel->bd = theme.col.panel_bd; + panel->opacity = theme.col.panel_opacity; + + UI_PushDF(Tag, panel->contents_box.v) + UI_PushDF(Parent, panel->contents_box) { - BfsPanel *panel_bfs = PushStruct(frame->arena, BfsPanel); - panel_bfs->panel = panel; - SllQueuePush(first_bfs_panel, last_bfs_panel, panel_bfs); + ////////////////////////////// + //- Build console panel - UI_PushDF(Tag, panel->contents_box.v) - UI_PushDF(Parent, panel->contents_box) + if (panel->flags & V_PanelFlag_Console) { - ////////////////////////////// - //- Build console panel + Vec4 level_colors[LogLevel_COUNT][2] = Zi; + SetBytes(level_colors, 0xFF, sizeof(level_colors)); + level_colors[LogLevel_Trace][0] = Rgb(0.1, 0.4, 0.4); + level_colors[LogLevel_Trace][1] = Rgb(0.2, 0.5, 0.5); + level_colors[LogLevel_Debug][0] = Rgb(0.4, 0.1, 0.4); + level_colors[LogLevel_Debug][1] = Rgb(0.5, 0.2, 0.5); + level_colors[LogLevel_Info][0] = Rgb(0.2, 0.2, 0.2); + level_colors[LogLevel_Info][1] = Rgb(0.25, 0.25, 0.25); + level_colors[LogLevel_Success][0] = Rgb(0.1, 0.3, 0.1); + level_colors[LogLevel_Success][1] = Rgb(0.2, 0.4, 0.2); + level_colors[LogLevel_Warning][0] = Rgb(0.4, 0.4, 0.1); + level_colors[LogLevel_Warning][1] = Rgb(0.5, 0.5, 0.2); + level_colors[LogLevel_Error][0] = Rgb(0.4, 0.1, 0.1); + level_colors[LogLevel_Error][1] = Rgb(0.5, 0.2, 0.2); - if (panel->flags & V_PanelFlag_Console) + //- Gather visible logs + Struct(VisLog) { - Vec4 level_colors[LogLevel_COUNT][2] = Zi; - SetBytes(level_colors, 0xFF, sizeof(level_colors)); - level_colors[LogLevel_Trace][0] = Rgb(0.1, 0.4, 0.4); - level_colors[LogLevel_Trace][1] = Rgb(0.2, 0.5, 0.5); - level_colors[LogLevel_Debug][0] = Rgb(0.4, 0.1, 0.4); - level_colors[LogLevel_Debug][1] = Rgb(0.5, 0.2, 0.5); - level_colors[LogLevel_Info][0] = Rgb(0.2, 0.2, 0.2); - level_colors[LogLevel_Info][1] = Rgb(0.25, 0.25, 0.25); - level_colors[LogLevel_Success][0] = Rgb(0.1, 0.3, 0.1); - level_colors[LogLevel_Success][1] = Rgb(0.2, 0.4, 0.2); - level_colors[LogLevel_Warning][0] = Rgb(0.4, 0.4, 0.1); - level_colors[LogLevel_Warning][1] = Rgb(0.5, 0.5, 0.2); - level_colors[LogLevel_Error][0] = Rgb(0.4, 0.1, 0.1); - level_colors[LogLevel_Error][1] = Rgb(0.5, 0.2, 0.2); + VisLog *next; + VisLog *prev; + LogEvent log_ev; + }; + u64 display_logs_count = 0; + VisLog *first_vis_log = 0; + VisLog *last_vis_log = 0; - //- Gather visible logs - Struct(VisLog) + i32 max_log_level = LogLevel_Trace; + + f32 max_display_logs = MaxF32(10, DimsFromRng2(UI_Rect(panel->contents_box)).y / (UI_Top(FontSize))); + LogEventsArray log_events = GetLogEvents(); + { + for (u64 log_event_idx = log_events.count; log_event_idx-- > 0 && display_logs_count < max_display_logs;) { - VisLog *next; - VisLog *prev; - LogEvent log_ev; - }; - u64 display_logs_count = 0; - VisLog *first_vis_log = 0; - VisLog *last_vis_log = 0; - - i32 max_log_level = LogLevel_Trace; - - f32 max_display_logs = MaxF32(10, DimsFromRng2(UI_Rect(panel->contents_box)).y / (UI_Top(FontSize))); - LogEventsArray log_events = GetLogEvents(); - { - for (u64 log_event_idx = log_events.count; log_event_idx-- > 0 && display_logs_count < max_display_logs;) + LogEvent ev = log_events.events[log_event_idx]; + if (ev.level <= max_log_level) { - LogEvent ev = log_events.events[log_event_idx]; - if (ev.level <= max_log_level) - { - VisLog *vis_log = PushStruct(frame->arena, VisLog); - vis_log->log_ev = ev; - DllQueuePush(first_vis_log, last_vis_log, vis_log); - ++display_logs_count; - } - } - } - - //- Build log entries UI - UI_PushDF(ChildAlignment, UI_Region_BottomLeft) - // UI_PushDF(Anchor, UI_Region_BottomLeft) - // UI_SetNext(Height, UI_Shrink(0, 1)); - UI_PushDF(Parent, UI_BuildColumn()) - { - // UI_SetNext(BackgroundColor, VEC4(0.1, 0.5, 0.5, 0.8)); - // UI_SetNext(Height, UI_Grow(1, 0)); - // UI_BuildBox(); - - // UI_SetNext(Flags, UI_BoxFlag_Floating) - UI_SetNext(Height, UI_Shrink(0, 1)); - UI_PushDF(Parent, UI_BuildColumn()) - { - for (VisLog *vis_log = last_vis_log; vis_log; vis_log = vis_log->prev) - { - - LogEvent ev = vis_log->log_ev; - String log_msg = ev.msg; - String display_text = StringF(frame->arena, "%F", FmtString(log_msg)); - - Vec4 color = level_colors[ev.level][ev.level_id % 2]; - color.a *= 0.55; - - UI_SetNext(BackgroundColor, color); - UI_SetNext(Height, UI_Shrink(0, 1)); - UI_PushDF(Parent, UI_BuildRow()) - { - // UI_BuildLabelF("%F", FmtString(text)); - UI_SetNext(Height, UI_Shrink(0, 1)); - UI_SetNext(Text, display_text); - // UI_SetNext(ChildAlignment, UI_Region_BottomLeft); - // UI_SetNext(ChildAlignment, UI_Region_TopLeft); - UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_BuildBox(); - } - } + VisLog *vis_log = PushStruct(frame->arena, VisLog); + vis_log->log_ev = ev; + DllQueuePush(first_vis_log, last_vis_log, vis_log); + ++display_logs_count; } } } - - - - - - - - - - - - ////////////////////////////// - //- Build spawner panel - - - - - - - if (panel->flags & V_PanelFlag_Spawn) + //- Build log entries UI + UI_PushDF(ChildAlignment, UI_Region_BottomLeft) + // UI_PushDF(Anchor, UI_Region_BottomLeft) + // UI_SetNext(Height, UI_Shrink(0, 1)); + UI_PushDF(Parent, UI_BuildColumn()) { - UI_Size window_padding = UI_Fnt(0.60, 1); - Vec4 divider_color = VEC4(0.35, 0.35, 0.35, 1); + // UI_SetNext(BackgroundColor, VEC4(0.1, 0.5, 0.5, 0.8)); + // UI_SetNext(Height, UI_Grow(1, 0)); + // UI_BuildBox(); - UI_PushDF(Parent, UI_BuildRow()) + // UI_SetNext(Flags, UI_BoxFlag_Floating) + UI_SetNext(Height, UI_Shrink(0, 1)); + UI_PushDF(Parent, UI_BuildColumn()) { - UI_BuildSpacer(window_padding, Axis_X); - UI_PushDF(Parent, UI_BuildColumn()) + for (VisLog *vis_log = last_vis_log; vis_log; vis_log = vis_log->prev) { - UI_BuildSpacer(window_padding, Axis_Y); - //- Header + LogEvent ev = vis_log->log_ev; + String log_msg = ev.msg; + String display_text = StringF(frame->arena, "%F", FmtString(log_msg)); + + Vec4 color = level_colors[ev.level][ev.level_id % 2]; + color.a *= 0.55; + + UI_SetNext(BackgroundColor, color); + UI_SetNext(Height, UI_Shrink(0, 1)); + UI_PushDF(Parent, UI_BuildRow()) { - UI_SetNext(Text, Lit("Spawn")); - UI_SetNext(ChildAlignment, UI_Region_Center); - UI_SetNext(FontSize, UI_Top(FontSize) * theme.h3); + // UI_BuildLabelF("%F", FmtString(text)); UI_SetNext(Height, UI_Shrink(0, 1)); + UI_SetNext(Text, display_text); + // UI_SetNext(ChildAlignment, UI_Region_BottomLeft); + // UI_SetNext(ChildAlignment, UI_Region_TopLeft); UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_BuildRow(); + UI_BuildBox(); } + } + } + } + } - // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildDivider(UI_Px(1, 0), theme.col.divider, Axis_Y); - UI_BuildSpacer(window_padding, Axis_Y); - //- Tiles + + + + + + + + + + + ////////////////////////////// + //- Build spawner panel + + + + + + + if (panel->flags & V_PanelFlag_Spawn) + { + UI_Size window_padding = UI_Fnt(0.60, 1); + Vec4 divider_color = VEC4(0.35, 0.35, 0.35, 1); + + UI_PushDF(Parent, UI_BuildRow()) + { + UI_BuildSpacer(window_padding, Axis_X); + UI_PushDF(Parent, UI_BuildColumn()) + { + UI_BuildSpacer(window_padding, Axis_Y); + + //- Header + { + UI_SetNext(Text, Lit("Spawn")); + UI_SetNext(ChildAlignment, UI_Region_Center); + UI_SetNext(FontSize, UI_Top(FontSize) * theme.h3); + UI_SetNext(Height, UI_Shrink(0, 1)); + UI_SetNext(Flags, UI_BoxFlag_DrawText); + UI_BuildRow(); + } + + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildDivider(UI_Px(1, 0), theme.col.divider, Axis_Y); + UI_BuildSpacer(window_padding, Axis_Y); + + //- Tiles + { + for (P_TileKind tile_kind = 0; tile_kind < P_TileKind_COUNT; ++tile_kind) { - for (P_TileKind tile_kind = 0; tile_kind < P_TileKind_COUNT; ++tile_kind) + UI_BuildDivider(UI_Px(1, 0), divider_color, Axis_Y); + + String tile_name = P_NameFromTileKind(tile_kind); + UI_Key tile_box = UI_KeyF("Tile %F", FmtString(tile_name)); + + if (UI_Downs(tile_box, Button_M1)) + { + frame->edit_mode = V_EditMode_Tile; + frame->equipped_tile = tile_kind; + } + + Vec4 bg_color = Zi; + bg_color = LerpSrgb(bg_color, theme.col.button_hot, UI_Hot(tile_box)); + bg_color = LerpSrgb(bg_color, theme.col.button_active, UI_Active(tile_box)); + + b32 is_selected = ( + frame->edit_mode == V_EditMode_Tile && + tile_kind == frame->equipped_tile + ); + + Vec4 border_color = Zi; + // border_color = LerpSrgb(border_color, theme.col.button_selected, UI_Misc(tile_box)); + border_color = LerpSrgb(border_color, theme.col.button_active, UI_Hot(tile_box)); + + UI_SetNext(BackgroundColor, bg_color); + UI_SetNext(BorderColor, border_color); + UI_SetNext(BorderSize, 1); + UI_SetNext(Width, UI_Grow(1, 0)); + UI_SetNext(Height, UI_Shrink(UI_Fnt(0.25, 0).v, 0)); + UI_SetNext(Misc, is_selected); + UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); + UI_SetNext(ChildAlignment, UI_Region_Left); + UI_PushDF(Parent, UI_BuildRowEx(tile_box)) + { + UI_BuildSpacer(UI_Fnt(0.25, 0), Axis_X); + + // Tile sprite + { + String sheet_name = StringF(frame->arena, "tile/%F.ase", FmtString(tile_name)); + ResourceKey sheet_resource = ResourceKeyFromStore(&P_Resources, sheet_name); + SPR_SheetKey sheet = SPR_SheetKeyFromResource(sheet_resource); + + UI_SetNext(ChildAlignment, UI_Region_Center); + UI_SetNext(Width, UI_Fnt(2.5, 0)); + UI_SetNext(Height, UI_Fnt(2.5, 0)); + UI_SetNext(SpriteSheet, sheet); + UI_BuildRow(); + } + + UI_BuildSpacer(UI_Fnt(0.5, 0), Axis_X); + + // Tile name + { + UI_SetNext(ChildAlignment, UI_Region_Center); + UI_SetNext(Text, tile_name); + UI_SetNext(Flags, UI_BoxFlag_DrawText); + UI_SetNext(Width, UI_Shrink(4, 0)); + UI_SetNext(Height, UI_Shrink(2, 0)); + UI_BuildRow(); + } + } + } + } + + //- Prefabs + + { + for (P_PrefabKind prefab_kind = 0; prefab_kind < P_PrefabKind_COUNT; ++prefab_kind) + { + String prefab_name = P_NameFromPrefabKind(prefab_kind); + P_PrefabFlag prefab_flags = P_FlagsFromPrefabKind(prefab_kind); + if (!AnyBit(prefab_flags, P_PrefabFlag_HideFromEditor)) { UI_BuildDivider(UI_Px(1, 0), divider_color, Axis_Y); - String tile_name = P_NameFromTileKind(tile_kind); - UI_Key tile_box = UI_KeyF("Tile %F", FmtString(tile_name)); + UI_Key prefab_box = UI_KeyF("Prefab %F", FmtString(prefab_name)); - if (UI_Downs(tile_box, Button_M1)) + if (UI_Downs(prefab_box, Button_M1)) { - frame->edit_mode = V_EditMode_Tile; - frame->equipped_tile = tile_kind; + frame->edit_mode = V_EditMode_Prefab; + frame->equipped_prefab = prefab_kind; } Vec4 bg_color = Zi; - bg_color = LerpSrgb(bg_color, theme.col.button_hot, UI_Hot(tile_box)); - bg_color = LerpSrgb(bg_color, theme.col.button_active, UI_Active(tile_box)); + bg_color = LerpSrgb(bg_color, theme.col.button_hot, UI_Hot(prefab_box)); + bg_color = LerpSrgb(bg_color, theme.col.button_active, UI_Active(prefab_box)); b32 is_selected = ( - frame->edit_mode == V_EditMode_Tile && - tile_kind == frame->equipped_tile + frame->edit_mode == V_EditMode_Prefab && + prefab_kind == frame->equipped_prefab ); Vec4 border_color = Zi; - // border_color = LerpSrgb(border_color, theme.col.button_selected, UI_Misc(tile_box)); - border_color = LerpSrgb(border_color, theme.col.button_active, UI_Hot(tile_box)); + // border_color = LerpSrgb(border_color, theme.col.button_selected, UI_Misc(prefab_box)); + border_color = LerpSrgb(border_color, theme.col.button_active, UI_Hot(prefab_box)); UI_SetNext(BackgroundColor, bg_color); UI_SetNext(BorderColor, border_color); @@ -4216,13 +4319,13 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetNext(Misc, is_selected); UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); UI_SetNext(ChildAlignment, UI_Region_Left); - UI_PushDF(Parent, UI_BuildRowEx(tile_box)) + UI_PushDF(Parent, UI_BuildRowEx(prefab_box)) { UI_BuildSpacer(UI_Fnt(0.25, 0), Axis_X); - // Tile sprite + // Prefab sprite { - String sheet_name = StringF(frame->arena, "tile/%F.ase", FmtString(tile_name)); + String sheet_name = StringF(frame->arena, "prefab/%F.ase", FmtString(prefab_name)); ResourceKey sheet_resource = ResourceKeyFromStore(&P_Resources, sheet_name); SPR_SheetKey sheet = SPR_SheetKeyFromResource(sheet_resource); @@ -4235,10 +4338,10 @@ void V_TickForever(WaveLaneCtx *lane) UI_BuildSpacer(UI_Fnt(0.5, 0), Axis_X); - // Tile name + // Prefab name { UI_SetNext(ChildAlignment, UI_Region_Center); - UI_SetNext(Text, tile_name); + UI_SetNext(Text, prefab_name); UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_SetNext(Width, UI_Shrink(4, 0)); UI_SetNext(Height, UI_Shrink(2, 0)); @@ -4247,84 +4350,12 @@ void V_TickForever(WaveLaneCtx *lane) } } } - - //- Prefabs - - { - for (P_PrefabKind prefab_kind = 0; prefab_kind < P_PrefabKind_COUNT; ++prefab_kind) - { - String prefab_name = P_NameFromPrefabKind(prefab_kind); - P_PrefabFlag prefab_flags = P_FlagsFromPrefabKind(prefab_kind); - if (!AnyBit(prefab_flags, P_PrefabFlag_HideFromEditor)) - { - UI_BuildDivider(UI_Px(1, 0), divider_color, Axis_Y); - - UI_Key prefab_box = UI_KeyF("Prefab %F", FmtString(prefab_name)); - - if (UI_Downs(prefab_box, Button_M1)) - { - frame->edit_mode = V_EditMode_Prefab; - frame->equipped_prefab = prefab_kind; - } - - Vec4 bg_color = Zi; - bg_color = LerpSrgb(bg_color, theme.col.button_hot, UI_Hot(prefab_box)); - bg_color = LerpSrgb(bg_color, theme.col.button_active, UI_Active(prefab_box)); - - b32 is_selected = ( - frame->edit_mode == V_EditMode_Prefab && - prefab_kind == frame->equipped_prefab - ); - - Vec4 border_color = Zi; - // border_color = LerpSrgb(border_color, theme.col.button_selected, UI_Misc(prefab_box)); - border_color = LerpSrgb(border_color, theme.col.button_active, UI_Hot(prefab_box)); - - UI_SetNext(BackgroundColor, bg_color); - UI_SetNext(BorderColor, border_color); - UI_SetNext(BorderSize, 1); - UI_SetNext(Width, UI_Grow(1, 0)); - UI_SetNext(Height, UI_Shrink(UI_Fnt(0.25, 0).v, 0)); - UI_SetNext(Misc, is_selected); - UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - UI_SetNext(ChildAlignment, UI_Region_Left); - UI_PushDF(Parent, UI_BuildRowEx(prefab_box)) - { - UI_BuildSpacer(UI_Fnt(0.25, 0), Axis_X); - - // Prefab sprite - { - String sheet_name = StringF(frame->arena, "prefab/%F.ase", FmtString(prefab_name)); - ResourceKey sheet_resource = ResourceKeyFromStore(&P_Resources, sheet_name); - SPR_SheetKey sheet = SPR_SheetKeyFromResource(sheet_resource); - - UI_SetNext(ChildAlignment, UI_Region_Center); - UI_SetNext(Width, UI_Fnt(2.5, 0)); - UI_SetNext(Height, UI_Fnt(2.5, 0)); - UI_SetNext(SpriteSheet, sheet); - UI_BuildRow(); - } - - UI_BuildSpacer(UI_Fnt(0.5, 0), Axis_X); - - // Prefab name - { - UI_SetNext(ChildAlignment, UI_Region_Center); - UI_SetNext(Text, prefab_name); - UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_SetNext(Width, UI_Shrink(4, 0)); - UI_SetNext(Height, UI_Shrink(2, 0)); - UI_BuildRow(); - } - } - } - } - } - UI_BuildSpacer(window_padding, Axis_Y); } - UI_BuildSpacer(window_padding, Axis_X); + UI_BuildSpacer(window_padding, Axis_Y); } + UI_BuildSpacer(window_padding, Axis_X); } + } @@ -4352,454 +4383,453 @@ void V_TickForever(WaveLaneCtx *lane) - ////////////////////////////// - //- Build profiler panel + ////////////////////////////// + //- Build profiler panel - if (panel->flags & V_PanelFlag_Profiler) - ProfZoneDF("Build profiler panel") + if (panel->flags & V_PanelFlag_Profiler) + ProfZoneDF("Build profiler panel") + { + // FIXME: Finalize + + + + // // FIXME: Remove this + // if (frame->tick == 1) + // { + // frame->profiler.is_showing = 1; + // } + + + + + + + + + + + V_Profiler *profiler = &panel->profiler; + + f64 min_profiler_ns_per_px = 1; + // f64 max_profiler_ns_per_px = NsFromSeconds(100); + f64 max_profiler_ns_per_px = frame->time_ns / 10; + profiler->target_ns_per_px = ClampF64(profiler->target_ns_per_px, min_profiler_ns_per_px, max_profiler_ns_per_px); + profiler->ns_per_px = ClampF64(profiler->ns_per_px, min_profiler_ns_per_px, max_profiler_ns_per_px); + + UI_PushDF(OmitFlags, UI_BoxFlag_CaptureMouse * !!(frame->is_looking)) + // if (profiler->is_showing) { - // FIXME: Finalize + // FIXME: Remove this - - - // // FIXME: Remove this // if (frame->tick == 1) // { - // frame->profiler.is_showing = 1; + // // profiler->ns_per_px = NsFromSeconds(0.0001); + // profiler->target_ns_per_px = NsFromSeconds(0.01); // } - - - - - - - - - V_Profiler *profiler = &panel->profiler; - - f64 min_profiler_ns_per_px = 1; - // f64 max_profiler_ns_per_px = NsFromSeconds(100); - f64 max_profiler_ns_per_px = frame->time_ns / 10; - profiler->target_ns_per_px = ClampF64(profiler->target_ns_per_px, min_profiler_ns_per_px, max_profiler_ns_per_px); - profiler->ns_per_px = ClampF64(profiler->ns_per_px, min_profiler_ns_per_px, max_profiler_ns_per_px); - - UI_PushDF(OmitFlags, UI_BoxFlag_CaptureMouse * !!(frame->is_looking)) - // if (profiler->is_showing) + // FIXME: Remove this { - // FIXME: Remove this + V_ProfilerFrame *pf = &V.profiler_frames[V.profiler_frame_seq % V_ProfilerFramesCap]; + V.profiler_frame_seq += 1; + } - // if (frame->tick == 1) + + //- Build profiler + // UI_Key profiler_box = UI_KeyF("profiler"); + // // UI_PushDF(Tag, profiler_box.v) + // UI_PushDF(Parent, profiler_box) + { + UI_Key main_box = UI_KeyF("main"); + + // UI_Size profiler_height = UI_Fnt(70, 1); + UI_Size profiler_height = UI_Grow(1, 0); + UI_Size header_height = UI_Fnt(2, 1); + UI_Size footer_height = UI_Fnt(2, 1); + UI_Size window_padding = UI_Fnt(0.60, 1); + UI_Size minor_padding = UI_Fnt(0.15, 1); + // UI_Size graph_height = UI_Grow(0.25, 0); + UI_Size graph_height = UI_Fnt(2, 1); + UI_Size main_height = UI_Grow(1, 0); + UI_Size zone_height = UI_Fnt(1.25, 0); + // UI_Size track_height = UI_Fnt(10, 0); + // UI_Size track_height = UI_Grow(1, 0); + UI_Size track_height = UI_Shrink(0, 0); + f32 zone_text_padding_px = UI_Top(FontSize) * 0.2; + + // Vec2 old_main_dims = DimsFromRng2(UI_Rect(main_box)); + // old_main_dims.x = MaxF32(old_main_dims.x, 1); + // old_main_dims.y = MaxF32(old_main_dims.y, 1); + + + + // if (profiler->view_start_ns == 0 && profiler->view_end_ns == 0) // { - // // profiler->ns_per_px = NsFromSeconds(0.0001); - // profiler->target_ns_per_px = NsFromSeconds(0.01); + // profiler->view_start_ns = NsFromSeconds(0); + // profiler->view_end_ns = NsFromSeconds(10); // } - // FIXME: Remove this + // f32 old_cursor_offset_px = frame->screen_cursor.x - UI_Rect(main_box).p0.x; + // i64 old_cursor_offset_ns = (old_cursor_offset_px / old_main_dims.x) * (profiler->view_end_ns - profiler->view_start_ns); + // i64 old_cursor_ns = profiler->view_start_ns + old_cursor_offset_ns; + + f32 cursor_px = frame->screen_cursor.x - UI_Rect(main_box).p0.x; + + b32 is_main_hot = UI_HotAbsolute(main_box); + // if (is_main_hot) { - V_ProfilerFrame *pf = &V.profiler_frames[V.profiler_frame_seq % V_ProfilerFramesCap]; - V.profiler_frame_seq += 1; + profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns; + } + + // Snap view + if (!profiler->unsnap) + { + f64 snap_width_ns = NsFromSeconds(1.0 / 10.0); + profiler->target_view_ns = frame->time_ns - snap_width_ns; + profiler->target_ns_per_px = snap_width_ns / MaxF32(DimsFromRng2(UI_Rect(main_box)).x, 100); + } + + f32 prof_zoom_rate = 1.65; + f64 prof_lerp_rate = SaturateF64(frame->dt * 25); + + { + f64 zooms = UI_Presses(main_box, Button_WheelDown) - UI_Presses(main_box, Button_WheelUp); + if (zooms != 0) + { + profiler->unsnap = 1; + } + f64 zoom_factor = PowF64(prof_zoom_rate, zooms); + profiler->target_ns_per_px *= zoom_factor; + profiler->target_view_ns = profiler->cursor_ns - (profiler->cursor_ns - profiler->target_view_ns) * zoom_factor; + if (zooms != 0) + { + profiler->last_zoom_delta = profiler->target_ns_per_px - profiler->ns_per_px; + profiler->last_view_delta = profiler->target_view_ns - profiler->view_ns; + } + f64 overshoot_factor = 0.01; + profiler->ns_per_px = LerpF64(profiler->ns_per_px, profiler->target_ns_per_px + profiler->last_zoom_delta * overshoot_factor, prof_lerp_rate); + profiler->view_ns = LerpF64(profiler->view_ns, profiler->target_view_ns + profiler->last_view_delta * overshoot_factor, prof_lerp_rate); + + if (profiler->last_zoom_delta < 0) + { + profiler->ns_per_px = MaxF64(profiler->ns_per_px, profiler->target_ns_per_px); + } + else if (profiler->last_zoom_delta > 0) + { + profiler->ns_per_px = MinF64(profiler->ns_per_px, profiler->target_ns_per_px); + } + + if (profiler->last_view_delta < 0) + { + profiler->view_ns = MaxF64(profiler->view_ns, profiler->target_view_ns); + } + else if (profiler->last_view_delta > 0) + { + profiler->view_ns = MinF64(profiler->view_ns, profiler->target_view_ns); + } } - //- Build profiler - // UI_Key profiler_box = UI_KeyF("profiler"); - // // UI_PushDF(Tag, profiler_box.v) - // UI_PushDF(Parent, profiler_box) + + + + + + + + + + + + + + + + + // if (profiler->is_dragging && !prev_frame->profiler.is_dragging) + // { + // profiler->drag_view_ns = profiler->view_ns; + // profiler->drag_cursor_px = cursor_px; + // } + + // if (profiler->is_dragging) + // { + // profiler->view_ns = profiler->drag_view_ns - ((cursor_px - profiler->drag_cursor_px) * profiler->ns_per_px); + // } + + + + + // FIXME: Recalc cursor after zoom + + + + + // if (is_main_hot) { - UI_Key main_box = UI_KeyF("main"); - - // UI_Size profiler_height = UI_Fnt(70, 1); - UI_Size profiler_height = UI_Grow(1, 0); - UI_Size header_height = UI_Fnt(2, 1); - UI_Size footer_height = UI_Fnt(2, 1); - UI_Size window_padding = UI_Fnt(0.60, 1); - UI_Size minor_padding = UI_Fnt(0.15, 1); - // UI_Size graph_height = UI_Grow(0.25, 0); - UI_Size graph_height = UI_Fnt(2, 1); - UI_Size main_height = UI_Grow(1, 0); - UI_Size zone_height = UI_Fnt(1.25, 0); - // UI_Size track_height = UI_Fnt(10, 0); - // UI_Size track_height = UI_Grow(1, 0); - UI_Size track_height = UI_Shrink(0, 0); - f32 zone_text_padding_px = UI_Top(FontSize) * 0.2; - - // Vec2 old_main_dims = DimsFromRng2(UI_Rect(main_box)); - // old_main_dims.x = MaxF32(old_main_dims.x, 1); - // old_main_dims.y = MaxF32(old_main_dims.y, 1); + profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns; + } - // if (profiler->view_start_ns == 0 && profiler->view_end_ns == 0) - // { - // profiler->view_start_ns = NsFromSeconds(0); - // profiler->view_end_ns = NsFromSeconds(10); - // } - // f32 old_cursor_offset_px = frame->screen_cursor.x - UI_Rect(main_box).p0.x; - // i64 old_cursor_offset_ns = (old_cursor_offset_px / old_main_dims.x) * (profiler->view_end_ns - profiler->view_start_ns); - // i64 old_cursor_ns = profiler->view_start_ns + old_cursor_offset_ns; - f32 cursor_px = frame->screen_cursor.x - UI_Rect(main_box).p0.x; + // TODO: Drag in px units for sharper resolution + if (UI_Downs(main_box, Button_M2) || UI_Downs(main_box, Button_M3)) + { + profiler->drag_view_ns = profiler->view_ns; + profiler->drag_cursor_px = cursor_px; + } - b32 is_main_hot = UI_HotAbsolute(main_box); - // if (is_main_hot) + // Drag ruler + // TODO: When measuring stopped, lerp ruler closed + b32 is_measuring = 0; + if (UI_Downs(main_box, Button_M1)) + { + profiler->unsnap = 1; + profiler->ruler_start_ns = profiler->cursor_ns; + } + if (UI_Held(main_box, Button_M1)) + { + profiler->unsnap = 1; + is_measuring = 1; + profiler->target_ruler_opacity = 1; + } + else + { + profiler->target_ruler_opacity = 0; + } + profiler->ruler_opacity = LerpF32(profiler->ruler_opacity, profiler->target_ruler_opacity, prof_lerp_rate); + + // Drag view + if (UI_Held(main_box, Button_M2) || UI_Held(main_box, Button_M3)) + { + profiler->unsnap = 1; + profiler->view_ns = profiler->drag_view_ns - ((cursor_px - profiler->drag_cursor_px) * profiler->ns_per_px); + profiler->target_view_ns = profiler->view_ns; + } + + + + + + + + + // FIXME: Remove this + b32 do_break = frame->real_held_buttons[Button_B] && !prev_frame->real_held_buttons[Button_B]; + + + + + + + + // FIXME: Remove this + f64 view_range_len_px = DimsFromRng2(UI_Rect(main_box)).x; + f64 view_range_len_ns = view_range_len_px * profiler->ns_per_px; + + f64 view_start_ns = profiler->view_ns; + f64 view_end_ns = view_start_ns + view_range_len_ns; + + f64 view_start_px = view_start_ns / profiler->ns_per_px; + f64 view_end_px = view_end_ns / profiler->ns_per_px; + + + + + + + + + + + + + + + + + //- Generate visible zones + + Struct(VisZone) + { + VisZone *parent; + VisZone *next; + VisZone *next_bfs; + V_Zone *zone; + + u32 depth; + u64 id; + String name; + Vec4 color; + + f64 start_px; + f64 end_px; + + i64 start_ns; + i64 end_ns; + + u64 collapsed_count; + }; + + Struct(VisTrack) + { + VisTrack *next; + u64 id; + + u32 rows_count; + VisZone *first_zone; + VisZone *last_zone; + }; + + VisTrack *first_vis_track = 0; + VisTrack *last_vis_track = 0; + 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") + { + for (V_ZoneTrack *zone_track = V.first_zone_track; zone_track; zone_track = zone_track->next) { - profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns; - } + // TODO: Ignore non-visible tracks + // TODO: Ignore non-visible depths - // Snap view - if (!profiler->unsnap) - { - f64 snap_width_ns = NsFromSeconds(1.0 / 10.0); - profiler->target_view_ns = frame->time_ns - snap_width_ns; - profiler->target_ns_per_px = snap_width_ns / MaxF32(DimsFromRng2(UI_Rect(main_box)).x, 100); - } + VisTrack *vis_track = PushStruct(frame->arena, VisTrack); + SllQueuePush(first_vis_track, last_vis_track, vis_track); + vis_track->id = zone_track->id; - f32 prof_zoom_rate = 1.65; - f64 prof_lerp_rate = SaturateF64(frame->dt * 25); + VisZone *first_bfs_vis_zone = 0; + VisZone *last_bfs_vis_zone = 0; - { - f64 zooms = UI_Presses(main_box, Button_WheelDown) - UI_Presses(main_box, Button_WheelUp); - if (zooms != 0) + // Push root vis zone node to bfs { - profiler->unsnap = 1; - } - f64 zoom_factor = PowF64(prof_zoom_rate, zooms); - profiler->target_ns_per_px *= zoom_factor; - profiler->target_view_ns = profiler->cursor_ns - (profiler->cursor_ns - profiler->target_view_ns) * zoom_factor; - if (zooms != 0) - { - profiler->last_zoom_delta = profiler->target_ns_per_px - profiler->ns_per_px; - profiler->last_view_delta = profiler->target_view_ns - profiler->view_ns; - } - f64 overshoot_factor = 0.01; - profiler->ns_per_px = LerpF64(profiler->ns_per_px, profiler->target_ns_per_px + profiler->last_zoom_delta * overshoot_factor, prof_lerp_rate); - profiler->view_ns = LerpF64(profiler->view_ns, profiler->target_view_ns + profiler->last_view_delta * overshoot_factor, prof_lerp_rate); - - if (profiler->last_zoom_delta < 0) - { - profiler->ns_per_px = MaxF64(profiler->ns_per_px, profiler->target_ns_per_px); - } - else if (profiler->last_zoom_delta > 0) - { - profiler->ns_per_px = MinF64(profiler->ns_per_px, profiler->target_ns_per_px); + VisZone *root_bfs = PushStruct(frame->arena, VisZone); + root_bfs->zone = zone_track->root_zone; + root_bfs->start_px = -Inf; + root_bfs->end_px = Inf; + root_bfs->start_ns = I64Min; + root_bfs->end_ns = I64Max; + root_bfs->id = zone_track->root_zone->id; + SllQueuePushN(first_bfs_vis_zone, last_bfs_vis_zone, root_bfs, next_bfs); } - if (profiler->last_view_delta < 0) + for (VisZone *parent_vis = first_bfs_vis_zone; parent_vis; parent_vis = first_bfs_vis_zone) { - profiler->view_ns = MaxF64(profiler->view_ns, profiler->target_view_ns); - } - else if (profiler->last_view_delta > 0) - { - profiler->view_ns = MinF64(profiler->view_ns, profiler->target_view_ns); - } - } + SllQueuePopN(first_bfs_vis_zone, last_bfs_vis_zone, next_bfs); + V_Zone *parent = parent_vis->zone; - - - - - - - - - - - - - - - - - - // if (profiler->is_dragging && !prev_frame->profiler.is_dragging) - // { - // profiler->drag_view_ns = profiler->view_ns; - // profiler->drag_cursor_px = cursor_px; - // } - - // if (profiler->is_dragging) - // { - // profiler->view_ns = profiler->drag_view_ns - ((cursor_px - profiler->drag_cursor_px) * profiler->ns_per_px); - // } - - - - - // FIXME: Recalc cursor after zoom - - - - - // if (is_main_hot) - { - profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns; - } - - - - - - - // TODO: Drag in px units for sharper resolution - if (UI_Downs(main_box, Button_M2) || UI_Downs(main_box, Button_M3)) - { - profiler->drag_view_ns = profiler->view_ns; - profiler->drag_cursor_px = cursor_px; - } - - // Drag ruler - // TODO: When measuring stopped, lerp ruler closed - b32 is_measuring = 0; - if (UI_Downs(main_box, Button_M1)) - { - profiler->unsnap = 1; - profiler->ruler_start_ns = profiler->cursor_ns; - } - if (UI_Held(main_box, Button_M1)) - { - profiler->unsnap = 1; - is_measuring = 1; - profiler->target_ruler_opacity = 1; - } - else - { - profiler->target_ruler_opacity = 0; - } - profiler->ruler_opacity = LerpF32(profiler->ruler_opacity, profiler->target_ruler_opacity, prof_lerp_rate); - - // Drag view - if (UI_Held(main_box, Button_M2) || UI_Held(main_box, Button_M3)) - { - profiler->unsnap = 1; - profiler->view_ns = profiler->drag_view_ns - ((cursor_px - profiler->drag_cursor_px) * profiler->ns_per_px); - profiler->target_view_ns = profiler->view_ns; - } - - - - - - - - - // FIXME: Remove this - b32 do_break = frame->real_held_buttons[Button_B] && !prev_frame->real_held_buttons[Button_B]; - - - - - - - - // FIXME: Remove this - f64 view_range_len_px = DimsFromRng2(UI_Rect(main_box)).x; - f64 view_range_len_ns = view_range_len_px * profiler->ns_per_px; - - f64 view_start_ns = profiler->view_ns; - f64 view_end_ns = view_start_ns + view_range_len_ns; - - f64 view_start_px = view_start_ns / profiler->ns_per_px; - f64 view_end_px = view_end_ns / profiler->ns_per_px; - - - - - - - - - - - - - - - - - //- Generate visible zones - - Struct(VisZone) - { - VisZone *parent; - VisZone *next; - VisZone *next_bfs; - V_Zone *zone; - - u32 depth; - u64 id; - String name; - Vec4 color; - - f64 start_px; - f64 end_px; - - i64 start_ns; - i64 end_ns; - - u64 collapsed_count; - }; - - Struct(VisTrack) - { - VisTrack *next; - u64 id; - - u32 rows_count; - VisZone *first_zone; - VisZone *last_zone; - }; - - VisTrack *first_vis_track = 0; - VisTrack *last_vis_track = 0; - 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") - { - 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); - vis_track->id = zone_track->id; - - VisZone *first_bfs_vis_zone = 0; - VisZone *last_bfs_vis_zone = 0; - - // Push root vis zone node to bfs + // Process child zones { - VisZone *root_bfs = PushStruct(frame->arena, VisZone); - root_bfs->zone = zone_track->root_zone; - root_bfs->start_px = -Inf; - root_bfs->end_px = Inf; - root_bfs->start_ns = I64Min; - root_bfs->end_ns = I64Max; - root_bfs->id = zone_track->root_zone->id; - SllQueuePushN(first_bfs_vis_zone, last_bfs_vis_zone, root_bfs, next_bfs); - } - - for (VisZone *parent_vis = first_bfs_vis_zone; parent_vis; parent_vis = first_bfs_vis_zone) - { - SllQueuePopN(first_bfs_vis_zone, last_bfs_vis_zone, next_bfs); - V_Zone *parent = parent_vis->zone; - - // Process child zones + b32 reached_end_of_view = 0; + VisZone *left_vis = 0; + for (V_ZoneChunk *chunk = parent->first_chunk; chunk && !reached_end_of_view; chunk = chunk->next) { - b32 reached_end_of_view = 0; - VisZone *left_vis = 0; - for (V_ZoneChunk *chunk = parent->first_chunk; chunk && !reached_end_of_view; chunk = chunk->next) + i64 chunk_start_ns = chunk->zones[0].start_ns; + i64 chunk_end_ns = MinI64(chunk->zones[chunk->count - 1].end_ns, frame->time_ns); + + // i64 should_collapse_chunk = (chunk->end_ns - chunk->start_ns) / + + if (chunk_start_ns <= view_end_ns && chunk_end_ns >= view_start_ns) { - i64 chunk_start_ns = chunk->zones[0].start_ns; - i64 chunk_end_ns = MinI64(chunk->zones[chunk->count - 1].end_ns, frame->time_ns); - - // i64 should_collapse_chunk = (chunk->end_ns - chunk->start_ns) / - - if (chunk_start_ns <= view_end_ns && chunk_end_ns >= view_start_ns) + // TODO: Binary search to find start within chunk + for (u64 chunk_zone_idx = 0; chunk_zone_idx < chunk->count && !reached_end_of_view; ++chunk_zone_idx) { - // TODO: Binary search to find start within chunk - for (u64 chunk_zone_idx = 0; chunk_zone_idx < chunk->count && !reached_end_of_view; ++chunk_zone_idx) + V_Zone *zone = &chunk->zones[chunk_zone_idx]; + if (zone->start_ns > view_end_ns) { - V_Zone *zone = &chunk->zones[chunk_zone_idx]; - if (zone->start_ns > view_end_ns) - { - reached_end_of_view = 1; - } - else - { - 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; - 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); + reached_end_of_view = 1; + } + else + { + 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; + 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; + 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 = MaxF64(visual_zone_end_px, visual_zone_start_px + min_zone_width_px); - { - f32 overshoot = MaxF32(visual_zone_end_px - parent_vis->end_px, 0); - visual_zone_start_px -= overshoot; - visual_zone_end_px -= overshoot; - } - visual_zone_start_px = MaxF64(visual_zone_start_px, parent_vis->start_px); - if (left_vis) - { - visual_zone_start_px = MaxF64(visual_zone_start_px, left_vis->end_px); - } - visual_zone_start_px = RoundF64(visual_zone_start_px); - visual_zone_end_px = RoundF64(visual_zone_end_px); + f32 overshoot = MaxF32(visual_zone_end_px - parent_vis->end_px, 0); + visual_zone_start_px -= overshoot; + visual_zone_end_px -= overshoot; } - - // Push vis zone - if (visual_zone_end_px <= (frame->time_ns / profiler->ns_per_px)) + visual_zone_start_px = MaxF64(visual_zone_start_px, parent_vis->start_px); + if (left_vis) { - b32 should_collapse_zone = (visual_zone_end_px - visual_zone_start_px) <= zone_collapse_threshold_px; - String zone_name = zone->name; - u64 zone_id = zone->id; + visual_zone_start_px = MaxF64(visual_zone_start_px, left_vis->end_px); + } + visual_zone_start_px = RoundF64(visual_zone_start_px); + visual_zone_end_px = RoundF64(visual_zone_end_px); + } - u64 color_seed = HashString(zone->name); - f32 h = (Norm16(color_seed >> 0) * 1) * 360; - f32 s = TweakFloat("Profiler zone saturation", 0.50, 0, 1); - f32 v = TweakFloat("Profiler zone brightness", 1.00, 0, 1); - Vec4 zone_color = SrgbFromHsv(h, s, v); + // 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; + String zone_name = zone->name; + u64 zone_id = zone->id; - // b32 should_collapse_zone = visual_zone_len_px <= zone_collapse_threshold_px; - // b32 should_collapse_zone = 0; + u64 color_seed = HashString(zone->name); + f32 h = (Norm16(color_seed >> 0) * 1) * 360; + f32 s = TweakFloat("Profiler zone saturation", 0.50, 0, 1); + f32 v = TweakFloat("Profiler zone brightness", 1.00, 0, 1); + Vec4 zone_color = SrgbFromHsv(h, s, v); - // if (visual_zone_start_ns > view_end_ns) - // { - // reached_end_of_view = 1; - // } + // b32 should_collapse_zone = visual_zone_len_px <= zone_collapse_threshold_px; + // b32 should_collapse_zone = 0; - if (visual_zone_end_ns >= view_start_ns && visual_zone_start_ns <= view_end_ns) + // if (visual_zone_start_ns > view_end_ns) + // { + // reached_end_of_view = 1; + // } + + if (visual_zone_end_ns >= view_start_ns && visual_zone_start_ns <= view_end_ns) + { + VisZone *vis_zone = 0; + if ( + should_collapse_zone && + left_vis && + left_vis->collapsed_count > 0 && + ((zone_start_ns - left_vis->end_ns) / profiler->ns_per_px) < zone_collapse_threshold_px + ) { - VisZone *vis_zone = 0; - if ( - should_collapse_zone && - left_vis && - left_vis->collapsed_count > 0 && - ((zone_start_ns - left_vis->end_ns) / profiler->ns_per_px) < zone_collapse_threshold_px - ) - { - vis_zone = left_vis; - } - else - { - vis_zone = PushStruct(frame->arena, VisZone); - vis_zone->zone = zone; - vis_zone->parent = parent_vis; - vis_zone->start_ns = zone_start_ns; - vis_zone->start_px = visual_zone_start_px; - vis_zone->name = zone_name; - vis_zone->id = zone_id; - } + vis_zone = left_vis; + } + else + { + vis_zone = PushStruct(frame->arena, VisZone); + vis_zone->zone = zone; + vis_zone->parent = parent_vis; + vis_zone->start_ns = zone_start_ns; + vis_zone->start_px = visual_zone_start_px; + vis_zone->name = zone_name; + vis_zone->id = zone_id; + } - SllQueuePush(vis_track->first_zone, vis_track->last_zone, vis_zone); - vis_zone->end_px = visual_zone_end_px; - vis_zone->end_ns = zone_end_ns; - vis_zone->color = zone_color; - vis_zone->depth = zone->depth; - vis_track->rows_count = MaxU32(vis_track->rows_count, vis_zone->depth); + SllQueuePush(vis_track->first_zone, vis_track->last_zone, vis_zone); + vis_zone->end_px = visual_zone_end_px; + vis_zone->end_ns = zone_end_ns; + vis_zone->color = zone_color; + vis_zone->depth = zone->depth; + vis_track->rows_count = MaxU32(vis_track->rows_count, vis_zone->depth); - if (should_collapse_zone) - { - vis_zone->collapsed_count += zone->total_descendents_count + 1; - } + if (should_collapse_zone) + { + vis_zone->collapsed_count += zone->total_descendents_count + 1; + } - left_vis = vis_zone; + left_vis = vis_zone; - if (!should_collapse_zone) - { - SllQueuePushN(first_bfs_vis_zone, last_bfs_vis_zone, vis_zone, next_bfs); - } + if (!should_collapse_zone) + { + SllQueuePushN(first_bfs_vis_zone, last_bfs_vis_zone, vis_zone, next_bfs); } } } @@ -4810,395 +4840,432 @@ void V_TickForever(WaveLaneCtx *lane) } } } + } - // Vec4 profiler_color = theme.col.window_bg; - Vec4 profiler_color = theme.col.window_bg; - f32 profiler_opacity = TweakFloat("Profiler opacity", 1, 0, 1); + // Vec4 profiler_color = theme.col.window_bg; + Vec4 profiler_color = theme.col.window_bg; + f32 profiler_opacity = TweakFloat("Profiler opacity", 1, 0, 1); - // Vec4 timeline_cursor_color = theme.col.window_bd; - Vec4 timeline_cursor_color = VEC4(0.5, 0.5, 0.5, 1); - timeline_cursor_color.a = UI_Hot(main_box) * 0.75; - UI_Size timeline_cursor_width = UI_Fnt(0.15, 1); + // Vec4 timeline_cursor_color = theme.col.window_bd; + Vec4 timeline_cursor_color = VEC4(0.5, 0.5, 0.5, 1); + timeline_cursor_color.a = UI_Hot(main_box) * 0.75; + UI_Size timeline_cursor_width = UI_Fnt(0.15, 1); - UI_Key hovered_zone_box = Zi; - VisZone *hovered_zone = 0; - f64 ruler_len_ns = 0; + UI_Key hovered_zone_box = Zi; + VisZone *hovered_zone = 0; + f64 ruler_len_ns = 0; - Vec4 main_color_sampled = profiler_color; - main_color_sampled.r *= 0.75; - main_color_sampled.g *= 0.75; - main_color_sampled.b *= 0.75; + Vec4 main_color_sampled = profiler_color; + main_color_sampled.r *= 0.75; + main_color_sampled.g *= 0.75; + main_color_sampled.b *= 0.75; - Vec4 main_color_unsampled = main_color_sampled; - main_color_unsampled.r *= 0.85; - main_color_unsampled.g *= 0.85; - main_color_unsampled.b *= 0.85; + Vec4 main_color_unsampled = main_color_sampled; + main_color_unsampled.r *= 0.85; + main_color_unsampled.g *= 0.85; + main_color_unsampled.b *= 0.85; - Vec4 collapsed_line_color = SrgbFromHsv(64, 1, 0.5); - Vec4 collapsed_text_color = SrgbFromHsv(64, 1, 0.75); + Vec4 collapsed_line_color = SrgbFromHsv(64, 1, 0.5); + Vec4 collapsed_text_color = SrgbFromHsv(64, 1, 0.75); - // main_color_sampled.g += 0.05; + // main_color_sampled.g += 0.05; - // UI_SetNext(Parent, vis_screen_box); - // UI_SetNext(BorderColor, theme.col.window_bd); - // UI_SetNext(BorderSize, 2); - // UI_SetNext(BackgroundColor, profiler_color); - // UI_SetNext(Rounding, UI_Rpx(10 * theme.rounding)); - // UI_SetNext(Height, profiler_height); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_SetNext(Opacity, profiler_opacity); - // UI_SetNext(Parent, panel->contents_box); - // UI_PushDF(Width, UI_Grow(1, 0)) - // UI_PushDF(Parent, UI_BuildColumnEx(profiler_box)) - // UI_PushDF(Parent, UI_BuildRow()) + // UI_SetNext(Parent, vis_screen_box); + // UI_SetNext(BorderColor, theme.col.window_bd); + // UI_SetNext(BorderSize, 2); + // UI_SetNext(BackgroundColor, profiler_color); + // UI_SetNext(Rounding, UI_Rpx(10 * theme.rounding)); + // UI_SetNext(Height, profiler_height); + // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); + // UI_SetNext(Opacity, profiler_opacity); + // UI_SetNext(Parent, panel->contents_box); + // UI_PushDF(Width, UI_Grow(1, 0)) + // UI_PushDF(Parent, UI_BuildColumnEx(profiler_box)) + // UI_PushDF(Parent, UI_BuildRow()) + { + UI_BuildSpacer(window_padding, Axis_X); + UI_PushDF(Parent, UI_BuildColumn()) { - UI_BuildSpacer(window_padding, Axis_X); - UI_PushDF(Parent, UI_BuildColumn()) + //- Header + // UI_PushDF(BackgroundColor, Color_Red) + // UI_SetNext(BorderColor, Color_Red); + // UI_SetNext(BorderSize, 1); + // UI_SetNext(ChildAlignment, UI_Region_Center); + // UI_PushDF(Height, header_height) + // UI_PushDF(Parent, UI_BuildBoxEx(UI_KeyF("profiler header"))) + // { + // UI_PushDF(TextColor, theme.col.hint) + // UI_BuildLabelF("Profiler"); + // } + + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); + + //- Graph + // UI_SetNext(BackgroundColor, Color_Cyan); + UI_SetNext(Height, graph_height); + UI_PushDF(Parent, UI_BuildBoxEx(profiler_graph_box)) { - //- Header - // UI_PushDF(BackgroundColor, Color_Red) - // UI_SetNext(BorderColor, Color_Red); - // UI_SetNext(BorderSize, 1); - // UI_SetNext(ChildAlignment, UI_Region_Center); - // UI_PushDF(Height, header_height) - // UI_PushDF(Parent, UI_BuildBoxEx(UI_KeyF("profiler header"))) - // { - // UI_PushDF(TextColor, theme.col.hint) - // UI_BuildLabelF("Profiler"); - // } + } + // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); - // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildSpacer(window_padding, Axis_Y); - // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); + // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); - //- Graph - // UI_SetNext(BackgroundColor, Color_Cyan); - UI_SetNext(Height, graph_height); - UI_PushDF(Parent, UI_BuildBoxEx(profiler_graph_box)) + UI_BuildSpacer(window_padding, Axis_Y); + + + + + + + //- 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)) + { + //- Active area background + UI_PushDF(Opacity, 0.75) { + 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_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); - // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); - - UI_BuildSpacer(window_padding, Axis_Y); + UI_Size track_padding = UI_Px(window_padding.v * 2, 0); + // FIXME: Remove this + panel->bg = main_color_unsampled; + panel->opacity = 1; - - - //- 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)) + //- Zone tracks + ProfZoneDF("Build zones") { - //- Active area background - UI_PushDF(Opacity, 0.75) + for (VisTrack *vis_track = first_vis_track; vis_track; vis_track = vis_track->next) { - f64 aabg_left_ns = MaxF64(0, profiler->view_ns); - f64 aabg_right_ns = MinF64(frame->time_ns, view_end_ns); + // 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_len_ns = aabg_right_ns - aabg_left_ns; - f64 aabg_len_px = aabg_len_ns / profiler->ns_per_px; + Vec2 track_dims_rate = VEC2(Inf, 10); - 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 - theme.col.panel_bg = main_color_unsampled; - theme.col.panel_opacity = 1; - - - //- Zone tracks - ProfZoneDF("Build zones") - { - for (VisTrack *vis_track = first_vis_track; vis_track; vis_track = vis_track->next) + UI_SetNext(Height, track_height); + UI_SetNext(DimsRate, track_dims_rate); + UI_PushDF(Tag, track_box.v) + UI_PushDF(Parent, UI_BuildColumnEx(track_box)) { - // 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, 10); + // UI_BuildSpacer(window_padding, Axis_Y); + // UI_BuildSpacer(window_padding, Axis_Y); UI_SetNext(Height, track_height); - UI_SetNext(DimsRate, track_dims_rate); - UI_PushDF(Tag, track_box.v) - UI_PushDF(Parent, UI_BuildColumnEx(track_box)) + UI_PushDF(Parent, UI_BuildRow()) { - // 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_SetNext(DimsRate, track_dims_rate); UI_SetNext(Height, track_height); - UI_PushDF(Parent, UI_BuildRow()) + UI_PushDF(Parent, UI_BuildColumnEx(UI_KeyF("track area"))) { - // UI_BuildSpacer(window_padding, Axis_X); - // UI_BuildSpacer(window_padding, Axis_X); + 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_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_BuildSpacer(window_padding, Axis_Y); - - // 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_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(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_PushDF(Text, Lit(" Async ")) + // UI_PushDF(TextColor, theme.col.hint) + UI_BuildBox(); - UI_PushDF(Text, Lit("Lane 0")) - UI_PushDF(TextColor, theme.col.hint) - UI_BuildBox(); - } + UI_PushDF(Text, Lit("Lane 0")) + 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_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_PushDF(Parent, UI_BuildColumn()) { - // UI_BuildSpacer(window_padding, Axis_Y); - UI_SetNext(Height, track_height); - UI_PushDF(Parent, UI_BuildColumn()) + // 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_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)) { - 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_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) + { + 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); + } - // 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) + if (zone_len_px < zone_name_hide_threshold_px) { - UI_Key zone_row_box = zone_row_boxes[zone->depth - 1]; - b32 can_hover = profiler->unsnap; + zone_text.len = 0; + } - 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); + 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; - String zone_text = zone->name; + 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) { - 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); - + // 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(); } - if (zone_len_px < zone_name_hide_threshold_px) + if (zone_text.len > 0) { - 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(); + } - 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 = 0.3; - // f32 zag_intensity = TweakFloat("RAAAAAAAAAAAAAH", 1, 0, 1); - - 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)) - { + // Right collapsed lines if (is_collapsed) { - // Left zag UI_SetNext(Width, UI_Grow(1, 0)); UI_SetNext(ZagColor, zone_line_color); UI_BuildBox(); @@ -5208,269 +5275,233 @@ 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); - // 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) + //- 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 { - 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(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_PushDF(Width, UI_Shrink(0, 1)) - UI_PushDF(Height, UI_Shrink(0, 1)) - UI_PushDF(Parent, UI_BuildRowEx(tooltip_box)) + 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_X); + UI_BuildSpacer(window_padding, Axis_Y); - UI_SetNext(Width, UI_Shrink(0, 1)); - UI_SetNext(Height, UI_Shrink(0, 1)); - UI_PushDF(Parent, UI_BuildColumn()) + if (show_ruler_time) { - UI_BuildSpacer(window_padding, Axis_Y); + // UI_SetNext(TextColor, theme.col.positive); + // UI_SetNext(TextColor, theme.col.button_active); - 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("%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); - } - } + // UI_SetNext(TextColor, theme.col.button_selected); + // UI_BuildLabelF("Ruler"); if (show_hovered_zone) { - VisZone *zone = hovered_zone; - UI_PushDF(Parent, UI_BuildRow()) + 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()) { - 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_BuildLabelF("%F ", FmtTimeNs(elapsed_ns, .p = 2)); - - if (zone->collapsed_count > 0) + UI_PushDF(Parent, UI_BuildRow()) { - UI_PushDF(Parent, UI_BuildRow()) + if (zone->collapsed_count == 1) { - 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_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(" (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("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, 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)); - } + // 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)); - } + } + 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_Y); } + UI_BuildSpacer(window_padding, Axis_X); } } } - - // UI_BuildSpacer(window_padding, Axis_Y); - - // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); - - //- Footer - UI_PushDF(Height, footer_height) - UI_PushDF(ChildAlignment, UI_Region_Center) - UI_PushDF(Parent, UI_BuildRow()) - { - if (IsUnoptimized) - { - UI_PushDF(Width, UI_Shrink(0, 1)) - UI_PushDF(Height, UI_Shrink(0, 1)) - UI_PushDF(ChildAlignment, UI_Region_Left) - UI_PushDF(TextColor, theme.col.warn) - UI_PushDF(Parent, UI_BuildRow()) - { - UI_BuildIcon(theme.icon_font, UI_Icon_Warning); - // UI_BuildIcon(theme.icon_font, UI_Icon_Info); - UI_BuildLabelF(" Profiling an unoptimized build"); - } - } - - // Right side text - UI_BuildSpacer(UI_Grow(1, 0), Axis_X); - UI_SetNext(Opacity, UI_Hot(main_box)); - UI_BuildLabelF("%Fs", FmtFloat(SecondsFromNs(profiler->cursor_ns), .p = 3)); - } } - UI_BuildSpacer(window_padding, Axis_X); + + // UI_BuildSpacer(window_padding, Axis_Y); + + // UI_BuildDivider(UI_Px(1, 1), theme.col.divider, Axis_Y); + + //- Footer + UI_PushDF(Height, footer_height) + UI_PushDF(ChildAlignment, UI_Region_Center) + UI_PushDF(Parent, UI_BuildRow()) + { + if (IsUnoptimized) + { + UI_PushDF(Width, UI_Shrink(0, 1)) + UI_PushDF(Height, UI_Shrink(0, 1)) + UI_PushDF(ChildAlignment, UI_Region_Left) + UI_PushDF(TextColor, theme.col.warn) + UI_PushDF(Parent, UI_BuildRow()) + { + UI_BuildIcon(theme.icon_font, UI_Icon_Warning); + // UI_BuildIcon(theme.icon_font, UI_Icon_Info); + UI_BuildLabelF(" Profiling an unoptimized build"); + } + } + + // Right side text + UI_BuildSpacer(UI_Grow(1, 0), Axis_X); + UI_SetNext(Opacity, UI_Hot(main_box)); + UI_BuildLabelF("%Fs", FmtFloat(SecondsFromNs(profiler->cursor_ns), .p = 3)); + } } + UI_BuildSpacer(window_padding, Axis_X); } } } @@ -5528,18 +5559,18 @@ void V_TickForever(WaveLaneCtx *lane) 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; - } + // //- 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 { @@ -5555,31 +5586,30 @@ void V_TickForever(WaveLaneCtx *lane) } } - //- Test spawn panel + // //- 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 = left_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_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; + panel->flags |= V_PanelFlag_Profiler; + panel->pct = 0.5; } //- Vis screen panel @@ -5595,18 +5625,18 @@ void V_TickForever(WaveLaneCtx *lane) panel->pct = 1; } - // //- Test profiler panel + // //- Test console panel // { + // V_Panel *parent = right_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(); + // 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_Profiler; - // panel->flags |= V_PanelFlag_Ignore; - // panel->pct = 2; + // panel->flags |= V_PanelFlag_Console; + // // panel->flags |= V_PanelFlag_Spawn; + // panel->pct = 0.25; // } } @@ -5615,53 +5645,6 @@ void V_TickForever(WaveLaneCtx *lane) - ////////////////////////////// - //- Update panels from cmds - - - - - // TODO: Remove this - // if (frame->tick == 1) - // { - // frame->show_consoles = 1; - // } - - - - - - b32 show_editor_panels = (frame->is_editing && !hide_editor_ui) || TweakBool("Show panels when not editing", 0); - { - Struct(PanelBfs) { PanelBfs *next; V_Panel *panel; }; - PanelBfs *first_panel_bfs = PushStruct(frame->arena, PanelBfs); - PanelBfs *last_panel_bfs = first_panel_bfs; - first_panel_bfs->panel = V.root_panel; - for (PanelBfs *bfs_parent = first_panel_bfs; bfs_parent; bfs_parent = first_panel_bfs) - { - SllQueuePop(first_panel_bfs, last_panel_bfs); - V_Panel *parent_panel = bfs_parent->panel; - for (V_Panel *panel = parent_panel->first; panel; panel = panel->next) - { - PanelBfs *bfs_panel = PushStruct(frame->arena, PanelBfs); - bfs_panel->panel = panel; - SllQueuePush(first_panel_bfs, last_panel_bfs, bfs_panel); - { - b32 should_show = 1; - b32 is_editor_panel = !panel->is_organizational && !AnyBit(panel->flags, V_PanelFlag_Screen | V_PanelFlag_Console); - should_show = should_show && (!is_editor_panel || show_editor_panels); - should_show = should_show && (!AnyBit(panel->flags, V_PanelFlag_Console) || frame->show_consoles); - should_show = should_show && (!AnyBit(panel->flags, V_PanelFlag_Profiler) || frame->show_profilers); - panel->flags = SetBit(panel->flags, V_PanelFlag_Ignore, !should_show); - } - } - } - } - - - - - ////////////////////////////// //- Build vis panel contents @@ -5788,20 +5771,14 @@ void V_TickForever(WaveLaneCtx *lane) f32 children_count = 0; for (V_Panel *panel = parent_panel->first; panel; panel = panel->next) { - if (!V_ShouldIgnorePanel(panel)) - { - children_count += 1; - pct_accum += panel->pct; - } + children_count += 1; + pct_accum += panel->pct; } f32 violation = 1.0 - pct_accum; for (V_Panel *panel = parent_panel->first; panel; panel = panel->next) { - if (!V_ShouldIgnorePanel(panel)) - { - panel->pct = panel->pct + violation / children_count; - panel->pct = MaxF32(panel->pct, minimum_panel_pct); - } + panel->pct = panel->pct + violation / children_count; + panel->pct = MaxF32(panel->pct, minimum_panel_pct); } } @@ -5846,130 +5823,1268 @@ void V_TickForever(WaveLaneCtx *lane) //- Build panel boxes for (V_Panel *panel = parent_panel->first; panel; panel = panel->next) { - if (!V_ShouldIgnorePanel(panel)) + PanelBfs *bfs_panel = PushStruct(frame->arena, PanelBfs); + bfs_panel->panel = panel; + SllQueuePush(first_panel_bfs, last_panel_bfs, bfs_panel); + + UI_Key panel_box = panel->box; + UI_Key contents_box = panel->contents_box; + UI_Key resizer_box = panel->resizer_box; + + UI_Size resizer_size = UI_Px(3, 1); + + Vec4 panel_bg = panel->bg; + panel_bg.a *= panel->opacity; + + Vec4 panel_bd = panel->bd; + + Vec4 resizer_color = theme.col.divider; + resizer_color.a *= theme.col.panel_resizer_opacity; + panel_bd.a *= theme.col.panel_border_opacity; + + // f32 panel_pct = panel->pct; + + // UI_SetNext(AxisSize, UI_Grow(panel_pct, 1), .axis = parent_axis); + // UI_SetNext(AxisSize, UI_Grow(panel_pct, 0), .axis = parent_axis); + UI_SetNext(AxisSize, UI_Grow(panel->pct, 0), .axis = parent_axis); + // UI_SetNext(AxisSize, UI_Grow(panel->solved_pct * children_pct_scale, 1), .axis = parent_axis); + // 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_PushDF(Tag, panel_box.v) + UI_PushDF(Parent, UI_BuildBoxEx(panel_box)) { - PanelBfs *bfs_panel = PushStruct(frame->arena, PanelBfs); - bfs_panel->panel = panel; - SllQueuePush(first_panel_bfs, last_panel_bfs, bfs_panel); + // panel_bd.a = 0; + // resizer_color.a = 0; - UI_Key panel_box = panel->box; - UI_Key contents_box = panel->contents_box; - UI_Key resizer_box = panel->resizer_box; - - UI_Size resizer_size = UI_Px(3, 1); - - Vec4 panel_bg = theme.col.panel_bg; - Vec4 panel_bd = theme.col.panel_bd; - panel_bg.a *= theme.col.panel_opacity; - - Vec4 resizer_color = theme.col.divider; - resizer_color.a *= theme.col.panel_resizer_opacity; - panel_bd.a *= theme.col.panel_border_opacity; - - // f32 panel_pct = panel->pct; - - // UI_SetNext(AxisSize, UI_Grow(panel_pct, 1), .axis = parent_axis); - // UI_SetNext(AxisSize, UI_Grow(panel_pct, 0), .axis = parent_axis); - UI_SetNext(AxisSize, UI_Grow(panel->pct, 0), .axis = parent_axis); - // UI_SetNext(AxisSize, UI_Grow(panel->solved_pct * children_pct_scale, 1), .axis = parent_axis); - // 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_PushDF(Tag, panel_box.v) - UI_PushDF(Parent, UI_BuildBoxEx(panel_box)) + b32 is_screen_panel_box = panel->flags & V_PanelFlag_Screen; + if (is_screen_panel_box || panel->is_organizational) { - // panel_bd.a = 0; - // resizer_color.a = 0; - - b32 is_screen_panel_box = panel->flags & V_PanelFlag_Screen; - if (is_screen_panel_box || panel->is_organizational) - { - panel_bg.a = 0; - panel_bd.a = 0; - resizer_color.a = 0; - } - if (panel->is_organizational) - { - panel_bg.a = 0; - } - - //- Left null-resizer box - // if (!panel->prev && !V_ShouldIgnorePanel(panel->prev)) - // { - // UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); - // UI_SetNext(BackgroundColor, resizer_color); - // UI_BuildBox(); - // } - - //- Panel contents box - { - // UI_SetNext(AxisSize, UI_Grow(panel_pct, 1), .axis = parent_axis); - // UI_SetNext(AxisSize, UI_Grow(1, 0), .axis = !parent_axis); - UI_SetNext(ChildLayoutAxis, panel->axis); - // UI_SetNext(Width, UI_Px(500, 1)); - // UI_SetNext(Height, UI_Px(200, 1)); - UI_SetNext(BackgroundColor, panel_bg); - UI_SetNext(BorderColor, panel_bd); - UI_SetNext(BorderSize, 2); - // 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)) - { - } - } - - - - //- Resizer box - b32 can_resize = panel->next != 0 && !V_ShouldIgnorePanel(panel->next); - if (can_resize) - { - UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); - UI_SetNext(BackgroundColor, resizer_color); - UI_SetNext(Flags, UI_BoxFlag_CaptureMouse * !!can_resize); - UI_BuildBoxEx(resizer_box); - } - - - // //- Overlay box - // { - // // UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); - // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = parent_axis); - // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = !parent_axis); - // // UI_SetNext(AxisSize, UI_Grow(1, 1), .axis = !parent_axis); - // // UI_SetNext(AxisSize, UI_Grow(1, 1), .axis = !parent_axis); - // // UI_SetNext(BackgroundColor, Color_Cyan); - // // UI_SetNext(Anchor, UI_Region_Center); - // UI_SetNext(ChildLayoutAxis, parent_axis); - // UI_SetNext(Flags, UI_BoxFlag_Floating); - // UI_SetNext(Parent, contents_box); - // // FIXME: Don't use contents box - // UI_PushDF(Parent, UI_BuildBoxEx(UI_KeyF("overlay box"))) - // { - // UI_SetNext(AxisSize, UI_Grow(1, 0), .axis = parent_axis); - // UI_BuildBox(); - - // //- Resizer box - // if (panel->next) - // { - // UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); - // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = parent_axis); - // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = !parent_axis); - // // UI_SetNext(AxisSize, UI_Grow(1, 1), .axis = !parent_axis); - // // UI_SetNext(BackgroundColor, theme.col.divider); - // UI_SetNext(Anchor, UI_Region_Center); - // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); - // UI_BuildBoxEx(resizer_box); - // } - // } - // } + panel_bg.a = 0; + panel_bd.a = 0; + resizer_color.a = 0; } + if (panel->is_organizational) + { + panel_bg.a = 0; + } + + //- Left null-resizer box + // if (!panel->prev && !V_ShouldIgnorePanel(panel->prev)) + // { + // UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); + // UI_SetNext(BackgroundColor, resizer_color); + // UI_BuildBox(); + // } + + //- Panel contents box + { + // UI_SetNext(AxisSize, UI_Grow(panel_pct, 1), .axis = parent_axis); + // UI_SetNext(AxisSize, UI_Grow(1, 0), .axis = !parent_axis); + UI_SetNext(ChildLayoutAxis, panel->axis); + // UI_SetNext(Width, UI_Px(500, 1)); + // UI_SetNext(Height, UI_Px(200, 1)); + UI_SetNext(BackgroundColor, panel_bg); + UI_SetNext(BorderColor, panel_bd); + UI_SetNext(BorderSize, 2); + // 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)) + { + } + } + + + + //- Resizer box + b32 can_resize = panel->next != 0; + if (can_resize) + { + UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); + UI_SetNext(BackgroundColor, resizer_color); + UI_SetNext(Flags, UI_BoxFlag_CaptureMouse * !!can_resize); + UI_BuildBoxEx(resizer_box); + } + + + // //- Overlay box + // { + // // UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); + // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = parent_axis); + // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = !parent_axis); + // // UI_SetNext(AxisSize, UI_Grow(1, 1), .axis = !parent_axis); + // // UI_SetNext(AxisSize, UI_Grow(1, 1), .axis = !parent_axis); + // // UI_SetNext(BackgroundColor, Color_Cyan); + // // UI_SetNext(Anchor, UI_Region_Center); + // UI_SetNext(ChildLayoutAxis, parent_axis); + // UI_SetNext(Flags, UI_BoxFlag_Floating); + // UI_SetNext(Parent, contents_box); + // // FIXME: Don't use contents box + // UI_PushDF(Parent, UI_BuildBoxEx(UI_KeyF("overlay box"))) + // { + // UI_SetNext(AxisSize, UI_Grow(1, 0), .axis = parent_axis); + // UI_BuildBox(); + + // //- Resizer box + // if (panel->next) + // { + // UI_SetNext(AxisSize, resizer_size, .axis = parent_axis); + // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = parent_axis); + // // UI_SetNext(AxisSize, UI_Px(100, 1), .axis = !parent_axis); + // // UI_SetNext(AxisSize, UI_Grow(1, 1), .axis = !parent_axis); + // // UI_SetNext(BackgroundColor, theme.col.divider); + // UI_SetNext(Anchor, UI_Region_Center); + // UI_SetNext(Flags, UI_BoxFlag_CaptureMouse); + // UI_BuildBoxEx(resizer_box); + // } + // } + // } } } } } } } + + + + + + + + + + // ////////////////////////////// + // //- 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); + // } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -6264,7 +7379,7 @@ void V_TickForever(WaveLaneCtx *lane) b32 is_dragging_text = 0; if (has_focus) { - // Generate & apply mouse selection delta + // Generate & apply mouse text selection delta if (UI_Held(search_box, Button_M1)) { V.text_input_ns = frame->time_ns; @@ -7094,7 +8209,6 @@ void V_TickForever(WaveLaneCtx *lane) - ////////////////////////////// //- Build notifications diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index d5914a6e..f3f1ce02 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -313,11 +313,10 @@ Struct(V_Profiler) Enum(V_PanelFlag) { V_PanelFlag_None = 0, - V_PanelFlag_Ignore = (1 << 0), - V_PanelFlag_Screen = (1 << 1), - V_PanelFlag_Spawn = (1 << 2), - V_PanelFlag_Profiler = (1 << 3), - V_PanelFlag_Console = (1 << 4), + V_PanelFlag_Screen = (1 << 0), + V_PanelFlag_Spawn = (1 << 1), + V_PanelFlag_Profiler = (1 << 2), + V_PanelFlag_Console = (1 << 3), }; Struct(V_Panel) @@ -347,6 +346,12 @@ Struct(V_Panel) V_PanelFlag flags; V_Profiler profiler; + + //- Content-controlled parameters + + Vec4 bg; + Vec4 bd; + f32 opacity; }; //////////////////////////////////////////////////////////// @@ -526,11 +531,6 @@ V_TextboxDeltaFlag V_ApplyTextboxDeltas(V_TextboxState *tb, V_TextboxDeltaList d String V_StringFromTextbox(Arena *arena, V_TextboxState *tb); String V_StringFromTextboxSelection(Arena *arena, V_TextboxState *tb); -//////////////////////////////////////////////////////////// -//~ Panel - -b32 V_ShouldIgnorePanel(V_Panel *panel); - //////////////////////////////////////////////////////////// //~ Timeline helpers