Unravel Engine C++ Reference
Loading...
Searching...
No Matches
profiler_statistics_utils.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
6{
7
8namespace
9{
10constexpr float hover_color_multiplier = 0.1f;
11}
12
13auto draw_progress_bar(float width, float max_width, float height, const ImVec4& color) -> bool
14{
15 const ImGuiStyle& style = ImGui::GetStyle();
16
17 ImVec4 hovered_color(color.x + color.x * hover_color_multiplier,
18 color.y + color.y * hover_color_multiplier,
19 color.z + color.z * hover_color_multiplier,
20 color.w + color.w * hover_color_multiplier);
21
22 ImGui::PushStyleColor(ImGuiCol_Button, color);
23 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, hovered_color);
24 ImGui::PushStyleColor(ImGuiCol_ButtonActive, color);
25 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);
26 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, style.ItemSpacing.y));
27
28 bool item_hovered = false;
29
30 ImGui::Button("##bar_button", ImVec2(width, height));
31 item_hovered |= ImGui::IsItemHovered();
32
33 ImGui::SameLine();
34 ImGui::InvisibleButton("##bar_invisible", ImVec2(max_width - width + 1, height));
35 item_hovered |= ImGui::IsItemHovered();
36
37 ImGui::PopStyleVar(2);
38 ImGui::PopStyleColor(3);
39
40 return item_hovered;
41}
42
43auto draw_resource_bar(const char* name,
44 const char* tooltip,
45 uint32_t current_value,
46 uint32_t max_value,
47 float max_width,
48 float height) -> void
49{
50 bool item_hovered = false;
51 ImGui::PushID(name);
52
53 ImGui::AlignTextToFramePadding();
54 ImGui::Text("%s: %6d / %6d", name, current_value, max_value);
55 item_hovered |= ImGui::IsItemHovered();
56 ImGui::SameLine();
57
58 const float percentage = static_cast<float>(current_value) / static_cast<float>(max_value);
59 static const ImVec4 color(0.5f, 0.5f, 0.5f, 1.0f);
60 item_hovered |= draw_progress_bar(std::max(1.0f, percentage * max_width), max_width, height, color);
61 ImGui::SameLine();
62
63 ImGui::Text("%5.2f%%", static_cast<double>(percentage * 100.0f));
64
65 if(item_hovered)
66 {
67 ImGui::SetNextWindowViewportToCurrent();
68 ImGui::BeginTooltip();
69 ImGui::Text("%s %5.2f%%", tooltip, static_cast<double>(percentage * 100.0f));
70 ImGui::EndTooltip();
71 }
72
73 ImGui::PopID();
74}
75
76} // namespace unravel::profiler_statistics_utils
uint32_t width
uint32_t height
std::string name
Definition hub.cpp:33
const char * tooltip
auto draw_progress_bar(float width, float max_width, float height, const ImVec4 &color) -> bool
auto draw_resource_bar(const char *name, const char *tooltip, uint32_t current_value, uint32_t max_value, float max_width, float height) -> void
std::vector< math::color > color