From bfdb9b4019ef3eb3d03ad2a5429e3c6a6d9b74ba Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 19 May 2024 21:51:55 +0200 Subject: [PATCH] impr: Allow views to opt out of having their open state saved --- lib/libimhex/include/hex/ui/view.hpp | 5 ++++- plugins/builtin/source/content/views.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/include/hex/ui/view.hpp b/lib/libimhex/include/hex/ui/view.hpp index 5964ea1d2..e82ecc1cd 100644 --- a/lib/libimhex/include/hex/ui/view.hpp +++ b/lib/libimhex/include/hex/ui/view.hpp @@ -80,6 +80,8 @@ namespace hex { */ [[nodiscard]] virtual ImGuiWindowFlags getWindowFlags() const; + [[nodiscard]] virtual bool shouldStoreWindowState() const { return true; } + [[nodiscard]] const char *getIcon() const { return m_icon; } [[nodiscard]] bool &getWindowOpenState(); @@ -183,7 +185,8 @@ namespace hex { } } - virtual bool hasCloseButton() const { return true; } + [[nodiscard]] virtual bool hasCloseButton() const { return true; } + [[nodiscard]] bool shouldStoreWindowState() const override { return false; } }; } \ No newline at end of file diff --git a/plugins/builtin/source/content/views.cpp b/plugins/builtin/source/content/views.cpp index ed2257822..4fe87583d 100644 --- a/plugins/builtin/source/content/views.cpp +++ b/plugins/builtin/source/content/views.cpp @@ -50,6 +50,9 @@ namespace hex::plugin::builtin { LayoutManager::registerLoadCallback([](std::string_view line) { for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) { + if (!view->shouldStoreWindowState()) + continue; + std::string format = hex::format("{}=%d", view->getUnlocalizedName().get()); sscanf(line.data(), format.c_str(), &view->getWindowOpenState()); } @@ -57,6 +60,9 @@ namespace hex::plugin::builtin { LayoutManager::registerStoreCallback([](ImGuiTextBuffer *buffer) { for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) { + if (!view->shouldStoreWindowState()) + continue; + buffer->appendf("%s=%d\n", name.c_str(), view->getWindowOpenState()); } });