#include "Panel.h" #include "../ManagementContext/StyleManagmentContext.h" #include "../ImGui.h" #include "MaterialIcons.h" #include "../ManagementContext/PanelManagementContext.h" #include bool Panel::beginCustomWindow(std::string title) { if (state == DETACHED && PanelManagementContext::GetMode() != DEFAULT) { return false; } if (!ImGui::Begin(title.c_str(), (bool*)&state, ImGuiWindowFlags_NoTitleBar | (state == DETACHED ? 0 : ImGuiWindowFlags_NoResize))) { ImGui::End(); return false; } isWindowActive = ImGui::IsItemActive(); ImGui::Text(title.c_str(), nullptr); ImGui::SameLine(); ImGui::PushFont(DearImGuiApp::MaterialIcons, 24.0f); StyleManagmentContext::Push(NOBORDER); ImVec2 cursor = ImGui::GetCursorScreenPos(); ImVec2 avail = ImGui::GetContentRegionAvail(); cursor.x += avail.x - 72.0f; cursor.y -= 2.0f; ImGui::SetCursorScreenPos(cursor); if (state == OPEN) { if (ImGui::SmallButton(ICON_MS_OPEN_IN_NEW)) { state = DETACHED; PanelManagementContext::PopMode(); } ImGui::SameLine(); // Detach } else { if (ImGui::SmallButton(ICON_MS_REOPEN_WINDOW)) { state = OPEN; PanelManagementContext::PushMode(CONFIGURE); } ImGui::SameLine(); // Reattach } cursor.x += 36.0f; ImGui::SetCursorScreenPos(cursor); if (ImGui::SmallButton(ICON_MS_CLOSE)) { PanelManagementContext::Close(this); } cursor = ImGui::GetCursorScreenPos(); cursor.y -= 2.0f; ImGui::SetCursorScreenPos(cursor); StyleManagmentContext::Pop(); ImGui::PopFont(); StyleManagmentContext::Push(BASECONTENTS); ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail(), ImGuiCond_None); if (!ImGui::BeginChild((title + "Contents").c_str(), ImVec2(0, 0), ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_Borders | ImGuiChildFlags_NavFlattened)) { ImGui::EndChild(); StyleManagmentContext::Pop(); return false; } return true; } void Panel::endCustomWindow() { if (state == OPEN && ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { PanelManagementContext::Close(this); } if (state == OPEN && ImGui::IsMouseDragging(ImGuiMouseButton_Left) && isWindowActive && ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { state = DETACHED; PanelManagementContext::PopMode(); } ImGui::EndChild(); StyleManagmentContext::Pop(); ImGui::End(); } void Panel::Toggle() { switch (state) { case CLOSED: state = OPEN; break; default: case OPEN: state = CLOSED; break; } } PanelState Panel::GetState() { return state; }