From bf61589f3d1cf86ce98b3e50f08338f852527c4c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 11 Jan 2026 16:20:06 +0100 Subject: [PATCH] Separate wrapped text printer from text fixup. --- profiler/src/profiler/TracyImGui.cpp | 11 ----------- profiler/src/profiler/TracyMarkdown.cpp | 26 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/profiler/src/profiler/TracyImGui.cpp b/profiler/src/profiler/TracyImGui.cpp index 62b54bba..72dd92d8 100644 --- a/profiler/src/profiler/TracyImGui.cpp +++ b/profiler/src/profiler/TracyImGui.cpp @@ -131,18 +131,7 @@ void PrintSource( const std::vector& lines ) bool PrintTextWrapped( const char* text, const char* end ) { bool hovered = false; - - // Replace narrow no-break space with no-break space if( !end ) end = text + strlen( text ); - std::string buf( text, end ); - auto found = buf.find( "\xe2\x80\xaf" ); - while( found != std::string::npos ) - { - buf.replace( found, 3, "\xc2\xa0" ); - found = buf.find( "\xe2\x80\xaf", found ); - } - text = buf.c_str(); - end = text + buf.size(); auto firstWord = text; while( firstWord < end && *firstWord != ' ' && *firstWord != '\n' ) firstWord++; diff --git a/profiler/src/profiler/TracyMarkdown.cpp b/profiler/src/profiler/TracyMarkdown.cpp index 39ec80f9..a85f4c97 100644 --- a/profiler/src/profiler/TracyMarkdown.cpp +++ b/profiler/src/profiler/TracyMarkdown.cpp @@ -235,7 +235,7 @@ public: if( !link.empty() ) ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.55f, 0.55f, 1.f, 1.f ) ); Glue(); - const auto hovered = PrintTextWrapped( text, text + size ); + const auto hovered = PrintText( text, text + size ); ImGui::PopFont(); if( !link.empty() ) { @@ -255,14 +255,14 @@ public: } case MD_TEXT_NULLCHAR: Glue(); - PrintTextWrapped( "\xEF\xBF\xBD" ); + PrintText( "\xEF\xBF\xBD" ); break; case MD_TEXT_BR: glue = false; break; case MD_TEXT_SOFTBR: Glue(); - PrintTextWrapped( " " ); + PrintText( " " ); break; case MD_TEXT_CODE: case MD_TEXT_LATEXMATH: @@ -282,7 +282,7 @@ public: } else { - PrintTextWrapped( text, text + size ); + PrintText( text, text + size ); } ImGui::PopFont(); } @@ -306,6 +306,24 @@ private: separate = false; } + static bool PrintText( const char* text, const char* end = nullptr ) + { + if( !end ) end = text + strlen( text ); + + // Replace narrow no-break space with no-break space + std::string buf( text, end ); + auto found = buf.find( "\xe2\x80\xaf" ); + while( found != std::string::npos ) + { + buf.replace( found, 3, "\xc2\xa0" ); + found = buf.find( "\xe2\x80\xaf", found ); + } + text = buf.c_str(); + end = text + buf.size(); + + return PrintTextWrapped( text, end ); + } + int bold = 0; int italic = 0; int header = 0;