From 08fd09064a68f231ada9ffe1df4a9fb9958175a8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 4 Dec 2023 22:17:43 +0100 Subject: [PATCH] fix: Settings view still using old system and not opening properly --- lib/libimhex/include/hex/ui/view.hpp | 2 +- .../include/content/views/view_settings.hpp | 7 +- .../source/content/views/view_settings.cpp | 113 ++++++++---------- 3 files changed, 57 insertions(+), 65 deletions(-) diff --git a/lib/libimhex/include/hex/ui/view.hpp b/lib/libimhex/include/hex/ui/view.hpp index 064153d3a..d43472b26 100644 --- a/lib/libimhex/include/hex/ui/view.hpp +++ b/lib/libimhex/include/hex/ui/view.hpp @@ -154,7 +154,7 @@ namespace hex { public: explicit Floating(std::string unlocalizedName) : Window(std::move(unlocalizedName)) {} - [[nodiscard]] ImGuiWindowFlags getWindowFlags() const { return ImGuiWindowFlags_NoDocking; } + [[nodiscard]] ImGuiWindowFlags getWindowFlags() const override { return ImGuiWindowFlags_NoDocking; } }; /** diff --git a/plugins/builtin/include/content/views/view_settings.hpp b/plugins/builtin/include/content/views/view_settings.hpp index ac89dc69f..b99bec0dd 100644 --- a/plugins/builtin/include/content/views/view_settings.hpp +++ b/plugins/builtin/include/content/views/view_settings.hpp @@ -4,15 +4,14 @@ namespace hex::plugin::builtin { - class ViewSettings : public View::Floating { + class ViewSettings : public View::Modal { public: explicit ViewSettings(); ~ViewSettings() override; - void drawContent() override {} - void drawAlwaysVisibleContent() override; + void drawContent() override; - [[nodiscard]] bool shouldDraw() const override { return false; } + [[nodiscard]] bool shouldDraw() const override { return true; } [[nodiscard]] bool hasViewMenuItemEntry() const override { return false; } [[nodiscard]] ImVec2 getMinSize() const override { return scaled({ 700, 400 }); } diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 396c9e638..8b25f6675 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -6,16 +6,14 @@ #include #include -#include namespace hex::plugin::builtin { - ViewSettings::ViewSettings() : View::Floating("hex.builtin.view.settings.name") { + ViewSettings::ViewSettings() : View::Modal("hex.builtin.view.settings.name") { // Handle window open requests EventManager::subscribe(this, [this](const std::string &name) { if (name == "Settings") { TaskManager::doLater([this] { - ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); this->getWindowOpenState() = true; }); } @@ -24,7 +22,6 @@ namespace hex::plugin::builtin { // Add the settings menu item to the Extras menu ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.extras" }, 3000); ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.settings.name"_lang }, 4000, Shortcut::None, [&, this] { - TaskManager::doLater([this] { ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); }); this->getWindowOpenState() = true; }); } @@ -33,83 +30,79 @@ namespace hex::plugin::builtin { EventManager::unsubscribe(this); } - void ViewSettings::drawAlwaysVisibleContent() { - if (ImGui::BeginPopupModal(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoResize)) { - if (ImGui::BeginTabBar("settings")) { - auto &categories = ContentRegistry::Settings::impl::getSettings(); + void ViewSettings::drawContent() { + if (ImGui::BeginTabBar("settings")) { + auto &categories = ContentRegistry::Settings::impl::getSettings(); - // Draw all categories - for (auto &category : categories) { + // Draw all categories + for (auto &category : categories) { - // Skip empty categories - if (category.subCategories.empty()) - continue; + // Skip empty categories + if (category.subCategories.empty()) + continue; - // For each category, create a new tab - if (ImGui::BeginTabItem(Lang(category.unlocalizedName))) { - if (ImGui::BeginChild("scrolling")) { + // For each category, create a new tab + if (ImGui::BeginTabItem(Lang(category.unlocalizedName))) { + if (ImGui::BeginChild("scrolling")) { - // Draw the category description - if (!category.unlocalizedDescription.empty()) { - ImGuiExt::TextFormattedWrapped("{}", Lang(category.unlocalizedDescription)); - ImGui::NewLine(); - } + // Draw the category description + if (!category.unlocalizedDescription.empty()) { + ImGuiExt::TextFormattedWrapped("{}", Lang(category.unlocalizedDescription)); + ImGui::NewLine(); + } - // Draw all settings of that category - for (auto &subCategory : category.subCategories) { + // Draw all settings of that category + for (auto &subCategory : category.subCategories) { - // Skip empty subcategories - if (subCategory.entries.empty()) - continue; + // Skip empty subcategories + if (subCategory.entries.empty()) + continue; - ImGuiExt::BeginSubWindow(Lang(subCategory.unlocalizedName)); - { - for (auto &setting : subCategory.entries) { - ImGui::BeginDisabled(!setting.widget->isEnabled()); - ImGui::PushItemWidth(-200_scaled); - bool settingChanged = setting.widget->draw(Lang(setting.unlocalizedName)); - ImGui::PopItemWidth(); - ImGui::EndDisabled(); + ImGuiExt::BeginSubWindow(Lang(subCategory.unlocalizedName)); + { + for (auto &setting : subCategory.entries) { + ImGui::BeginDisabled(!setting.widget->isEnabled()); + ImGui::PushItemWidth(-200_scaled); + bool settingChanged = setting.widget->draw(Lang(setting.unlocalizedName)); + ImGui::PopItemWidth(); + ImGui::EndDisabled(); - if (auto tooltip = setting.widget->getTooltip(); tooltip.has_value() && ImGui::IsItemHovered()) - ImGuiExt::InfoTooltip(Lang(tooltip.value())); + if (auto tooltip = setting.widget->getTooltip(); tooltip.has_value() && ImGui::IsItemHovered()) + ImGuiExt::InfoTooltip(Lang(tooltip.value())); - auto &widget = setting.widget; + auto &widget = setting.widget; - // Handle a setting being changed - if (settingChanged) { - auto newValue = widget->store(); + // Handle a setting being changed + if (settingChanged) { + auto newValue = widget->store(); - // Write new value to settings - ContentRegistry::Settings::write(category.unlocalizedName, setting.unlocalizedName, newValue); + // Write new value to settings + ContentRegistry::Settings::write(category.unlocalizedName, setting.unlocalizedName, newValue); - // Print a debug message - log::debug("Setting [{} / {}]: Value was changed to {}", category.unlocalizedName, setting.unlocalizedName, nlohmann::to_string(newValue)); + // Print a debug message + log::debug("Setting [{} / {}]: Value was changed to {}", category.unlocalizedName, setting.unlocalizedName, nlohmann::to_string(newValue)); - // Signal that the setting was changed - EventManager::post(); - widget->onChanged(); + // Signal that the setting was changed + EventManager::post(); + widget->onChanged(); - // Request a restart if the setting requires it - if (widget->doesRequireRestart()) - this->m_restartRequested = true; - } + // Request a restart if the setting requires it + if (widget->doesRequireRestart()) + this->m_restartRequested = true; } } - ImGuiExt::EndSubWindow(); } + ImGuiExt::EndSubWindow(); } - ImGui::EndChild(); - - ImGui::EndTabItem(); } - } + ImGui::EndChild(); - ImGui::EndTabBar(); + ImGui::EndTabItem(); + } } - ImGui::EndPopup(); - } else - this->getWindowOpenState() = false; + + ImGui::EndTabBar(); + } // If a restart is required, ask the user if they want to restart if (!this->getWindowOpenState() && this->m_restartRequested) {