Files
imhex/plugins/builtin/source/content/tools/demangler.cpp
paxcut df1e97af0a improv: further reformatting of text editor in an effort to bring it into the ui plugin. (#2385)
Added the ui namespace and broke the main rendering function into a set
of smaller functions. Reorganized the header code separating functions
into rough groups that eventually will be in separate files.
2025-08-08 12:47:52 -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 ui::TextEditor outputField = []{
ui::TextEditor editor;
editor.setReadOnly(true);
editor.setShowLineNumbers(false);
editor.setShowWhitespaces(false);
editor.setShowCursor(false);
editor.setImGuiChildIgnored(true);
auto languageDef = ui::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();
}
}