mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-25 04:28:22 +00:00
Merge pull request #1116 from siliceum/bugfix/clipboard-button
Fix clipboard button and add code preview in Zone Info
This commit is contained in:
@@ -240,6 +240,26 @@ 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, 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 );
|
||||
}
|
||||
|
||||
[[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 };
|
||||
|
||||
@@ -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, g_fonts.normal, FontNormal );
|
||||
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, g_fonts.normal, FontNormal );
|
||||
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, g_fonts.normal, FontNormal );
|
||||
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 ) );
|
||||
|
||||
Reference in New Issue
Block a user