1
0
mirror of synced 2024-11-24 15:50:16 +01:00

impr: Allow views to opt out of having their open state saved

This commit is contained in:
WerWolv 2024-05-19 21:51:55 +02:00
parent bad37d0940
commit bfdb9b4019
2 changed files with 10 additions and 1 deletions

View File

@ -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; }
};
}

View File

@ -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());
}
});