From 301298d6f72077958e07c9473907a95aa7610086 Mon Sep 17 00:00:00 2001 From: Antoine Mura Date: Mon, 21 Jul 2025 10:03:18 +0200 Subject: [PATCH 1/2] Fix clipboard button and add code preview in Zone Info --- profiler/src/profiler/TracyImGui.hpp | 9 ++++ profiler/src/profiler/TracyView_ZoneInfo.cpp | 45 ++++++-------------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/profiler/src/profiler/TracyImGui.hpp b/profiler/src/profiler/TracyImGui.hpp index c64f806a..f1940d70 100644 --- a/profiler/src/profiler/TracyImGui.hpp +++ b/profiler/src/profiler/TracyImGui.hpp @@ -240,6 +240,15 @@ static constexpr const uint32_t AsmSyntaxColors[] = { return res; } +[[maybe_unused]] static inline void TextFocusedClipboard( const char* label, const char* value, const char* clipboard, const int clipboardButtonId ) +{ + TextDisabledUnformatted( label ); + ImGui::SameLine(); + if( ClipboardButton( clipboardButtonId ) ) ImGui::SetClipboardText( value ); + ImGui::SameLine(); + ImGui::TextUnformatted( clipboard ); +} + [[maybe_unused]] static tracy_force_inline void DrawLine( ImDrawList* draw, const ImVec2& v1, const ImVec2& v2, uint32_t col, float thickness = 1.0f ) { const ImVec2 data[2] = { v1, v2 }; diff --git a/profiler/src/profiler/TracyView_ZoneInfo.cpp b/profiler/src/profiler/TracyView_ZoneInfo.cpp index 29f592a0..5826df8d 100644 --- a/profiler/src/profiler/TracyView_ZoneInfo.cpp +++ b/profiler/src/profiler/TracyView_ZoneInfo.cpp @@ -410,31 +410,26 @@ void View::DrawZoneInfoWindow() else if( srcloc.name.active ) { ImGui::PushFont( g_fonts.normal, FontBig ); - TextFocused( "Zone name:", m_worker.GetString( srcloc.name ) ); + TextFocusedClipboard( "Zone name:", m_worker.GetString( srcloc.name ), m_worker.GetString( srcloc.name ), 1 ); ImGui::PopFont(); - ImGui::SameLine(); - if( ClipboardButton( 1 ) ) ImGui::SetClipboardText( m_worker.GetString( srcloc.name ) ); - TextFocused( "Function:", m_worker.GetString( srcloc.function ) ); - ImGui::SameLine(); - if( ClipboardButton( 2 ) ) ImGui::SetClipboardText( m_worker.GetString( srcloc.function ) ); + TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 2 ); } else { ImGui::PushFont( g_fonts.normal, FontBig ); - TextFocused( "Function:", m_worker.GetString( srcloc.function ) ); + TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 1 ); ImGui::PopFont(); - ImGui::SameLine(); - if( ClipboardButton( 1 ) ) ImGui::SetClipboardText( m_worker.GetString( srcloc.function ) ); } SmallColorBox( GetSrcLocColor( m_worker.GetSourceLocation( ev.SrcLoc() ), 0 ) ); ImGui::SameLine(); - TextDisabledUnformatted( "Location:" ); - ImGui::SameLine(); - ImGui::TextUnformatted( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) ); - ImGui::SameLine(); - if( ClipboardButton( 3 ) ) + TextFocusedClipboard( "Location:", LocationToString( fileName, srcloc.line ), LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ), 3 ); + if( ImGui::IsItemHovered() ) { - ImGui::SetClipboardText( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) ); + DrawSourceTooltip( fileName, srcloc.line ); + if( ImGui::IsItemClicked( ImGuiMouseButton_Right ) && SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) ) + { + ViewSourceCheckKeyMod( fileName, srcloc.line, m_worker.GetString( srcloc.function ) ); + } } SmallColorBox( GetThreadColor( tid, 0 ) ); ImGui::SameLine(); @@ -1514,23 +1509,11 @@ void View::DrawGpuInfoWindow() const auto tid = GetZoneThread( ev ); ImGui::PushFont( g_fonts.normal, FontBig ); - TextFocused( "Zone name:", m_worker.GetString( srcloc.name ) ); + TextFocusedClipboard( "Zone name:", m_worker.GetString( srcloc.name ), m_worker.GetString( srcloc.name ), 1 ); + ImGui::SameLine(); ImGui::PopFont(); - ImGui::SameLine(); - if( ClipboardButton( 1 ) ) ImGui::SetClipboardText( m_worker.GetString( srcloc.name ) ); - TextFocused( "Function:", m_worker.GetString( srcloc.function ) ); - ImGui::SameLine(); - if( ClipboardButton( 2 ) ) ImGui::SetClipboardText( m_worker.GetString( srcloc.function ) ); - SmallColorBox( GetZoneColor( ev ) ); - ImGui::SameLine(); - TextDisabledUnformatted( "Location:" ); - ImGui::SameLine(); - ImGui::TextUnformatted( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) ); - ImGui::SameLine(); - if( ClipboardButton( 3 ) ) - { - ImGui::SetClipboardText( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) ); - } + TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 2 ); + TextFocusedClipboard( "Location:", LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ), LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ), 3 ); SmallColorBox( GetThreadColor( tid, 0 ) ); ImGui::SameLine(); TextFocused( "Thread:", m_worker.GetThreadName( tid ) ); From effb5fbed5ac3362f5c96067961f99cd6dca919f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gr=C3=A9goire?= Date: Thu, 31 Jul 2025 00:20:56 +0200 Subject: [PATCH 2/2] Allow to chhange clipboard button font + center-align based on previous font --- profiler/src/profiler/TracyImGui.hpp | 13 ++++++++++++- profiler/src/profiler/TracyView_ZoneInfo.cpp | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/profiler/src/profiler/TracyImGui.hpp b/profiler/src/profiler/TracyImGui.hpp index f1940d70..731a80d1 100644 --- a/profiler/src/profiler/TracyImGui.hpp +++ b/profiler/src/profiler/TracyImGui.hpp @@ -240,11 +240,22 @@ static constexpr const uint32_t AsmSyntaxColors[] = { return res; } -[[maybe_unused]] static inline void TextFocusedClipboard( const char* label, const char* value, const char* clipboard, const int clipboardButtonId ) +[[maybe_unused]] static inline void TextFocusedClipboard( const char* label, const char* value, const char* clipboard, const int clipboardButtonId, ImFont* font = nullptr, float fontSizeBase = 0.f ) { TextDisabledUnformatted( label ); ImGui::SameLine(); + // Due to the font size change, we need to realign the button vertically by hand + // We center-align it based on the previous font. + // This is apparently the recommended (only) way to do it: https://github.com/ocornut/imgui/issues/1284 + ImVec2 cursorPos = ImGui::GetCursorPos(); + const float previousFontSize = ImGui::GetFontSize(); + ImGui::PushFont( font, fontSizeBase ); + const float buttonFontSize = ImGui::GetFontSize(); + cursorPos.y += ( previousFontSize - buttonFontSize ) / 2.f; + ImGui::SetCursorPos( cursorPos ); if( ClipboardButton( clipboardButtonId ) ) ImGui::SetClipboardText( value ); + ImGui::PopFont(); + ImGui::SameLine(); ImGui::TextUnformatted( clipboard ); } diff --git a/profiler/src/profiler/TracyView_ZoneInfo.cpp b/profiler/src/profiler/TracyView_ZoneInfo.cpp index 5826df8d..f1b6d3fb 100644 --- a/profiler/src/profiler/TracyView_ZoneInfo.cpp +++ b/profiler/src/profiler/TracyView_ZoneInfo.cpp @@ -410,14 +410,14 @@ void View::DrawZoneInfoWindow() else if( srcloc.name.active ) { ImGui::PushFont( g_fonts.normal, FontBig ); - TextFocusedClipboard( "Zone name:", m_worker.GetString( srcloc.name ), m_worker.GetString( srcloc.name ), 1 ); + TextFocusedClipboard( "Zone name:", m_worker.GetString( srcloc.name ), m_worker.GetString( srcloc.name ), 1, g_fonts.normal, FontNormal ); ImGui::PopFont(); TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 2 ); } else { ImGui::PushFont( g_fonts.normal, FontBig ); - TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 1 ); + TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 1, g_fonts.normal, FontNormal ); ImGui::PopFont(); } SmallColorBox( GetSrcLocColor( m_worker.GetSourceLocation( ev.SrcLoc() ), 0 ) ); @@ -1509,7 +1509,7 @@ void View::DrawGpuInfoWindow() const auto tid = GetZoneThread( ev ); ImGui::PushFont( g_fonts.normal, FontBig ); - TextFocusedClipboard( "Zone name:", m_worker.GetString( srcloc.name ), m_worker.GetString( srcloc.name ), 1 ); + TextFocusedClipboard( "Zone name:", m_worker.GetString( srcloc.name ), m_worker.GetString( srcloc.name ), 1, g_fonts.normal, FontNormal ); ImGui::SameLine(); ImGui::PopFont(); TextFocusedClipboard( "Function:", m_worker.GetString( srcloc.function ), m_worker.GetString( srcloc.function ), 2 );