impr: Modernize Tools view

This commit is contained in:
WerWolv
2025-08-10 12:36:11 +02:00
parent 5028b354cc
commit 73a59fe5c1
7 changed files with 53 additions and 47 deletions

View File

@@ -1276,7 +1276,7 @@ namespace ImGuiExt {
const auto framePadding = style.FramePadding.x;
ImGui::PushStyleVarX(ImGuiStyleVar_FramePadding, 0);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - style.WindowPadding.x + framePadding);
*collapsed = !ImGui::TreeNodeEx("##CollapseHeader", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanLabelWidth);
*collapsed = !ImGui::TreeNodeEx("##CollapseHeader", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanLabelWidth | (*collapsed ? ImGuiTreeNodeFlags_None : ImGuiTreeNodeFlags_DefaultOpen));
ImGui::SameLine(0, framePadding);
ImGui::TextUnformatted(label);
if (!*collapsed) ImGui::TreePop();
@@ -1287,8 +1287,6 @@ namespace ImGuiExt {
}
if (collapsed != nullptr && *collapsed) {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - (ImGui::GetStyle().FramePadding.y * 2));
ImGuiExt::TextFormattedDisabled("...");
result = false;
}
}

View File

@@ -20,6 +20,7 @@ namespace hex::plugin::builtin {
std::map<ImGuiWindow*, float> m_windowHeights;
std::map<UnlocalizedString, bool> m_detachedTools;
std::map<UnlocalizedString, bool> m_collapsedTools;
};
}

View File

@@ -652,7 +652,7 @@
"hex.builtin.tools.http_requests.headers": "Headers",
"hex.builtin.tools.http_requests.response": "Response",
"hex.builtin.tools.http_requests.body": "Body",
"hex.builtin.tools.ieee754": "IEEE 754 Floating Point Encoder and Decoder",
"hex.builtin.tools.ieee754": "IEEE 754 Floating Point Explorer",
"hex.builtin.tools.ieee754.clear": "Clear",
"hex.builtin.tools.ieee754.description": "IEEE754 is a standard for representing floating point numbers which is used by most modern CPUs.\n\nThis tool visualizes the internal representation of a floating point number and allows decoding and encoding of numbers with a non-standard number of mantissa or exponent bits.",
"hex.builtin.tools.ieee754.double_precision": "Double Precision",

View File

@@ -580,7 +580,7 @@
"hex.builtin.tools.http_requests.headers": "",
"hex.builtin.tools.http_requests.response": "",
"hex.builtin.tools.http_requests.send": "",
"hex.builtin.tools.ieee754": "IEEE 754 Floating Point Tester",
"hex.builtin.tools.ieee754": "IEEE 754 Floating Point Explorer",
"hex.builtin.tools.ieee754.clear": "",
"hex.builtin.tools.ieee754.description": "",
"hex.builtin.tools.ieee754.double_precision": "Double Precision",

View File

@@ -347,6 +347,8 @@ namespace hex::plugin::builtin::recent {
}
}
} else {
ImGui::TextUnformatted("...");
}
ImGuiExt::EndSubWindow();
}

View File

