impr: Ensure that wrapped text doesn't end up wrapping at every character

This commit is contained in:
WerWolv
2025-08-25 21:22:43 +02:00
parent df2448e121
commit c1a14cb4d4
3 changed files with 7 additions and 4 deletions

View File

@@ -11,6 +11,7 @@
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/concepts.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/scaling.hpp>
#include <wolv/utils/string.hpp>
@@ -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<decltype(args)>(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<char *>(text.c_str()),

View File

@@ -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)

View File

@@ -107,7 +107,8 @@ namespace hex::ui {
break;
}
case MD_BLOCK_P:
ImGui::NewLine();
if (!self.m_firstLine)
ImGui::NewLine();
break;
default:
break;