Extract normalized name tooltip function.

This commit is contained in:
Bartosz Taudul 2022-08-15 19:43:03 +02:00
parent 63d074c5d8
commit 4d0591cf2f
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 22 additions and 15 deletions

View File

@ -117,4 +117,24 @@ const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, fl
} }
} }
void TooltipNormalizedName( const char* name, const char* normalized )
{
if( ImGui::IsItemHovered() && normalized != name && strcmp( normalized, name ) != 0 )
{
const auto scale = ImGui::GetTextLineHeight() / 15.f;
if( ImGui::CalcTextSize( name ).x > 1400 * scale )
{
ImGui::SetNextWindowSize( ImVec2( 1400 * scale, 0 ) );
ImGui::BeginTooltip();
ImGui::TextWrapped( "%s", name );
}
else
{
ImGui::BeginTooltip();
ImGui::TextUnformatted( name );
}
ImGui::EndTooltip();
}
}
} }

View File

@ -18,6 +18,7 @@ enum class ShortenName : uint8_t
}; };
const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, float zsz ); const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, float zsz );
void TooltipNormalizedName( const char* name, const char* normalized );
static inline const char* ShortenZoneName( ShortenName type, const char* name ) { ImVec2 tsz = {}; return ShortenZoneName( type, name, tsz, 0 ); } static inline const char* ShortenZoneName( ShortenName type, const char* name ) { ImVec2 tsz = {}; return ShortenZoneName( type, name, tsz, 0 ); }

View File

@ -216,21 +216,7 @@ void View::DrawCallstackTable( uint32_t callstack, bool globalEntriesButton )
{ {
const auto normalized = ShortenZoneName( ShortenName::OnlyNormalize, txt ); const auto normalized = ShortenZoneName( ShortenName::OnlyNormalize, txt );
ImGui::TextUnformatted( normalized ); ImGui::TextUnformatted( normalized );
if( ImGui::IsItemHovered() && normalized != txt && strcmp( normalized, txt ) != 0 ) TooltipNormalizedName( txt, normalized );
{
if( ImGui::CalcTextSize( txt ).x > 1400 * GetScale() )
{
ImGui::SetNextWindowSize( ImVec2( 1400 * GetScale(), 0 ) );
ImGui::BeginTooltip();
ImGui::TextWrapped( "%s", txt );
}
else
{
ImGui::BeginTooltip();
ImGui::TextUnformatted( txt );
}
ImGui::EndTooltip();
}
} }
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();
} }