diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 0ded79a80..06d3d10e4 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -349,8 +349,7 @@ namespace ImGuiExt { ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y); const ImRect bb(pos, pos + size); - if (!ItemAdd(bb, id)) - return false; + ItemAdd(bb, id); bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); @@ -1273,11 +1272,15 @@ namespace ImGuiExt { 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(); + const auto &style = ImGui::GetStyle(); + const auto framePadding = style.FramePadding.x; + ImGui::PushStyleVarX(ImGuiStyleVar_FramePadding, 0); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - style.WindowPadding.x + framePadding); + *collapsed = !ImGui::TreeNodeEx("##CollapseHeader", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanLabelWidth); + ImGui::SameLine(0, framePadding); + ImGui::TextUnformatted(label); + if (!*collapsed) ImGui::TreePop(); + ImGui::PopStyleVar(); } ImGui::EndMenuBar(); diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index f8396d298..aa170f2e6 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -352,12 +352,11 @@ namespace hex::plugin::builtin { if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.start.open_other"_lang, nullptr, ImVec2(200_scaled, ImGui::GetTextLineHeightWithSpacing() * 5.8), ImGuiChildFlags_AutoResizeX)) { for (const auto &[unlocalizedProviderName, icon] : ContentRegistry::Provider::impl::getEntries()) { - if (ImGuiExt::Hyperlink(fmt::format("{} {}", icon, Lang(unlocalizedProviderName)).c_str())) { + if (ImGuiExt::IconHyperlink(icon, Lang(unlocalizedProviderName))) { ImHexApi::Provider::createProvider(unlocalizedProviderName); otherProvidersVisible = false; } } - } ImGuiExt::EndSubWindow(); } @@ -515,28 +514,32 @@ namespace hex::plugin::builtin { static bool hovered = false; ImGui::PushStyleVar(ImGuiStyleVar_Alpha, hovered ? 1.0F : 0.3F); { - const ImVec2 windowSize = { 150_scaled, ImGui::GetTextLineHeightWithSpacing() * 3.5F }; - ImGui::SetCursorScreenPos(ImGui::GetWindowPos() + ImGui::GetWindowSize() - windowSize - ImGui::GetStyle().WindowPadding); - ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); - if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.quick_settings"_lang, nullptr, windowSize, ImGuiChildFlags_AutoResizeY)) { - u32 id = 0; - for (auto &[onIcon, offIcon, unlocalizedTooltip, toggleCallback, state] : ContentRegistry::Interface::impl::getWelcomeScreenQuickSettingsToggles()) { - ImGui::PushID(id + 1); - if (ImGuiExt::DimmedIconToggle(onIcon.c_str(), offIcon.c_str(), &state)) { - toggleCallback(state); - ContentRegistry::Settings::write("hex.builtin.settings.quick_settings", unlocalizedTooltip, state); + const auto &quickSettings = ContentRegistry::Interface::impl::getWelcomeScreenQuickSettingsToggles(); + if (!quickSettings.empty()) { + const auto padding = ImGui::GetStyle().FramePadding.y; + const ImVec2 windowSize = { 150_scaled, 2 * ImGui::GetTextLineHeightWithSpacing() + padding + std::ceil(quickSettings.size() / 5.0F) * (ImGui::GetTextLineHeightWithSpacing() + padding) }; + ImGui::SetCursorScreenPos(ImGui::GetWindowPos() + ImGui::GetWindowSize() - windowSize - ImGui::GetStyle().WindowPadding); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); + if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.quick_settings"_lang, nullptr, windowSize, ImGuiChildFlags_AutoResizeY)) { + u32 id = 0; + for (auto &[onIcon, offIcon, unlocalizedTooltip, toggleCallback, state] : quickSettings) { + ImGui::PushID(id + 1); + if (ImGuiExt::DimmedIconToggle(onIcon.c_str(), offIcon.c_str(), &state)) { + toggleCallback(state); + ContentRegistry::Settings::write("hex.builtin.settings.quick_settings", unlocalizedTooltip, state); + } + if (id % 5 > 0) + ImGui::SameLine(); + ImGui::SetItemTooltip("%s", Lang(unlocalizedTooltip).get()); + ImGui::PopID(); + id += 1; } - if (id % 5 > 0) - ImGui::SameLine(); - ImGui::SetItemTooltip("%s", Lang(unlocalizedTooltip).get()); - ImGui::PopID(); - id += 1; } - } - ImGuiExt::EndSubWindow(); + ImGuiExt::EndSubWindow(); - ImGui::PopStyleColor(); - hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByItem | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); + ImGui::PopStyleColor(); + hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByItem | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); + } } ImGui::PopStyleVar();