From f9a3088094d67201b9e94253104aafa7749eeb67 Mon Sep 17 00:00:00 2001 From: William JCM Date: Sat, 10 Jul 2021 16:44:39 +0200 Subject: [PATCH] SaveTool: improve drawUnsafeWidget(). --- src/SaveTool/SaveTool.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index c8b401e..24af7a4 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -106,21 +106,22 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener template auto drawUnsafeWidget(Functor func, Args... args) -> bool { - if(!_unsafeMode && _mbManager->gameState() != GameState::NotRunning) { + GameState game_state = _mbManager->gameState(); + if(!_unsafeMode && game_state != GameState::NotRunning) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f); } bool result = func(std::forward(args)...); - if(!_unsafeMode && _mbManager->gameState() != GameState::NotRunning) { + if(!_unsafeMode && game_state != GameState::NotRunning) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); } return result; } // Obviously, should only be used with ImGui widgets that return a bool. - // Also, should be called with a lambda if there are any default arguments, like ImGui::Button(), etc... + // Also, func should be a lambda if there are any default arguments, like ImGui::Button(), etc... void drawUnsafeText(const char* text, ...); // Alternative to the above, for ImGui::Text*() variants.