From 86c2574848845f451a88c160895ff9657bd0f921 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 14 Aug 2022 14:16:56 +0200 Subject: [PATCH] Fix printing floats in source view. --- server/TracySourceView.cpp | 42 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 53a952d8..31091a28 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -4241,19 +4241,17 @@ void SourceView::RenderHwLinePart( size_t cycles, size_t retired, size_t branchR else { char buf[16]; - if( rate >= 0.1f ) + const auto end = PrintFloat( buf, buf+16, rate * 100, 1 ); + memcpy( end, "% ", 3 ); + if( end - buf == 4 ) { - const auto end = PrintFloat( buf, buf+16, rate * 100, 1 ); - assert( end == buf+4 ); + TextColoredUnformatted( col, buf ); } else { - *buf = ' '; - const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 ); - assert( end == buf+4 ); + ImGui::SameLine( 0, ts.x ); + TextColoredUnformatted( col, buf ); } - memcpy( buf+4, "% ", 3 ); - TextColoredUnformatted( col, buf ); } if( ImGui::IsItemHovered() ) { @@ -4334,19 +4332,17 @@ void SourceView::RenderHwLinePart( size_t cycles, size_t retired, size_t branchR else { char buf[16]; - if( rate >= 0.1f ) + const auto end = PrintFloat( buf, buf+16, rate * 100, 1 ); + memcpy( end, "% ", 3 ); + if( end - buf == 4 ) { - const auto end = PrintFloat( buf, buf+16, rate * 100, 1 ); - assert( end == buf+4 ); + TextColoredUnformatted( col, buf ); } else { - *buf = ' '; - const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 ); - assert( end == buf+4 ); + ImGui::SameLine( 0, ts.x ); + TextColoredUnformatted( col, buf ); } - memcpy( buf+4, "% ", 3 ); - TextColoredUnformatted( col, buf ); } if( ImGui::IsItemHovered() ) { @@ -4384,19 +4380,17 @@ void SourceView::RenderHwLinePart( size_t cycles, size_t retired, size_t branchR else { char buf[16]; - if( rate >= 0.1f ) + const auto end = PrintFloat( buf, buf+16, rate * 100, 1 ); + memcpy( end, "%", 2 ); + if( end - buf == 4 ) { - const auto end = PrintFloat( buf, buf+16, rate * 100, 1 ); - assert( end == buf+4 ); + TextColoredUnformatted( col, buf ); } else { - *buf = ' '; - const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 ); - assert( end == buf+4 ); + ImGui::SameLine( 0, ts.x ); + TextColoredUnformatted( col, buf ); } - memcpy( buf+4, "%", 2 ); - TextColoredUnformatted( col, buf ); } if( ImGui::IsItemHovered() ) {