From 5f75c8684fed5b749c9331fad7f07872c8f82c31 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 10 Apr 2024 21:04:57 +0200 Subject: [PATCH] impr: Better UI for the case when no plugins could be loaded --- main/gui/include/window.hpp | 3 ++- main/gui/source/window/window.cpp | 36 ++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/main/gui/include/window.hpp b/main/gui/include/window.hpp index bdbd40f89..8d97abad2 100644 --- a/main/gui/include/window.hpp +++ b/main/gui/include/window.hpp @@ -62,7 +62,8 @@ namespace hex { ImGuiExt::ImHexCustomData m_imguiCustomData; - u32 m_searchBarPosition; + u32 m_searchBarPosition = 0; + bool m_emergencyPopupOpen = false; }; } \ No newline at end of file diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 7954bd603..0bb278405 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -44,12 +44,13 @@ namespace hex { using namespace std::literals::chrono_literals; Window::Window() { - constexpr static auto openEmergencyPopup = [](const std::string &title){ - TaskManager::doLater([title] { + const static auto openEmergencyPopup = [this](const std::string &title){ + TaskManager::doLater([this, title] { for (const auto &provider : ImHexApi::Provider::getProviders()) ImHexApi::Provider::remove(provider, false); ImGui::OpenPopup(title.c_str()); + m_emergencyPopupOpen = true; }); }; @@ -290,7 +291,10 @@ namespace hex { ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0F); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + + if (!m_emergencyPopupOpen) + windowFlags |= ImGuiWindowFlags_MenuBar; // Render main dock space if (ImGui::Begin("ImHexDockSpace", nullptr, windowFlags)) { @@ -303,7 +307,8 @@ namespace hex { ImGui::End(); ImGui::PopStyleVar(2); - // Plugin load error popups. These are not translated because they should always be readable, no matter if any localization could be loaded or not + // Plugin load error popups + // These are not translated because they should always be readable, no matter if any localization could be loaded or not { auto drawPluginFolderTable = [] { ImGuiExt::UnderlinedText("Plugin folders"); @@ -326,9 +331,19 @@ namespace hex { } }; + if (m_emergencyPopupOpen) { + const auto pos = ImHexApi::System::getMainWindowPosition(); + const auto size = ImHexApi::System::getMainWindowSize(); + ImGui::GetBackgroundDrawList()->AddRectFilled(pos, pos + size, ImGui::GetColorU32(ImGuiCol_WindowBg) | 0xFF000000); + } + + ImGui::PushStyleColor(ImGuiCol_ModalWindowDimBg, 0x00); + ON_SCOPE_EXIT { ImGui::PopStyleColor(); }; + // No plugins error popup - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); - if (ImGui::BeginPopupModal("No Plugins", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) { + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5F, 0.5F)); + if (ImGui::BeginPopupModal("No Plugins", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar)) { + ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindowRead()); ImGui::TextUnformatted("No ImHex plugins loaded (including the built-in plugin)!"); ImGui::TextUnformatted("Make sure you installed ImHex correctly."); ImGui::TextUnformatted("There should be at least a 'builtin.hexplug' file in your plugins folder."); @@ -338,15 +353,16 @@ namespace hex { drawPluginFolderTable(); ImGui::NewLine(); - if (ImGui::Button("Close ImHex", ImVec2(ImGui::GetContentRegionAvail().x, 0))) + if (ImGuiExt::DimmedButton("Close ImHex", ImVec2(ImGui::GetContentRegionAvail().x, 0))) ImHexApi::System::closeImHex(true); ImGui::EndPopup(); } // Duplicate plugins error popup - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); - if (ImGui::BeginPopupModal("Duplicate Plugins loaded", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) { + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5F, 0.5F)); + if (ImGui::BeginPopupModal("Duplicate Plugins loaded", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar)) { + ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindowRead()); ImGui::TextUnformatted("ImHex found and attempted to load multiple plugins with the same name!"); ImGui::TextUnformatted("Make sure you installed ImHex correctly and, if needed,"); ImGui::TextUnformatted("cleaned up older installations correctly."); @@ -357,7 +373,7 @@ namespace hex { drawPluginFolderTable(); ImGui::NewLine(); - if (ImGui::Button("Close ImHex", ImVec2(ImGui::GetContentRegionAvail().x, 0))) + if (ImGuiExt::DimmedButton("Close ImHex", ImVec2(ImGui::GetContentRegionAvail().x, 0))) ImHexApi::System::closeImHex(true); ImGui::EndPopup();