Common percentage printing function.

This commit is contained in:
Bartosz Taudul 2020-03-30 22:26:45 +02:00
parent 11aedf2b27
commit c1ed44bd35

View File

@ -396,6 +396,19 @@ void SourceView::Render( const Worker& worker )
} }
} }
static void PrintPercentage( float val )
{
char tmp[16];
auto end = PrintFloat( tmp, tmp+16, val, 2 );
memcpy( end, "%", 2 );
end++;
const auto sz = end - tmp;
char buf[16];
memset( buf, ' ', 7-sz );
memcpy( buf + 7 - sz, tmp, sz+1 );
ImGui::TextUnformatted( buf );
}
void SourceView::RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal ) void SourceView::RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal )
{ {
const auto ty = ImGui::GetFontSize(); const auto ty = ImGui::GetFontSize();
@ -415,15 +428,7 @@ void SourceView::RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint
} }
else else
{ {
char tmp[16]; PrintPercentage( 100.f * ipcnt / iptotal );
auto end = PrintFloat( tmp, tmp+16, 100.f * ipcnt / iptotal, 2 );
memcpy( end, "%", 2 );
end++;
const auto sz = end - tmp;
char buf[16];
memset( buf, ' ', 7-sz );
memcpy( buf + 7 - sz, tmp, sz+1 );
ImGui::TextUnformatted( buf );
} }
ImGui::SameLine( 0, ty ); ImGui::SameLine( 0, ty );
} }
@ -463,15 +468,7 @@ void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t ip
} }
else else
{ {
char tmp[16]; PrintPercentage( 100.f * ipcnt / iptotal );
auto end = PrintFloat( tmp, tmp+16, 100.f * ipcnt / iptotal, 2 );
memcpy( end, "%", 2 );
end++;
const auto sz = end - tmp;
char buf[16];
memset( buf, ' ', 7-sz );
memcpy( buf + 7 - sz, tmp, sz+1 );
ImGui::TextUnformatted( buf );
} }
ImGui::SameLine( 0, ty ); ImGui::SameLine( 0, ty );
} }