diff options
author | Marek Olšák <[email protected]> | 2016-08-18 17:21:54 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2016-08-22 16:01:35 +0200 |
commit | a33eb48d6111cb679a5ce8b35c5d7e4854f0045d (patch) | |
tree | d46d1863e2f87e5483c04700f55441082c7f88fc /src/gallium/auxiliary/hud | |
parent | b9c9551c09caac241ea44b618748c133897d59b9 (diff) |
gallium/hud: draw numbers with 3 decimal places if those aren't 0
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/hud')
-rw-r--r-- | src/gallium/auxiliary/hud/hud_context.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c index 8ab998ed9ac..f7baccd760c 100644 --- a/src/gallium/auxiliary/hud/hud_context.c +++ b/src/gallium/auxiliary/hud/hud_context.c @@ -296,12 +296,19 @@ number_to_human_readable(uint64_t num, uint64_t max_value, unit++; } - if (d >= 100 || d == (int)d) + /* Round to 3 decimal places so as not to print trailing zeros. */ + if (d*1000 != (int)(d*1000)) + d = round(d * 1000) / 1000; + + /* Show at least 4 digits with at most 3 decimal places, but not zeros. */ + if (d >= 1000 || d == (int)d) sprintf(out, "%.0f%s", d, units[unit]); - else if (d >= 10 || d*10 == (int)(d*10)) + else if (d >= 100 || d*10 == (int)(d*10)) sprintf(out, "%.1f%s", d, units[unit]); - else + else if (d >= 10 || d*100 == (int)(d*100)) sprintf(out, "%.2f%s", d, units[unit]); + else + sprintf(out, "%.3f%s", d, units[unit]); } static void @@ -536,7 +543,7 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex) /* prepare vertex buffers */ hud_alloc_vertices(hud, &hud->bg, 4 * 128, 2 * sizeof(float)); hud_alloc_vertices(hud, &hud->whitelines, 4 * 256, 2 * sizeof(float)); - hud_alloc_vertices(hud, &hud->text, 4 * 512, 4 * sizeof(float)); + hud_alloc_vertices(hud, &hud->text, 4 * 1024, 4 * sizeof(float)); /* prepare all graphs */ hud_batch_query_update(hud->batch_query); @@ -1026,7 +1033,7 @@ hud_parse_env_var(struct hud_context *hud, const char *env) case ';': env++; y = 10; - x += column_width + hud->font.glyph_width * 7; + x += column_width + hud->font.glyph_width * 9; height = 100; if (pane && pane->num_graphs) { |