feat: Make diff table resizable
This commit is contained in:
parent
33f7191c0d
commit
4c38fe261d
@ -184,10 +184,21 @@ namespace hex::plugin::diffing {
|
|||||||
if (auto &algorithms = ContentRegistry::Diffing::impl::getAlgorithms(); m_algorithm == nullptr && !algorithms.empty())
|
if (auto &algorithms = ContentRegistry::Diffing::impl::getAlgorithms(); m_algorithm == nullptr && !algorithms.empty())
|
||||||
m_algorithm = algorithms.front().get();
|
m_algorithm = algorithms.front().get();
|
||||||
|
|
||||||
const auto height = ImGui::GetContentRegionAvail().y;
|
static float height = 0;
|
||||||
|
static bool dragging = false;
|
||||||
|
|
||||||
|
const auto availableSize = ImGui::GetContentRegionAvail();
|
||||||
|
auto diffingColumnSize = availableSize;
|
||||||
|
diffingColumnSize.y *= 3.5 / 5.0;
|
||||||
|
diffingColumnSize.y -= ImGui::GetTextLineHeightWithSpacing();
|
||||||
|
diffingColumnSize.y += height;
|
||||||
|
|
||||||
|
if (availableSize.y > 1)
|
||||||
|
diffingColumnSize.y = std::clamp(diffingColumnSize.y, 1.0F, std::max(1.0F, availableSize.y - ImGui::GetTextLineHeightWithSpacing() * 3));
|
||||||
|
|
||||||
|
|
||||||
// Draw the two hex editor columns side by side
|
// Draw the two hex editor columns side by side
|
||||||
if (ImGui::BeginTable("##binary_diff", 2, ImGuiTableFlags_None, ImVec2(0, height - 250_scaled))) {
|
if (ImGui::BeginTable("##binary_diff", 2, ImGuiTableFlags_None, diffingColumnSize)) {
|
||||||
ImGui::TableSetupColumn("hex.diffing.view.diff.provider_a"_lang);
|
ImGui::TableSetupColumn("hex.diffing.view.diff.provider_a"_lang);
|
||||||
ImGui::TableSetupColumn("hex.diffing.view.diff.provider_b"_lang);
|
ImGui::TableSetupColumn("hex.diffing.view.diff.provider_b"_lang);
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
@ -214,11 +225,11 @@ namespace hex::plugin::diffing {
|
|||||||
|
|
||||||
// Draw first hex editor column
|
// Draw first hex editor column
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
bool scrollB = drawDiffColumn(a, height - 250_scaled);
|
bool scrollB = drawDiffColumn(a, diffingColumnSize.y);
|
||||||
|
|
||||||
// Draw second hex editor column
|
// Draw second hex editor column
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
bool scrollA = drawDiffColumn(b, height - 250_scaled);
|
bool scrollA = drawDiffColumn(b, diffingColumnSize.y);
|
||||||
|
|
||||||
// Sync the scroll positions of the hex editors
|
// Sync the scroll positions of the hex editors
|
||||||
{
|
{
|
||||||
@ -235,8 +246,24 @@ namespace hex::plugin::diffing {
|
|||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::Button("##table_drag_bar", ImVec2(ImGui::GetContentRegionAvail().x, 2_scaled));
|
||||||
|
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 0)) {
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
dragging = true;
|
||||||
|
} else {
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
if (ImGui::IsItemHovered()) {
|
||||||
|
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dragging) {
|
||||||
|
height += ImGui::GetMouseDragDelta(ImGuiMouseButton_Left, 0).y;
|
||||||
|
ImGui::ResetMouseDragDelta(ImGuiMouseButton_Left);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw the differences table
|
// Draw the differences table
|
||||||
if (ImGui::BeginTable("##differences", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Resizable, ImVec2(0, 200_scaled))) {
|
if (ImGui::BeginTable("##differences", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Resizable)) {
|
||||||
ImGui::TableSetupScrollFreeze(0, 1);
|
ImGui::TableSetupScrollFreeze(0, 1);
|
||||||
ImGui::TableSetupColumn("hex.ui.common.begin"_lang);
|
ImGui::TableSetupColumn("hex.ui.common.begin"_lang);
|
||||||
ImGui::TableSetupColumn("hex.ui.common.end"_lang);
|
ImGui::TableSetupColumn("hex.ui.common.end"_lang);
|
||||||
|
Loading…
Reference in New Issue
Block a user