sane graph drags
This commit is contained in:
parent
c864b0da32
commit
12281ce6f4
1 changed files with 12 additions and 4 deletions
|
@ -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<f32>(s.frame_max + 1), end = view_right * static_cast<f32>(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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue