From c1a14cb4d412256582464ac5e016e720f8c63085 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 25 Aug 2025 21:22:43 +0200 Subject: [PATCH] impr: Ensure that wrapped text doesn't end up wrapping at every character --- lib/libimhex/include/hex/ui/imgui_imhex_extensions.h | 6 ++++-- lib/libimhex/source/ui/imgui_imhex_extensions.cpp | 2 +- plugins/ui/source/ui/markdown.cpp | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 12380c727..fa0b17ecc 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -253,11 +254,12 @@ namespace ImGuiExt { } void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) { + using namespace hex; // Manually wrap text, using the letter M (generally the widest character in non-monospaced fonts) to calculate the character width to use. auto text = wolv::util::trim(wolv::util::wrapMonospacedString( fmt::format(fmt::runtime(fmt), std::forward(args)...), ImGui::CalcTextSize("M").x, - ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize + std::max(100_scaled, ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize) )); auto textSize = ImGui::CalcTextSize(text.c_str()); @@ -268,7 +270,7 @@ namespace ImGuiExt { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0F); ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4()); - ImGui::PushItemWidth(ImGui::CalcTextSize(text.c_str()).x + ImGui::GetStyle().FramePadding.x * 2); + ImGui::PushItemWidth(textSize.x + ImGui::GetStyle().FramePadding.x * 2); ImGui::InputTextMultiline( "##", const_cast(text.c_str()), diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index cbee19323..62d8136de 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -443,8 +443,8 @@ namespace ImGuiExt { ImGuiContext &g = *GImGui; const ImGuiStyle &style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label, nullptr, true) + CalcTextSize(description, nullptr, true); const ImVec2 label_size = CalcTextSize(label, nullptr, true); + const ImVec2 text_size = label_size + CalcTextSize(description, nullptr, true); ImVec2 pos = window->DC.CursorPos; if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag) diff --git a/plugins/ui/source/ui/markdown.cpp b/plugins/ui/source/ui/markdown.cpp index a335b9081..95c960045 100644 --- a/plugins/ui/source/ui/markdown.cpp +++ b/plugins/ui/source/ui/markdown.cpp @@ -107,7 +107,8 @@ namespace hex::ui { break; } case MD_BLOCK_P: - ImGui::NewLine(); + if (!self.m_firstLine) + ImGui::NewLine(); break; default: break;