| 586 | } |
| 587 | |
| 588 | void Shutdown(const sf::Window& window) |
| 589 | { |
| 590 | const bool needReplacement = (s_currWindowCtx->window->getNativeHandle() == window.getNativeHandle()); |
| 591 | |
| 592 | // remove window's context |
| 593 | auto found = std::find_if(s_windowContexts.begin(), |
| 594 | s_windowContexts.end(), |
| 595 | [&](std::unique_ptr<WindowContext>& ctx) |
| 596 | { return ctx->window->getNativeHandle() == window.getNativeHandle(); }); |
| 597 | assert(found != s_windowContexts.end() && |
| 598 | "Window wasn't inited properly: forgot to call ImGui::SFML::Init(window)?"); |
| 599 | s_windowContexts.erase(found); // s_currWindowCtx can become invalid here! |
| 600 | |
| 601 | // set current context to some window for convenience if needed |
| 602 | if (needReplacement) |
| 603 | { |
| 604 | auto it = s_windowContexts.begin(); |
| 605 | if (it != s_windowContexts.end()) |
| 606 | { |
| 607 | // set to some other window |
| 608 | s_currWindowCtx = it->get(); |
| 609 | ImGui::SetCurrentContext(s_currWindowCtx->imContext); |
| 610 | } |
| 611 | else |
| 612 | { |
| 613 | // no alternatives... |
| 614 | s_currWindowCtx = nullptr; |
| 615 | ImGui::SetCurrentContext(nullptr); |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | void Shutdown() |
| 621 | { |