mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
impr: Modernize Tools view
This commit is contained in:
@@ -347,6 +347,8 @@ namespace hex::plugin::builtin::recent {
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
ImGui::TextUnformatted("...");
|
||||
}
|
||||
ImGuiExt::EndSubWindow();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user