Files
imhex/plugins/builtin/source/content/tools/demangler.cpp
paxcut d429424f67 improv: refactor text editor to follow imhex style. (#2382)
Also fixes two bugs:
1) error messages not staying visible
2) uncaught exception when struct name is duplicated.

A lot of the code using coordinates for start and end has been moved to
use Selections instead. Created more string manipulation code that uses
utf8 indices aka Coordinates directly. This makes implementing editing
functions easier by not having to go back and forth from string indices
to char indices and back. Currently, the substring, erase and []
operator support coordinates and str indices.
2025-08-06 01:01:07 -07:00

63 lines
2.1 KiB
C++

#include <hex/helpers/utils.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/trace/stacktrace.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <imgui.h>
#include <TextEditor.h>
namespace hex::plugin::builtin {
void drawDemangler() {
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.m_identifiers)
identifier.m_declaration = "";
editor.setLanguageDefinition(languageDef);
return editor;
}();
static float prevWindowWidth;
if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) {
demangledName = trace::demangle(mangledName);
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(ImGui::GetContentRegionAvail().x, 150_scaled), true, ImGuiWindowFlags_NoMove)) {
outputField.render("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);
}
ImGui::EndChild();
}
}