SaveTool: improve drawUnsafeWidget().

This commit is contained in:
Guillaume Jacquemin 2021-07-10 16:44:39 +02:00
parent 031b7a1c9a
commit f9a3088094

View file

@ -106,21 +106,22 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
template<typename Functor, typename... Args>
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>(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.