From ba7c10f4b1ac75db2103a5959f5e1dddc8662642 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 25 Jun 2024 13:54:29 +0200 Subject: [PATCH] feat: Fix sub menus, allow recent items to be collapsed --- .../include/hex/ui/imgui_imhex_extensions.h | 2 +- .../source/ui/imgui_imhex_extensions.cpp | 25 ++++++- .../source/content/out_of_box_experience.cpp | 6 +- plugins/builtin/source/content/recent.cpp | 7 +- .../source/content/settings_entries.cpp | 6 +- .../source/content/views/view_about.cpp | 41 +++++++----- .../content/views/view_highlight_rules.cpp | 6 +- .../source/content/views/view_information.cpp | 6 +- .../source/content/views/view_settings.cpp | 6 +- .../source/content/views/view_tutorials.cpp | 6 +- .../builtin/source/content/welcome_screen.cpp | 65 ++++++++++--------- .../content/data_information_sections.cpp | 6 +- 12 files changed, 108 insertions(+), 74 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 9d5d60951..367eac269 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -286,7 +286,7 @@ namespace ImGuiExt { bool BeginBox(); void EndBox(); - void BeginSubWindow(const char *label, ImVec2 size = ImVec2(0, 0), ImGuiChildFlags flags = ImGuiChildFlags_None); + bool BeginSubWindow(const char *label, bool *collapsed = nullptr, ImVec2 size = ImVec2(0, 0), ImGuiChildFlags flags = ImGuiChildFlags_None); void EndSubWindow(); void ConfirmButtons(const char *textLeft, const char *textRight, const auto &leftButtonCallback, const auto &rightButtonCallback) { diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 2733ccbf5..06d57e6dd 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -1158,17 +1158,38 @@ namespace ImGuiExt { PopStyleVar(); } - void BeginSubWindow(const char *label, ImVec2 size, ImGuiChildFlags flags) { + bool BeginSubWindow(const char *label, bool *collapsed, ImVec2 size, ImGuiChildFlags flags) { const bool hasMenuBar = !std::string_view(label).empty(); + bool result = false; ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0F); if (ImGui::BeginChild(hex::format("{}##SubWindow", label).c_str(), size, ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY | flags, hasMenuBar ? ImGuiWindowFlags_MenuBar : ImGuiWindowFlags_None)) { + result = true; + if (hasMenuBar && ImGui::BeginMenuBar()) { - ImGui::TextUnformatted(label); + if (collapsed == nullptr) + ImGui::TextUnformatted(label); + else { + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, ImGui::GetStyle().FramePadding.y)); + ImGui::PushStyleColor(ImGuiCol_Button, 0x00); + if (ImGui::Button(label)) + *collapsed = !*collapsed; + ImGui::PopStyleColor(); + ImGui::PopStyleVar(); + } ImGui::EndMenuBar(); } + + if (collapsed != nullptr && *collapsed) { + ImGui::SetCursorPosY(ImGui::GetCursorPosY() - (ImGui::GetStyle().FramePadding.y * 2)); + ImGui::TextDisabled("..."); + result = false; + ImGui::EndChild(); + } } ImGui::PopStyleVar(); + + return result; } void EndSubWindow() { diff --git a/plugins/builtin/source/content/out_of_box_experience.cpp b/plugins/builtin/source/content/out_of_box_experience.cpp index b42b0d3dc..13744ae28 100644 --- a/plugins/builtin/source/content/out_of_box_experience.cpp +++ b/plugins/builtin/source/content/out_of_box_experience.cpp @@ -269,8 +269,7 @@ namespace hex::plugin::builtin { // Draw telemetry subwindow ImGui::SetCursorPos((windowSize - subWindowSize) / 2); - ImGuiExt::BeginSubWindow("hex.builtin.oobe.server_contact"_lang, subWindowSize, ImGuiChildFlags_AutoResizeY); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.oobe.server_contact"_lang, nullptr, subWindowSize, ImGuiChildFlags_AutoResizeY)) { // Draw telemetry information auto yBegin = ImGui::GetCursorPosY(); std::string message = "hex.builtin.oobe.server_contact.text"_lang; @@ -356,8 +355,9 @@ namespace hex::plugin::builtin { auto yEnd = ImGui::GetCursorPosY(); subWindowSize = ImGui::GetWindowSize(); subWindowSize.y = (yEnd - yBegin) + 35_scaled; + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); break; } diff --git a/plugins/builtin/source/content/recent.cpp b/plugins/builtin/source/content/recent.cpp index 161ad2b3f..0475c8eec 100644 --- a/plugins/builtin/source/content/recent.cpp +++ b/plugins/builtin/source/content/recent.cpp @@ -243,8 +243,8 @@ namespace hex::plugin::builtin::recent { if (s_recentEntries.empty() && !s_autoBackupsFound) return; - ImGuiExt::BeginSubWindow("hex.builtin.welcome.start.recent"_lang, ImVec2(), ImGuiChildFlags_AutoResizeX); - { + static bool collapsed = false; + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.start.recent"_lang, &collapsed, ImVec2(), ImGuiChildFlags_AutoResizeX)) { if (!s_recentEntriesUpdating) { for (auto it = s_recentEntries.begin(); it != s_recentEntries.end();) { const auto &recentEntry = *it; @@ -327,8 +327,9 @@ namespace hex::plugin::builtin::recent { PopupAutoBackups::open(); } } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } void addMenuItems() { diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 91a3fd9a1..dc9b7e08e 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -450,8 +450,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); // Draw toolbar icon box - ImGuiExt::BeginSubWindow("hex.builtin.setting.toolbar.icons"_lang, ImGui::GetContentRegionAvail()); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.setting.toolbar.icons"_lang, nullptr, ImGui::GetContentRegionAvail())) { if (ImGui::BeginTable("##icons", 6, ImGuiTableFlags_SizingStretchSame, ImGui::GetContentRegionAvail())) { ImGui::TableNextRow(); @@ -553,8 +552,9 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); // Handle dropping menu items onto the toolbar box if (ImGui::BeginDragDropTarget()) { diff --git a/plugins/builtin/source/content/views/view_about.cpp b/plugins/builtin/source/content/views/view_about.cpp index 4b0228694..3393e81a2 100644 --- a/plugins/builtin/source/content/views/view_about.cpp +++ b/plugins/builtin/source/content/views/view_about.cpp @@ -128,11 +128,11 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); - ImGuiExt::BeginSubWindow("Build Information", ImVec2(450_scaled, 0), ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_AutoResizeY); - { + if (ImGuiExt::BeginSubWindow("Build Information", nullptr, ImVec2(450_scaled, 0), ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_AutoResizeY)) { this->drawBuildInformation(); + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::EndTable(); } @@ -243,9 +243,9 @@ namespace hex::plugin::builtin { static void drawContributorTable(const char *title, const auto &contributors) { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); - ImGuiExt::BeginSubWindow(title, ImVec2(ImGui::GetContentRegionAvail().x, 0), ImGuiChildFlags_AutoResizeX); + auto result = ImGuiExt::BeginSubWindow(title, nullptr, ImVec2(ImGui::GetContentRegionAvail().x, 0), ImGuiChildFlags_AutoResizeX); ImGui::PopStyleVar(); - { + if (result) { if (ImGui::BeginTable(title, 1, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders)) { for (const auto &contributor : contributors) { ImGui::TableNextRow(); @@ -266,8 +266,9 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } void ViewAbout::drawContributorPage() { @@ -348,8 +349,7 @@ namespace hex::plugin::builtin { constexpr static auto drawTable = [](const char *category, const auto &libraries) { const auto width = ImGui::GetContentRegionAvail().x; - ImGuiExt::BeginSubWindow(category); - { + if (ImGuiExt::BeginSubWindow(category)) { for (const auto &library : libraries) { ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetColorU32(ImGuiCol_TableHeaderBg)); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 50); @@ -370,8 +370,9 @@ namespace hex::plugin::builtin { ImGui::PopStyleColor(); ImGui::PopStyleVar(2); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::NewLine(); }; @@ -388,9 +389,10 @@ namespace hex::plugin::builtin { const auto &plugins = PluginManager::getPlugins(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); - ImGuiExt::BeginSubWindow("hex.builtin.view.help.about.plugins"_lang); + auto result = ImGuiExt::BeginSubWindow("hex.builtin.view.help.about.plugins"_lang); ImGui::PopStyleVar(); - { + + if (result) { if (ImGui::BeginTable("plugins", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) { ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("hex.builtin.view.help.about.plugins.plugin"_lang); @@ -406,8 +408,9 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } void ViewAbout::drawPluginRow(const hex::Plugin& plugin) { @@ -479,8 +482,7 @@ namespace hex::plugin::builtin { static_assert(PathTypes.back().first != nullptr, "All path items need to be populated!"); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); - ImGuiExt::BeginSubWindow("Paths", ImGui::GetContentRegionAvail()); - { + if (ImGuiExt::BeginSubWindow("Paths", nullptr, ImGui::GetContentRegionAvail())) { if (ImGui::BeginTable("##imhex_paths", 2, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) { ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("Type"); @@ -508,8 +510,9 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::PopStyleVar(); } @@ -722,12 +725,14 @@ namespace hex::plugin::builtin { if (commits.empty()) return; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); - ImGuiExt::BeginSubWindow("Commits", ImGui::GetContentRegionAvail()); + auto result = ImGuiExt::BeginSubWindow("Commits", nullptr, ImGui::GetContentRegionAvail()); ImGui::PopStyleVar(); - this->drawCommitsTable(commits); + if (result) { + this->drawCommitsTable(commits); - ImGuiExt::EndSubWindow(); + ImGuiExt::EndSubWindow(); + } } void ViewAbout::drawCommitsTable(const auto& commits) { diff --git a/plugins/builtin/source/content/views/view_highlight_rules.cpp b/plugins/builtin/source/content/views/view_highlight_rules.cpp index 7fe27f9a4..836e4d6c7 100644 --- a/plugins/builtin/source/content/views/view_highlight_rules.cpp +++ b/plugins/builtin/source/content/views/view_highlight_rules.cpp @@ -228,8 +228,7 @@ namespace hex::plugin::builtin { void ViewHighlightRules::drawRulesConfig() { - ImGuiExt::BeginSubWindow("hex.builtin.view.highlight_rules.config"_lang, ImGui::GetContentRegionAvail()); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.view.highlight_rules.config"_lang, nullptr, ImGui::GetContentRegionAvail())) { if (m_selectedRule != m_rules->end()) { // Draw text input field for the rule name @@ -297,8 +296,9 @@ namespace hex::plugin::builtin { } else { ImGuiExt::TextFormattedCentered("hex.builtin.view.highlight_rules.no_rule"_lang); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index 52711f040..8a5a8b3d0 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -102,8 +102,7 @@ namespace hex::plugin::builtin { // Draw settings window ImGui::BeginDisabled(analysis.task.isRunning()); - ImGuiExt::BeginSubWindow("hex.ui.common.settings"_lang); - { + if (ImGuiExt::BeginSubWindow("hex.ui.common.settings"_lang)) { // Create a table so we can draw global settings on the left and section specific settings on the right if (ImGui::BeginTable("SettingsTable", 2, ImGuiTableFlags_BordersInner | ImGuiTableFlags_SizingStretchProp, ImVec2(ImGui::GetContentRegionAvail().x, 0))) { ImGui::TableSetupColumn("Left", ImGuiTableColumnFlags_WidthStretch, 0.3F); @@ -147,8 +146,9 @@ namespace hex::plugin::builtin { ImGui::SetCursorPosX(50_scaled); if (ImGuiExt::DimmedButton("hex.builtin.view.information.analyze"_lang, ImVec2(ImGui::GetContentRegionAvail().x - 50_scaled, 0))) this->analyze(); + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::EndDisabled(); if (analysis.analyzedProvider != nullptr) { diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 8dbaa4c03..5ad9972af 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -97,8 +97,7 @@ namespace hex::plugin::builtin { if (subCategory.entries.empty()) continue; - ImGuiExt::BeginSubWindow(Lang(subCategory.unlocalizedName)); - { + if (ImGuiExt::BeginSubWindow(Lang(subCategory.unlocalizedName))) { for (auto &setting : subCategory.entries) { ImGui::BeginDisabled(!setting.widget->isEnabled()); ImGui::PushItemWidth(-200_scaled); @@ -131,8 +130,9 @@ namespace hex::plugin::builtin { } } } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::NewLine(); } } diff --git a/plugins/builtin/source/content/views/view_tutorials.cpp b/plugins/builtin/source/content/views/view_tutorials.cpp index 155110af8..f21a04a02 100644 --- a/plugins/builtin/source/content/views/view_tutorials.cpp +++ b/plugins/builtin/source/content/views/view_tutorials.cpp @@ -55,11 +55,11 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); if (m_selectedTutorial != nullptr) { - ImGuiExt::BeginSubWindow("hex.builtin.view.tutorials.description"_lang, ImGui::GetContentRegionAvail() - ImVec2(0, ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().ItemSpacing.y * 2)); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.view.tutorials.description"_lang, nullptr, ImGui::GetContentRegionAvail() - ImVec2(0, ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().ItemSpacing.y * 2))) { ImGuiExt::TextFormattedWrapped(Lang(m_selectedTutorial->getUnlocalizedDescription())); + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::BeginDisabled(currTutorial != tutorials.end()); if (ImGuiExt::DimmedButton("hex.builtin.view.tutorials.start"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) { diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index e43cb24ec..d0d145e1d 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -212,8 +212,7 @@ namespace hex::plugin::builtin { { auto startPos = ImGui::GetCursorPos(); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.start"_lang, ImVec2(), ImGuiChildFlags_AutoResizeX); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.start"_lang, nullptr, ImVec2(), ImGuiChildFlags_AutoResizeX)) { if (ImGuiExt::IconHyperlink(ICON_VS_NEW_FILE, "hex.builtin.welcome.start.create_file"_lang)) { auto newProvider = hex::ImHexApi::Provider::createProvider("hex.builtin.provider.mem_file", true); if (newProvider != nullptr && !newProvider->open()) @@ -227,8 +226,9 @@ namespace hex::plugin::builtin { RequestOpenWindow::post("Open Project"); if (ImGuiExt::IconHyperlink(ICON_VS_TELESCOPE, "hex.builtin.welcome.start.open_other"_lang)) otherProvidersVisible = !otherProvidersVisible; + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); auto endPos = ImGui::GetCursorPos(); if (otherProvidersVisible) { @@ -237,14 +237,16 @@ namespace hex::plugin::builtin { ImGui::TextUnformatted(ICON_VS_ARROW_RIGHT); ImGui::SameLine(0, 2_scaled); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.start.open_other"_lang, ImVec2(200_scaled, ImGui::GetTextLineHeightWithSpacing() * 6), ImGuiChildFlags_AutoResizeX); - for (const auto &unlocalizedProviderName : ContentRegistry::Provider::impl::getEntries()) { - if (ImGuiExt::Hyperlink(Lang(unlocalizedProviderName))) { - ImHexApi::Provider::createProvider(unlocalizedProviderName); - otherProvidersVisible = false; + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.start.open_other"_lang, nullptr, ImVec2(200_scaled, ImGui::GetTextLineHeightWithSpacing() * 6), ImGuiChildFlags_AutoResizeX)) { + for (const auto &unlocalizedProviderName : ContentRegistry::Provider::impl::getEntries()) { + if (ImGuiExt::Hyperlink(Lang(unlocalizedProviderName))) { + ImHexApi::Provider::createProvider(unlocalizedProviderName); + otherProvidersVisible = false; + } } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } } @@ -256,13 +258,13 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.help"_lang, ImVec2(), ImGuiChildFlags_AutoResizeX); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.help"_lang, nullptr, ImVec2(), ImGuiChildFlags_AutoResizeX)) { if (ImGuiExt::IconHyperlink(ICON_VS_GITHUB, "hex.builtin.welcome.help.repo"_lang)) hex::openWebpage("hex.builtin.welcome.help.repo.link"_lang); if (ImGuiExt::IconHyperlink(ICON_VS_ORGANIZATION, "hex.builtin.welcome.help.gethelp"_lang)) hex::openWebpage("hex.builtin.welcome.help.gethelp.link"_lang); if (ImGuiExt::IconHyperlink(ICON_VS_COMMENT_DISCUSSION, "hex.builtin.welcome.help.discord"_lang)) hex::openWebpage("hex.builtin.welcome.help.discord.link"_lang); + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); if (ImHexApi::System::getInitArguments().contains("update-available")) { ImGui::TableNextRow(); @@ -281,17 +283,16 @@ namespace hex::plugin::builtin { auto windowPadding = ImGui::GetStyle().WindowPadding.x * 3; - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.customize"_lang, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0), ImGuiChildFlags_AutoResizeX); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.customize"_lang, nullptr, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0), ImGuiChildFlags_AutoResizeX)) { if (ImGuiExt::DescriptionButton("hex.builtin.welcome.customize.settings.title"_lang, "hex.builtin.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) RequestOpenWindow::post("Settings"); + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5); ImGui::TableNextColumn(); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.learn"_lang, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0), ImGuiChildFlags_AutoResizeX); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.learn"_lang, nullptr, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0), ImGuiChildFlags_AutoResizeX)) { const auto size = ImVec2(ImGui::GetContentRegionAvail().x, 0); if (ImGuiExt::DescriptionButton("hex.builtin.welcome.learn.latest.title"_lang, "hex.builtin.welcome.learn.latest.desc"_lang, size)) hex::openWebpage("hex.builtin.welcome.learn.latest.link"_lang); @@ -314,20 +315,21 @@ namespace hex::plugin::builtin { RequestOpenWindow::post("Achievements"); } } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); auto extraWelcomeScreenEntries = ContentRegistry::Interface::impl::getWelcomeScreenEntries(); if (!extraWelcomeScreenEntries.empty()) { ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5); ImGui::TableNextColumn(); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.various"_lang, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0)); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.various"_lang, nullptr, ImVec2(ImGui::GetContentRegionAvail().x - windowPadding, 0))) { for (const auto &callback : extraWelcomeScreenEntries) callback(); + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } if (s_infoBannerTexture.isValid()) { @@ -335,8 +337,8 @@ namespace hex::plugin::builtin { ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetStyleColorVec4(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Border)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.info"_lang, ImVec2(), ImGuiChildFlags_AutoResizeX); - { + + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.info"_lang, nullptr, ImVec2(), ImGuiChildFlags_AutoResizeX)) { const auto height = 80_scaled; ImGui::Image(s_infoBannerTexture, ImVec2(height * s_infoBannerTexture.getAspectRatio(), height)); hovered = ImGui::IsItemHovered(); @@ -344,8 +346,9 @@ namespace hex::plugin::builtin { if (ImGui::IsItemClicked()) { hex::openWebpage(ImHexApiURL + hex::format("/info/{}/link", hex::toLower(ImHexApi::System::getOSName()))); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::PopStyleVar(); ImGui::PopStyleColor(); @@ -372,8 +375,12 @@ namespace hex::plugin::builtin { ImGui::PushStyleColor(ImGuiCol_WindowShadow, 0x00); if (ImGui::Begin("ImHexDockSpace")) { if (!ImHexApi::Provider::isValid()) { - static std::array title; - ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindowRead()->Name, ImGui::GetID("ImHexMainDock")); + static auto title = []{ + std::array title = {}; + ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindowRead()->Name, ImGui::GetID("ImHexMainDock")); + return title; + }(); + if (ImGui::Begin(title.data(), nullptr, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBringToFrontOnFocus)) { ImGui::Dummy({}); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, scaled({ 10, 10 })); @@ -398,14 +405,14 @@ namespace hex::plugin::builtin { const ImVec2 windowSize = scaled({ 150, 60 }); ImGui::SetCursorScreenPos(ImGui::GetWindowPos() + ImGui::GetWindowSize() - windowSize - ImGui::GetStyle().WindowPadding); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); - ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.quick_settings"_lang, windowSize, ImGuiChildFlags_AutoResizeY); - { + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.quick_settings"_lang, nullptr, windowSize, ImGuiChildFlags_AutoResizeY)) { if (ImGuiExt::ToggleSwitch("hex.builtin.welcome.quick_settings.simplified"_lang, &s_simplifiedWelcomeScreen)) { ContentRegistry::Settings::write("hex.builtin.setting.interface", "hex.builtin.setting.interface.simplified_welcome_screen", s_simplifiedWelcomeScreen); WorkspaceManager::switchWorkspace(s_simplifiedWelcomeScreen ? "Minimal" : "Default"); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); ImGui::PopStyleColor(); hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByItem | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); diff --git a/plugins/yara_rules/source/content/data_information_sections.cpp b/plugins/yara_rules/source/content/data_information_sections.cpp index 39f7c929c..522b73cf8 100644 --- a/plugins/yara_rules/source/content/data_information_sections.cpp +++ b/plugins/yara_rules/source/content/data_information_sections.cpp @@ -75,14 +75,14 @@ namespace hex::plugin::yara { continue; ImGui::TableNextColumn(); - ImGuiExt::BeginSubWindow(categoryName.c_str()); - { + if (ImGuiExt::BeginSubWindow(categoryName.c_str())) { for (const auto &match : category.matchedRules) { const auto &ruleName = match.metadata.contains("name") ? match.metadata.at("name") : match.identifier; ImGui::TextUnformatted(ruleName.c_str()); } + + ImGuiExt::EndSubWindow(); } - ImGuiExt::EndSubWindow(); } ImGui::EndTable();