Source tooltip implementation.

This commit is contained in:
Bartosz Taudul 2021-03-27 13:25:21 +01:00
parent 0b6e55ee87
commit 8f0c5e867e
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 49 additions and 0 deletions

View File

@ -17801,4 +17801,50 @@ const char* View::SourceSubstitution( const char* srcFile ) const
return res.c_str();
}
void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before, int after, bool separateTooltip )
{
if( !SourceFileValid( filename, m_worker.GetCaptureTime(), *this, m_worker ) ) return;
m_srcHintCache.Parse( filename, m_worker, *this );
if( m_srcHintCache.empty() ) return;
if( separateTooltip ) ImGui::BeginTooltip();
if( m_fixedFont ) ImGui::PushFont( m_fixedFont );
auto& lines = m_srcHintCache.get();
const int start = std::max( 0, (int)srcline - ( before+1 ) );
const int end = std::min<int>( m_srcHintCache.get().size(), srcline + after );
for( int i=start; i<end; i++ )
{
auto& line = lines[i];
if( line.begin == line.end )
{
ImGui::TextUnformatted( "" );
}
else
{
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 );
}
TextColoredUnformatted( i == srcline-1 ? SyntaxColors[(int)it->color] : SyntaxColorsDimmed[(int)it->color], it->begin, it->end );
ImGui::SameLine( 0, 0 );
ptr = it->end;
++it;
}
ImGui::ItemSize( ImVec2( 0, 0 ), 0 );
}
}
if( m_fixedFont ) ImGui::PopFont();
if( separateTooltip ) ImGui::EndTooltip();
}
}

View File

@ -14,6 +14,7 @@
#include "TracyDecayValue.hpp"
#include "TracyImGui.hpp"
#include "TracyShortPtr.hpp"
#include "TracySourceContents.hpp"
#include "TracyTexture.hpp"
#include "TracyUserData.hpp"
#include "TracyVector.hpp"
@ -193,6 +194,7 @@ private:
void DrawSampleParents();
void DrawRanges();
void DrawRangeEntry( Range& range, const char* label, uint32_t color, const char* popupLabel, int id );
void DrawSourceTooltip( const char* filename, uint32_t line, int before = 3, int after = 3, bool separateTooltip = true );
void ListMemData( std::vector<const MemEvent*>& vec, std::function<void(const MemEvent*)> DrawAddress, const char* id = nullptr, int64_t startTime = -1, uint64_t pool = 0 );
@ -414,6 +416,7 @@ private:
Vector<const ZoneEvent*> m_zoneInfoStack;
Vector<const GpuEvent*> m_gpuInfoStack;
SourceContents m_srcHintCache;
std::unique_ptr<SourceView> m_sourceView;
const char* m_sourceViewFile;
bool m_uarchSet = false;