From 12281ce6f46c69ab23522e4ec11fe11210615592 Mon Sep 17 00:00:00 2001 From: lachrymaLF Date: Mon, 24 Jun 2024 12:00:30 -0400 Subject: [PATCH] sane graph drags --- Keishiki/UI.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Keishiki/UI.cpp b/Keishiki/UI.cpp index 511a23c..7c12d98 100644 --- a/Keishiki/UI.cpp +++ b/Keishiki/UI.cpp @@ -1297,14 +1297,18 @@ namespace K::UI { ImPlot::PushStyleColor(ImPlotCol_PlotBg, 0); ImPlot::PushStyleColor(ImPlotCol_PlotBorder, 0); if (ImPlot::BeginPlot("uniform", {view_width, ImGui::GetContentRegionAvail().y}, ImPlotFlags_CanvasOnly | ImPlotFlags_NoFrame | ImPlotFlags_NoInputs)) { + static bool started_dragging = false, dragging = false; + ImPlot::SetupAxis(ImAxis_X1, "time", ImPlotAxisFlags_NoHighlight | ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines); - ImPlot::SetupAxis(ImAxis_Y1, "val", ImPlotAxisFlags_NoHighlight | ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_Opposite | ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_AutoFit); + auto flags = ImPlotAxisFlags_NoHighlight | ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_Opposite | ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks; + if (!dragging) + flags |= ImPlotAxisFlags_AutoFit; + ImPlot::SetupAxis(ImAxis_Y1, "val", flags); const f32 begin = view_left * static_cast(s.frame_max + 1), end = view_right * static_cast(s.frame_max + 1); ImPlot::SetupAxisLimits(ImAxis_X1, begin, end, ImGuiCond_Always); ImPlot::SetupFinish(); - static bool started_dragging = false, dragging = false; if (started_dragging) { dragging = true; } @@ -1693,25 +1697,29 @@ namespace K::UI { ImGui::SetCursorPos(ImVec2{w * .8f, w - 15.0f,}); ImGui::Text("%.2f", y_min); + static f32 y_range_old{}; + ImVec2 size = {15.0f, 15.0f}; ImGui::SetCursorScreenPos(tp2 - size / 2.0f); ImVec2 off = io.MousePos - io.MouseClickedPos[0]; ImGui::Button("##P2", size); if (ImGui::IsItemClicked()) { + y_range_old = y_range; p2_old = p2; } if (ImGui::IsItemActive()) { - p2 = p2_old + ImVec2{off.x / w, off.y / -w * y_range}; + p2 = p2_old + ImVec2{off.x / w, off.y / -w * y_range_old}; p2.x = std::clamp(p2.x, 0.0f, 1.0f); } ImGui::SetCursorScreenPos(tp3 - size / 2.0f); ImGui::Button("##P3", size); if (ImGui::IsItemClicked()) { + y_range_old = y_range; p3_old = p3; } if (ImGui::IsItemActive()) { - p3 = p3_old + ImVec2{off.x / w, off.y / -w * y_range}; + p3 = p3_old + ImVec2{off.x / w, off.y / -w * y_range_old}; p3.x = std::clamp(p3.x, 0.0f, 1.0f); } }