@@ -10,46 +10,48 @@ namespace hex::plugin::builtin {
void drawASCIITable() {
static bool asciiTableShowOctal = false;
ImGui::BeginTable("##asciitable", 4);
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("");
if (ImGui::BeginTable("##asciitable", 4, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableSetupColumn("##1");
ImGui::TableSetupColumn("##2");
ImGui::TableSetupColumn("##3");
ImGui::TableSetupColumn("##4");
ImGui::TableNextColumn();
for (u8 tablePart = 0; tablePart < 4; tablePart++) {
ImGui::BeginTable("##asciitablepart", asciiTableShowOctal ? 4 : 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg);
ImGui::TableSetupColumn("dec");
if (asciiTableShowOctal)
ImGui::TableSetupColumn("oct");
ImGui::TableSetupColumn("hex");
ImGui::TableSetupColumn("char");
ImGui::TableHeadersRow();
for (u8 i = 0; i < 0x80 / 4; i++) {
ImGui::TableNextRow();
ImGui::TableNextRow();
for (u8 tablePart = 0; tablePart < 4; tablePart++) {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{0:03d}", i + 32 * tablePart);
if (ImGui::BeginTable("##asciitablepart", asciiTableShowOctal ? 4 : 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("dec");
if (asciiTableShowOctal)
ImGui::TableSetupColumn("oct");
ImGui::TableSetupColumn("hex");
ImGui::TableSetupColumn("char");
if (asciiTableShowOctal) {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("0o{0:03o}", i + 32 * tablePart);
ImGui::TableHeadersRow();
for (u8 i = 0; i < 0x80 / 4; i++) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{0:03d}", i + 32 * tablePart);
if (asciiTableShowOctal) {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("0o{0:03o}", i + 32 * tablePart);
}
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("0x{0:02X}", i + 32 * tablePart);
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{0}", hex::makePrintable(i + 32 * tablePart));
}
ImGui::EndTable();
}
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("0x{0:02X}", i + 32 * tablePart);
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{0}", hex::makePrintable(i + 32 * tablePart));
}
ImGui::EndTable();
ImGui::TableNextColumn();
}
ImGui::EndTable();
ImGui::Checkbox("hex.builtin.tools.ascii_table.octal"_lang, &asciiTableShowOctal);
}

View File

@@ -37,15 +37,18 @@ namespace hex::plugin::builtin {
// If the tool has been detached from the main window, don't draw it here anymore
if (m_detachedTools[unlocalizedName]) continue;
if (!m_collapsedTools.contains(unlocalizedName))
m_collapsedTools[unlocalizedName] = true;
// Draw the tool
if (ImGui::CollapsingHeader(fmt::format("{} {}", icon, Lang(unlocalizedName)).c_str())) {
auto &collapsed = m_collapsedTools[unlocalizedName];
if (ImGuiExt::BeginSubWindow(fmt::format("{} {}", icon, Lang(unlocalizedName)).c_str(), &collapsed, ImVec2(0, collapsed ? 1 : 0))) {
function();
ImGui::NewLine();
} else {
// Handle dragging the tool out of the main window
// If the user clicks on the header, start dragging the tool remember the iterator
if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && m_dragStartIterator == tools.end())
if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered() && m_dragStartIterator == tools.end())
m_dragStartIterator = iter;
// If the user released the mouse button, stop dragging the tool
@@ -53,11 +56,11 @@ namespace hex::plugin::builtin {
m_dragStartIterator = tools.end();
// Detach the tool if the user dragged it out of the main window
if (!ImGui::IsItemHovered() && m_dragStartIterator == iter) {
if (!ImGui::IsWindowHovered() && m_dragStartIterator == iter) {
m_detachedTools[unlocalizedName] = true;
}
}
ImGuiExt::EndSubWindow();
}
}
@@ -81,22 +84,22 @@ namespace hex::plugin::builtin {
ImGui::SetNextWindowSizeConstraints(ImVec2(400_scaled, height), ImVec2(FLT_MAX, height));
// Create a new window for the tool
ImGui::SetNextWindowPos(ImGui::GetMousePos() - ImVec2(0, ImGui::GetTextLineHeightWithSpacing()), ImGuiCond_Appearing);
if (ImGui::Begin(windowName.c_str(), &m_detachedTools[unlocalizedName], ImGuiWindowFlags_NoCollapse)) {
// Draw the tool content
function();
const auto window = ImGui::GetCurrentWindowRead();
// Handle the first frame after the tool has been detached
if (ImGui::IsWindowAppearing() && m_dragStartIterator == iter) {
m_dragStartIterator = tools.end();
// Attach the newly created window to the cursor, so it gets dragged around
auto& g = *ImGui::GetCurrentContext();
g.MovingWindow = ImGui::GetCurrentWindowRead();
g.ActiveId = g.MovingWindow->MoveId;
ImGui::StartMouseMovingWindowOrNode(window, nullptr, true);
}
const auto window = ImGui::GetCurrentWindowRead();
m_windowHeights[ImGui::GetCurrentWindowRead()] = ImGui::CalcWindowNextAutoFitSize(window).y;
m_windowHeights[window] = ImGui::CalcWindowNextAutoFitSize(window).y;
}
ImGui::End();
}