From 924b4a9436a4c84915ea3a85f338b740b0ab7797 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 7 Nov 2023 00:46:44 +0100 Subject: [PATCH] impr: Replace various fixed-size boxes with dynamic ones --- .../include/hex/ui/imgui_imhex_extensions.h | 3 +++ lib/libimhex/source/ui/imgui_imhex_extensions.cpp | 14 ++++++++++++++ .../source/content/views/view_disassembler.cpp | 5 +++-- .../builtin/source/content/views/view_settings.cpp | 9 ++------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index eccb54910..012329ed1 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -270,6 +270,9 @@ namespace ImGui { void TextOverlay(const char *text, ImVec2 pos); + bool BeginBox(); + void EndBox(); + template constexpr ImGuiDataType getImGuiDataType() { if constexpr (std::same_as) return ImGuiDataType_U8; diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index cb6b76ee9..a5349a58e 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -821,4 +821,18 @@ namespace ImGui { drawList->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), text); } + bool BeginBox() { + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(5, 5)); + auto result = ImGui::BeginTable("##box", 1, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_SizingStretchSame); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + return result; + } + + void EndBox() { + ImGui::EndTable(); + ImGui::PopStyleVar(); + } + } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_disassembler.cpp b/plugins/builtin/source/content/views/view_disassembler.cpp index 5d5b36a5d..3ba667541 100644 --- a/plugins/builtin/source/content/views/view_disassembler.cpp +++ b/plugins/builtin/source/content/views/view_disassembler.cpp @@ -115,7 +115,7 @@ namespace hex::plugin::builtin { this->m_mode = cs_mode(0); // Draw sub-settings for each architecture - if (ImGui::BeginChild("modes", ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 6), true, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::BeginBox()) { // Draw endian radio buttons. This setting is available for all architectures static int littleEndian = true; @@ -374,8 +374,9 @@ namespace hex::plugin::builtin { this->m_mode = cs_mode(0); break; } + + ImGui::EndBox(); } - ImGui::EndChild(); } // Draw disassemble button diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 54134c1ba..a91abdcd9 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -67,11 +67,7 @@ namespace hex::plugin::builtin { firstSubCategory = false; - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, scaled({5, 5})); - if (ImGui::BeginTable("##subCategory", 1, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_SizingStretchSame)) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - + if (ImGui::BeginBox()) { for (auto &setting : subCategory.entries) { ImGui::BeginDisabled(!setting.widget->isEnabled()); bool settingChanged = setting.widget->draw(LangEntry(setting.unlocalizedName)); @@ -102,9 +98,8 @@ namespace hex::plugin::builtin { } } - ImGui::EndTable(); + ImGui::EndBox(); } - ImGui::PopStyleVar(); }