#include "Popup.h" #include "../ManagementContext/StyleManagmentContext.h" #include "../ImGui.h" int Popup::count = 0; bool Popup::setActive(bool active) { if (active != this->active) { count += active ? 1 : -1; } return this->active = active; } Popup::Popup(std::vector options) { this->options = options; } Popup::~Popup() { } void Popup::OnRender() { if (!active) { return; } ImGui::SetNextWindowPos(this->position, 0, this->pivot); StyleManagmentContext::Push(POPUP); static int callDelay = 2; if (ImGui::Begin(("Popup##Popup" + std::to_string((long int)this)).c_str(), (bool*)NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) { callDelay++; if (callDelay == 2) { ImGui::SetWindowFocus(("Popup##Popup" + std::to_string((long int)this)).c_str()); } if (ImGui::IsWindowAppearing()) { callDelay = 0; } StyleManagmentContext::Push(POPUPINNER); if (ImGui::BeginChild("##MenuContent", ImVec2(200.0f, 0.0f), ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_Borders)) { for (size_t i = 0; i < options.size(); i++) { if (options[i] != options.front()) { ImGui::Separator(); } auto cursor = ImGui::GetCursorScreenPos(); ImGui::Selectable(("##" + options[i].label).c_str(), &options[i].selected, 0, ImVec2(200.0f, 32.0f)); cursor.x += 8.0f; cursor.y += 6.0f; ImGui::SetCursorScreenPos(cursor); if (options[i].icon.empty()) { ImGui::Text(options[i].label.c_str(), nullptr); } else { cursor.y -= 2.0f; ImGui::SetCursorScreenPos(cursor); ImGui::PushFont(DearImGuiApp::MaterialIcons, 24.0f); ImGui::Text(options[i].icon.c_str(), nullptr); ImGui::PopFont(); cursor.x += 28.0f; cursor.y += 2.0f; ImGui::SetCursorScreenPos(cursor); ImGui::Text(options[i].label.c_str(), nullptr); } cursor = ImGui::GetCursorScreenPos(); cursor.x += 0.0f; cursor.y += 6.0f; // ghetto ImGui::SetCursorScreenPos(cursor); /*if (selected) { //options[i].onSelect(); (void)selected; }*/ } ImGui::Dummy(ImVec2(0.0f, 0.0f)); ImGui::EndChild(); } StyleManagmentContext::Pop(); if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { setActive(false); } } ImGui::End(); StyleManagmentContext::Pop(); } void Popup::SetPosition(ImVec2 position, ImVec2 pivot) { this->position = position; this->pivot = pivot; } int Popup::CheckSelected() { for (size_t i = 0; i < options.size(); i++) { if (options[i].selected) { options[i].selected = false; setActive(false); return options[i].id; } } return -1; } int Popup::GetCount() { return count; } void Popup::Toggle() { setActive(!active); }