diff --git a/plugins/builtin/source/content/tools/demangler.cpp b/plugins/builtin/source/content/tools/demangler.cpp index 57f1fe95f..a32dc59bc 100644 --- a/plugins/builtin/source/content/tools/demangler.cpp +++ b/plugins/builtin/source/content/tools/demangler.cpp @@ -4,13 +4,32 @@ #include #include +#include #include + namespace hex::plugin::builtin { namespace impl { void drawDemangler() { - static std::string mangledName, demangledName; + static std::string mangledName, demangledName, wrappedDemangledName; + static TextEditor outputField = []{ + TextEditor editor; + editor.SetReadOnly(true); + editor.SetShowLineNumbers(false); + editor.SetShowWhitespaces(false); + editor.SetShowCursor(false); + editor.SetImGuiChildIgnored(true); + + auto languageDef = TextEditor::LanguageDefinition::CPlusPlus(); + for (auto &[name, identifier] : languageDef.mIdentifiers) + identifier.mDeclaration = ""; + + editor.SetLanguageDefinition(languageDef); + + return editor; + }(); + static float prevWindowWidth; if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) { demangledName = llvm::demangle(mangledName); @@ -18,11 +37,26 @@ namespace hex::plugin::builtin { if (demangledName == mangledName) { demangledName = "???"; } + + prevWindowWidth = 0; + } + + const auto windowWidth = ImGui::GetContentRegionAvail().x; + if (prevWindowWidth != windowWidth) { + wrappedDemangledName = wolv::util::wrapMonospacedString( + demangledName, + ImGui::CalcTextSize("M").x, + ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize + ); + + outputField.SetText(wrappedDemangledName); + prevWindowWidth = windowWidth; } ImGuiExt::Header("hex.builtin.tools.demangler.demangled"_lang); - if (ImGui::BeginChild("demangled", ImVec2(0, 200_scaled), true)) { - ImGuiExt::TextFormattedWrappedSelectable("{}", demangledName); + + if (ImGui::BeginChild("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true, ImGuiWindowFlags_NoMove)) { + outputField.Render("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true); } ImGui::EndChild(); }