diff options
author | Diego Gangl <dnicolas@gmail.com> | 2018-05-25 23:17:15 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2018-05-25 23:41:49 +0300 |
commit | 4dee702332abee23086dc0d26e79f014a27a3bb3 (patch) | |
tree | 62b8ee59ec03fe8585edd0bf47eeec2fa306a914 /source/blender/editors | |
parent | 9dca74f0e5f44463f82a46f417a12cf970b51179 (diff) |
Add number and memory size formatting throughout the UI
This commit adds number formatting (thousands separator) to the baking panel. It also adds a new function to format memory sizes (KB/GB/etc) and applies it to the baking panel and scene stats. The new function is unit tested.
Reviewers: Severin
Tags: #user_interface
Differential Revision: https://developer.blender.org/D1248
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_info/info_stats.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 8dc6c4229b2..10b5eded8d4 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -384,6 +384,7 @@ static void stats_string(Scene *scene) uintptr_t mem_in_use, mmap_in_use; char memstr[MAX_INFO_MEM_LEN]; char gpumemstr[MAX_INFO_MEM_LEN] = ""; + char formatted_mem[15]; char *s; size_t ofs = 0; @@ -419,20 +420,25 @@ static void stats_string(Scene *scene) /* get memory statistics */ - ofs = BLI_snprintf(memstr, MAX_INFO_MEM_LEN, IFACE_(" | Mem:%.2fM"), - (double)((mem_in_use - mmap_in_use) >> 10) / 1024.0); - if (mmap_in_use) - BLI_snprintf(memstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%.2fM)"), (double)((mmap_in_use) >> 10) / 1024.0); + BLI_str_format_byte_unit(formatted_mem, mem_in_use - mmap_in_use, true); + ofs = BLI_snprintf(memstr, MAX_INFO_MEM_LEN, IFACE_(" | Mem: %s"), formatted_mem); + + if (mmap_in_use) { + BLI_str_format_byte_unit(formatted_mem, mmap_in_use, true); + BLI_snprintf(memstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%s)"), formatted_mem); + } if (GPU_mem_stats_supported()) { int gpu_free_mem, gpu_tot_memory; GPU_mem_stats_get(&gpu_tot_memory, &gpu_free_mem); - ofs = BLI_snprintf(gpumemstr, MAX_INFO_MEM_LEN, IFACE_(" | Free GPU Mem:%.2fM"), (double)((gpu_free_mem)) / 1024.0); + BLI_str_format_byte_unit(formatted_mem, gpu_free_mem, true); + ofs = BLI_snprintf(gpumemstr, MAX_INFO_MEM_LEN, IFACE_(" | Free GPU Mem: %s"), formatted_mem); if (gpu_tot_memory) { - BLI_snprintf(gpumemstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_("/%.2fM"), (double)((gpu_tot_memory)) / 1024.0); + BLI_str_format_byte_unit(formatted_mem, gpu_tot_memory, true); + BLI_snprintf(gpumemstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_("/%s"), formatted_mem); } } |