Add source code printer helper.

This commit is contained in:
Bartosz Taudul 2024-06-08 13:07:12 +02:00
parent ef1c8e8512
commit e09379bd16
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 32 additions and 0 deletions

View File

@ -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 ); draw->AddText( wpos + ImVec2( round( (w-1-rsz) * 0.5 ), ty15 ), 0x66FFFFFF, range );
} }
void PrintSource( const std::vector<Tokenizer::Line>& 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 );
}
}
} }

View File

@ -7,12 +7,14 @@
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#include <vector>
#include "imgui.h" #include "imgui.h"
#include "imgui_internal.h" #include "imgui_internal.h"
#include "../public/common/TracyForceInline.hpp" #include "../public/common/TracyForceInline.hpp"
#include "IconsFontAwesome6.h" #include "IconsFontAwesome6.h"
#include "TracySourceTokenizer.hpp"
#if !IMGUI_DEFINE_MATH_OPERATORS #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 ); } 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 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 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 DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty );
void PrintSource( const std::vector<Tokenizer::Line>& lines );
static constexpr const uint32_t SyntaxColors[] = { static constexpr const uint32_t SyntaxColors[] = {