diff --git a/profiler/src/profiler/TracyImGui.cpp b/profiler/src/profiler/TracyImGui.cpp index 695294b5..7714951c 100644 --- a/profiler/src/profiler/TracyImGui.cpp +++ b/profiler/src/profiler/TracyImGui.cpp @@ -98,4 +98,33 @@ void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImV draw->AddText( wpos + ImVec2( round( (w-1-rsz) * 0.5 ), ty15 ), 0x66FFFFFF, range ); } +void PrintSource( const std::vector& lines ) +{ + for( auto& line: lines ) + { + auto ptr = line.begin; + auto it = line.tokens.begin(); + while( ptr < line.end ) + { + if( it == line.tokens.end() ) + { + ImGui::TextUnformatted( ptr, line.end ); + ImGui::SameLine( 0, 0 ); + break; + } + if( ptr < it->begin ) + { + ImGui::TextUnformatted( ptr, it->begin ); + ImGui::SameLine( 0, 0 ); + } + auto color = SyntaxColors[(int)it->color]; + TextColoredUnformatted( color, it->begin, it->end ); + ImGui::SameLine( 0, 0 ); + ptr = it->end; + ++it; + } + ImGui::ItemSize( ImVec2( 0, 0 ), 0 ); + } +} + } diff --git a/profiler/src/profiler/TracyImGui.hpp b/profiler/src/profiler/TracyImGui.hpp index 8e10900a..70b1b9b4 100644 --- a/profiler/src/profiler/TracyImGui.hpp +++ b/profiler/src/profiler/TracyImGui.hpp @@ -7,12 +7,14 @@ #include #include +#include #include "imgui.h" #include "imgui_internal.h" #include "../public/common/TracyForceInline.hpp" #include "IconsFontAwesome6.h" +#include "TracySourceTokenizer.hpp" #if !IMGUI_DEFINE_MATH_OPERATORS static inline ImVec2 operator+( const ImVec2& l, const ImVec2& r ) { return ImVec2( l.x + r.x, l.y + r.y ); } @@ -29,6 +31,7 @@ bool WasActive(); void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color ); void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, double x0, double y0, double x1, double y1, double sw, uint32_t color, bool fix_stripes_in_screen_space, bool inverted ); void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty ); +void PrintSource( const std::vector& lines ); static constexpr const uint32_t SyntaxColors[] = {