diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 7fd57439..68a5cdbf 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -124,11 +124,11 @@ public: Range m_waitStackRange; private: - enum class Namespace : uint8_t + enum class ShortenName : uint8_t { - Full, - Mid, - Short + Never, + Always, + WhenNoSpace }; enum class ShortcutAction : uint8_t @@ -177,7 +177,7 @@ private: void InitMemory(); void InitTextEditor( ImFont* font ); - const char* ShortenNamespace( const char* name ) const; + const char* ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const; bool DrawImpl(); void DrawNotificationArea(); @@ -483,7 +483,7 @@ private: bool m_groupWaitStackTopDown = true; ShortcutAction m_shortcut = ShortcutAction::None; - Namespace m_namespace = Namespace::Short; + ShortenName m_shortenName = ShortenName::WhenNoSpace; Animation m_zoomAnim; BuzzAnim m_callstackBuzzAnim; BuzzAnim m_sampleParentBuzzAnim; diff --git a/server/TracyView_Options.cpp b/server/TracyView_Options.cpp index 34159e23..c264c6e7 100644 --- a/server/TracyView_Options.cpp +++ b/server/TracyView_Options.cpp @@ -221,16 +221,16 @@ void View::DrawOptions() ImGui::PopStyleVar(); ImGui::Unindent(); m_vd.dynamicColors = ival; - ival = (int)m_namespace; - ImGui::TextUnformatted( ICON_FA_BOX_OPEN " Namespaces" ); + ival = (int)m_shortenName; + ImGui::TextUnformatted( ICON_FA_RULER_HORIZONTAL " Zone name shortening" ); ImGui::Indent(); ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); - ImGui::RadioButton( "Full", &ival, 0 ); - ImGui::RadioButton( "Shortened", &ival, 1 ); - ImGui::RadioButton( "None", &ival, 2 ); + ImGui::RadioButton( "Never", &ival, 0 ); + ImGui::RadioButton( "Always", &ival, 1 ); + ImGui::RadioButton( "When no space", &ival, 2 ); ImGui::PopStyleVar(); ImGui::Unindent(); - m_namespace = (Namespace)ival; + m_shortenName = (ShortenName)ival; ImGui::Unindent(); if( !m_worker.GetLockMap().empty() ) diff --git a/server/TracyView_Utility.cpp b/server/TracyView_Utility.cpp index f9f7345b..2613f69c 100644 --- a/server/TracyView_Utility.cpp +++ b/server/TracyView_Utility.cpp @@ -826,34 +826,60 @@ const char* View::GetFrameSetName( const FrameData& fd, const Worker& worker ) } } -const char* View::ShortenNamespace( const char* name ) const +const char* View::ShortenZoneName( const char* name, ImVec2& tsz, float zsz ) const { - if( m_namespace == Namespace::Full ) return name; - if( m_namespace == Namespace::Short ) - { - auto ptr = name; - while( *ptr != '\0' ) ptr++; - while( ptr > name && *ptr != ':' ) ptr--; - if( *ptr == ':' ) ptr++; - return ptr; - } + assert( m_shortenName != ShortenName::Never ); + if( m_shortenName == ShortenName::Always ) zsz = 0; + + static char buf[64*1024]; + char tmp[64*1024]; - static char buf[1024]; - auto dst = buf; auto ptr = name; + auto dst = tmp; + int cnt = 0; for(;;) { auto start = ptr; - while( *ptr != '\0' && *ptr != ':' ) ptr++; - if( *ptr == '\0' ) + while( *ptr && *ptr != '<' ) ptr++; + memcpy( dst, start, ptr - start + 1 ); + if( !*ptr ) break; + dst += ptr - start + 1; + cnt++; + ptr++; + while( cnt > 0 ) { - memcpy( dst, start, ptr - start + 1 ); - return buf; + if( !*ptr ) break; + if( *ptr == '<' ) cnt++; + else if( *ptr == '>' ) cnt--; + ptr++; } - *dst++ = *start; - *dst++ = ':'; - while( *ptr == ':' ) ptr++; + *dst++ = '>'; } + + ptr = tmp; + dst = buf; + cnt = 0; + for(;;) + { + auto start = ptr; + while( *ptr && *ptr != '(' ) ptr++; + memcpy( dst, start, ptr - start + 1 ); + if( !*ptr ) break; + dst += ptr - start + 1; + cnt++; + ptr++; + while( cnt > 0 ) + { + if( !*ptr ) break; + if( *ptr == '(' ) cnt++; + else if( *ptr == ')' ) cnt--; + ptr++; + } + *dst++ = ')'; + } + + tsz = ImGui::CalcTextSize( buf ); + return buf; } const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program ) diff --git a/server/TracyView_ZoneTimeline.cpp b/server/TracyView_ZoneTimeline.cpp index c11bad9a..73f1b310 100644 --- a/server/TracyView_ZoneTimeline.cpp +++ b/server/TracyView_ZoneTimeline.cpp @@ -217,10 +217,9 @@ int View::DrawGhostLevel( const Vector& vec, bool hover, double pxns, DrawLine( draw, dpos + ImVec2( px0, offset + tsz.y ), dpos + ImVec2( px1-1, offset + tsz.y ), dpos + ImVec2( px1-1, offset ), darkColor, 1.f ); auto origSymName = symName; - if( tsz.x > zsz ) + if( m_shortenName == ShortenName::Always || ( m_shortenName == ShortenName::WhenNoSpace && tsz.x > zsz ) ) { - symName = ShortenNamespace( symName ); - tsz = ImGui::CalcTextSize( symName ); + symName = ShortenZoneName( symName, tsz, zsz ); } if( tsz.x < zsz ) @@ -511,10 +510,9 @@ int View::DrawZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, co } auto tsz = ImGui::CalcTextSize( zoneName ); - if( tsz.x > zsz ) + if( m_shortenName == ShortenName::Always || ( m_shortenName == ShortenName::WhenNoSpace && tsz.x > zsz ) ) { - zoneName = ShortenNamespace( zoneName ); - tsz = ImGui::CalcTextSize( zoneName ); + zoneName = ShortenZoneName( zoneName, tsz, zsz ); } const auto pr0 = ( ev.Start() - m_vd.zvStart ) * pxns;