Unravel Engine C++ Reference
Loading...
Searching...
No Matches
footer_panel.cpp
Go to the documentation of this file.
1#include "footer_panel.h"
2#include "../panels_defs.h"
3
5
6#include <imgui/imgui.h>
7#include <imgui/imgui_internal.h>
9#include <imgui_widgets/tooltips.h>
10#include <imgui_widgets/utils.h>
11
12#include <logging/logging.h>
13
14namespace unravel
15{
16
17void footer_panel::draw_footer_child(rtti::context& ctx, float footer_size, const std::function<void()>& on_draw)
18{
19 ImGuiWindowFlags header_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
20 ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar |
21 ImGuiWindowFlags_NoDecoration;
22 const std::string child_id = "FOOTER_menubar";
23 ImGui::BeginChild(child_id.c_str(), ImVec2(0, 0), false, header_flags);
24 on_draw();
25
26
27 auto& thr = ctx.get_cached<threader>();
28 auto pool_jobs = thr.pool->get_jobs_count_detailed();
29
30
31 constexpr uint64_t notification_id = 99;
32 if(!pool_jobs.empty())
33 {
34 auto callback = [jobs = std::move(pool_jobs)](const ImGuiToast& toast, float opacity, const ImVec4& text_color)
35 {
36 size_t total_job_count = 0;
37 for(const auto& [name, count] : jobs)
38 {
39 total_job_count += count;
40 }
41
42
43 ImGui::AlignTextToFramePadding();
44
45 auto spinner_size = ImGui::GetTextLineHeight();
46
47 ImSpinner::Spinner<ImSpinner::SpinnerTypeT::e_st_eclipse>("spinner",
48 ImSpinner::Radius{spinner_size * 0.5f},
49 ImSpinner::Thickness{4.0f},
50 ImSpinner::Color{ImSpinner::white},
51 ImSpinner::Speed{6.0f});
52 ImGui::SameLine();
53
54 ImGui::TextColored(text_color, "%s", fmt::format("Jobs : {}", total_job_count).c_str());
55
56 for(const auto& [name, count] : jobs)
57 {
58 ImGui::TextColored(text_color, "%s", fmt::format("{} : {}", name, count).c_str());
59 }
60 };
61 ImGuiToast toast(ImGuiToastType_None, callback, 500);
62 ImGui::PushNotification(notification_id, toast);
63 last_notification_time_ = std::chrono::steady_clock::now();
64 }
65
66 if(last_notification_time_ != std::chrono::steady_clock::time_point::min())
67 {
68 if(last_notification_time_ + std::chrono::milliseconds(850) < std::chrono::steady_clock::now())
69 {
70 auto callback = [](const ImGuiToast& toast, float opacity, const ImVec4& text_color)
71 {
72 ImGui::TextColored(ImGuiToast::get_color(ImGuiToastType_Success), "%s", "Jobs Finished.");
73 };
74 ImGuiToast toast(ImGuiToastType_Info, callback, 2000);
75 ImGui::PushNotification(notification_id, toast);
76 last_notification_time_ = std::chrono::steady_clock::time_point::min();
77 }
78 }
79 ImGui::EndChild();
80}
81
82void footer_panel::on_frame_ui_render(rtti::context& ctx, float footer_size, const std::function<void()>& on_draw)
83{
84 ImGuiWindowFlags footer_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBringToFrontOnFocus |
85 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
86 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDecoration;
87 ImGuiViewport* viewport = ImGui::GetMainViewport();
88
89 ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x, viewport->WorkPos.y + viewport->WorkSize.y - footer_size));
90 ImGui::SetNextWindowSize(ImVec2(viewport->WorkSize.x, footer_size));
91 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyleColorVec4(ImGuiCol_MenuBarBg));
92 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
93 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
94
95 ImGui::SetNextWindowViewport(viewport->ID);
96 if(ImGui::Begin("FOOTER", nullptr, footer_flags))
97 {
98 // Draw a sep. child for the menu bar.
99 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_MenuBarBg));
100 draw_footer_child(ctx, footer_size, on_draw);
101
102 ImGui::PopStyleColor();
103 }
104
105 ImGui::End();
106
107 ImGui::PopStyleVar();
108 ImGui::PopStyleVar();
109 ImGui::PopStyleColor();
110}
111
112} // namespace unravel
NOTIFY_INLINE auto get_color() -> const ImVec4
void on_frame_ui_render(rtti::context &ctx, float footer_size, const std::function< void()> &on_draw={})
std::string name
Definition hub.cpp:27
@ ImGuiToastType_None
@ ImGuiToastType_Success
@ ImGuiToastType_Info
NOTIFY_INLINE void PushNotification(const ImGuiToast &toast)
Insert a new toast in the list.
auto get_cached() -> T &
Definition context.hpp:49