SpiecsEngine
 
Loading...
Searching...
No Matches
ImguiInfoBar.cpp
Go to the documentation of this file.
1/**
2* @file ImguiOperation.cpp.
3* @brief The ImguiOperation Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "ImguiInfoBar.h"
9#include "World/World/World.h"
10#include "Slate/SlateInfoBar.h"
11
12namespace Spices {
13
15 {
17
18 /**
19 * @brief Clear slected infobar.
20 */
21 if (m_SelectedInfoBar)
22 {
23 if (m_SelectedInfoBar->IsDestroy())
24 {
25 m_SelectedInfoBar = nullptr;
26 }
27 }
28
29 std::vector<std::string> eraseList;
30
31 m_InfoBars.for_each([&](auto& k, auto& v) {
32
33 if (v->IsDestroy())
34 {
35 eraseList.push_back(v->GetInfo());
36 }
37
38 return false;
39 });
40
41 /**
42 * @brief Erase completed InfoBar.
43 */
44 for (auto& item : eraseList)
45 {
46 m_InfoBars.erase(item);
47 }
48 }
49
51 {
53
54 /**
55 * @brief Begin render ContentBrowser.
56 */
57 Begin(m_PanelName, 1.0f, ImGuiWindowFlags_NoTitleBar);
58
59 {
60 SPICES_PROFILE_ZONEN("ImguiInfoBar");
61
62 float width = ImGui::GetContentRegionAvail().x;
63 ImGui::Spacing();
64
65 /**
66 * @brief Skip if no InfoBar Instance.
67 */
68 if (m_InfoBars.size() == 0)
69 {
70 End();
71 return;
72 }
73
74 ImGui::PushID("ImguiInfoBar");
75
76 auto item = m_SelectedInfoBar ? m_SelectedInfoBar : *m_InfoBars.first();
77
78 ImGui::Columns(3, 0);
79
80 ImGui::SetColumnWidth(0, 0.5f * width);
81 ImGui::NextColumn();
82
83 ImGui::SetColumnWidth(1, 0.39f * width);
84 ImGui::Text(item->GetInfo().c_str());
85 ImGui::NextColumn();
86
87 switch (item->GetType())
88 {
89 case SlateInfoBar::Type::progress:
90 {
91 float rate = std::any_cast<float>(item->GetRate());
92 ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(0.310f, 0.49f, 0.627f, 1.0f));
93 ImGui::ProgressBar(rate);
94 ImGui::PopStyleColor();
95 break;
96 }
97 case SlateInfoBar::Type::count:
98 {
99 int count = std::any_cast<int>(item->GetRate());
100 std::stringstream ss;
101 ss << count;
102
103 ImGui::Text(ss.str().c_str());
104 break;
105 }
106 }
107
108 ImGui::Columns(1);
109
110 ImGui::PopID();
111 }
112
113 {
114 SPICES_PROFILE_ZONEN("ImguiInfoBar::DisplayList");
115
116 if (ImGui::BeginPopupContextWindow(0, 1))
117 {
118 m_InfoBars.for_each([&](auto& k, auto& v) {
119
120 if (ImGui::MenuItem(k.c_str()))
121 {
122 m_SelectedInfoBar = v;
123 }
124 return false;
125
126 });
127
128 ImGui::EndPopup();
129 }
130 }
131
132 /**
133 * @brief End render ContentBrowser.
134 */
135 End();
136 }
137
138 void ImguiInfoBar::Push(std::shared_ptr<SlateInfoBar> instance)
139 {
141
142 m_InfoBars.push_back(instance->GetInfo(), instance);
143 }
144}
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
void Push(std::shared_ptr< SlateInfoBar > instance)
Add a InfoBar instance to this.
virtual void OnRender() override
This interface is called On SlateRenderer Render.
virtual void OnUpdate(TimeStep &ts) override
This interface is called On SlateSystem Update.
The ImguiInfoBar Class. This class defines how to render a Operation Panel.
void End()
End a slate.
This Class defines InfoBar instance.
This Class handles our engine time step during frames. Global Unique.
Definition TimeStep.h:22