88#include < thread>
99
1010#include " imgui.h"
11+ #include " implot.h"
1112
1213#include " polyscope/options.h"
1314#include " polyscope/pick.h"
@@ -33,6 +34,7 @@ namespace {
3334// initialization.
3435struct ContextEntry {
3536 ImGuiContext* context;
37+ ImPlotContext* plotContext;
3638 std ::function<void ()> callback;
3739 bool drawDefaultUI;
3840};
@@ -183,7 +185,7 @@ void init(std::string backend) {
183185
184186 // Create an initial context based context. Note that calling show() never actually uses this context, because it
185187 // pushes a new one each time. But using frameTick() may use this context.
186- contextStack.push_back (ContextEntry{ImGui::GetCurrentContext (), nullptr , true });
188+ contextStack.push_back (ContextEntry{ImGui::GetCurrentContext (), ImPlot::GetCurrentContext (), nullptr , true });
187189
188190 view::invalidateView ();
189191
@@ -205,11 +207,13 @@ void pushContext(std::function<void()> callbackFunction, bool drawDefaultUI) {
205207
206208 // Create a new context and push it on to the stack
207209 ImGuiContext* newContext = ImGui::CreateContext ();
210+ ImPlotContext* newPlotContext = ImPlot::CreateContext ();
208211 ImGuiIO& oldIO = ImGui::GetIO (); // used to GLFW + OpenGL data to the new IO object
209212#ifdef IMGUI_HAS_DOCK
210213 ImGuiPlatformIO& oldPlatformIO = ImGui::GetPlatformIO ();
211214#endif
212215 ImGui::SetCurrentContext (newContext);
216+ ImPlot::SetCurrentContext (newPlotContext);
213217#ifdef IMGUI_HAS_DOCK
214218 // Propagate GLFW window handle to new context
215219 ImGui::GetMainViewport ()->PlatformHandle = oldPlatformIO.Viewports [0 ]->PlatformHandle ;
@@ -219,7 +223,8 @@ void pushContext(std::function<void()> callbackFunction, bool drawDefaultUI) {
219223
220224 render::engine->configureImGui ();
221225
222- contextStack.push_back (ContextEntry{newContext, callbackFunction, drawDefaultUI});
226+
227+ contextStack.push_back (ContextEntry{newContext, newPlotContext, callbackFunction, drawDefaultUI});
223228
224229 if (contextStack.size () > 50 ) {
225230 // Catch bugs with nested show()
@@ -259,14 +264,17 @@ void pushContext(std::function<void()> callbackFunction, bool drawDefaultUI) {
259264 // Workaround overzealous ImGui assertion before destroying any inner context
260265 // https://github.com/ocornut/imgui/pull/7175
261266 ImGui::SetCurrentContext (newContext);
267+ ImPlot::SetCurrentContext (newPlotContext);
262268 ImGui::GetIO ().BackendPlatformUserData = nullptr ;
263269 ImGui::GetIO ().BackendRendererUserData = nullptr ;
264270
271+ ImPlot::DestroyContext (newPlotContext);
265272 ImGui::DestroyContext (newContext);
266273
267274 // Restore the previous context, if there was one
268275 if (!contextStack.empty ()) {
269276 ImGui::SetCurrentContext (contextStack.back ().context );
277+ ImPlot::SetCurrentContext (contextStack.back ().plotContext );
270278 }
271279}
272280
0 commit comments