From 24522b28862053a4831bb42a9d4f45cf376c036d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catal=C3=A3o?= Date: Wed, 16 Sep 2026 22:01:22 +0100 Subject: [PATCH 1/2] fix: DragRect can no longer be clicked outside the plot area --- implot.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/implot.cpp b/implot.cpp index c4485f40..cc14bf1c 100644 --- a/implot.cpp +++ b/implot.cpp @@ -4143,6 +4143,7 @@ bool DragRect(int n_id, double* x_min, double* y_min, double* x_max, double* y_m ImVec2 pc = PlotToPixels((*x_min+*x_max)/2,(*y_min+*y_max)/2,IMPLOT_AUTO,IMPLOT_AUTO); ImRect rect(ImMin(p[0],p[2]),ImMax(p[0],p[2])); ImRect rect_grab = rect; rect_grab.Expand(DRAG_GRAB_HALF_SIZE); + rect_grab.ClipWithFull(GImPlot->CurrentPlot->PlotRect); ImGuiMouseCursor cur[4]; if (show_curs) { @@ -4167,6 +4168,7 @@ bool DragRect(int n_id, double* x_min, double* y_min, double* x_max, double* y_m if (input) { // middle point ImRect b_rect(pc.x-DRAG_GRAB_HALF_SIZE,pc.y-DRAG_GRAB_HALF_SIZE,pc.x+DRAG_GRAB_HALF_SIZE,pc.y+DRAG_GRAB_HALF_SIZE); + b_rect.ClipWithFull(GImPlot->CurrentPlot->PlotRect); clicked = ImGui::ButtonBehavior(b_rect,id,&hovered,&held); if (out_clicked) *out_clicked = clicked; if (out_hovered) *out_hovered = hovered; @@ -4188,6 +4190,7 @@ bool DragRect(int n_id, double* x_min, double* y_min, double* x_max, double* y_m for (int i = 0; i < 4; ++i) { // points ImRect b_rect(p[i].x - DRAG_GRAB_HALF_SIZE, p[i].y - DRAG_GRAB_HALF_SIZE, p[i].x + DRAG_GRAB_HALF_SIZE, p[i].y + DRAG_GRAB_HALF_SIZE); + b_rect.ClipWithFull(GImPlot->CurrentPlot->PlotRect); ImGuiID p_id = id + i + 1; ImGui::KeepAliveID(p_id); if (input) { @@ -4210,6 +4213,7 @@ bool DragRect(int n_id, double* x_min, double* y_min, double* x_max, double* y_m ImVec2 e_max = ImMax(p[i],p[(i+1)%4]); b_rect = h[i] ? ImRect(e_min.x + DRAG_GRAB_HALF_SIZE, e_min.y - DRAG_GRAB_HALF_SIZE, e_max.x - DRAG_GRAB_HALF_SIZE, e_max.y + DRAG_GRAB_HALF_SIZE) : ImRect(e_min.x - DRAG_GRAB_HALF_SIZE, e_min.y + DRAG_GRAB_HALF_SIZE, e_max.x + DRAG_GRAB_HALF_SIZE, e_max.y - DRAG_GRAB_HALF_SIZE); + b_rect.ClipWithFull(GImPlot->CurrentPlot->PlotRect); ImGuiID e_id = id + i + 5; ImGui::KeepAliveID(e_id); if (input) { From a85a2cbc158a0d159b5ebd0c6344d7e480d76f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catal=C3=A3o?= Date: Wed, 16 Sep 2026 22:45:56 +0100 Subject: [PATCH 2/2] fix: DragPoint and DragLines can no longer be clicked outside the plot area --- implot.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/implot.cpp b/implot.cpp index cc14bf1c..d392c703 100644 --- a/implot.cpp +++ b/implot.cpp @@ -3984,6 +3984,7 @@ bool DragPoint(int n_id, double* x, double* y, const ImVec4& col, float radius, ImGui::KeepAliveID(id); if (input) { + rect.ClipWithFull(GImPlot->CurrentPlot->PlotRect); bool clicked = ImGui::ButtonBehavior(rect,id,&hovered,&held); if (out_clicked) *out_clicked = clicked; if (out_hovered) *out_hovered = hovered; @@ -4033,6 +4034,7 @@ bool DragLineX(int n_id, double* value, const ImVec4& col, float thickness, ImPl ImGui::KeepAliveID(id); if (input) { + rect.ClipWithFull(GImPlot->CurrentPlot->PlotRect); bool clicked = ImGui::ButtonBehavior(rect,id,&hovered,&held); if (out_clicked) *out_clicked = clicked; if (out_hovered) *out_hovered = hovered; @@ -4089,6 +4091,7 @@ bool DragLineY(int n_id, double* value, const ImVec4& col, float thickness, ImPl ImGui::KeepAliveID(id); if (input) { + rect.ClipWithFull(GImPlot->CurrentPlot->PlotRect); bool clicked = ImGui::ButtonBehavior(rect,id,&hovered,&held); if (out_clicked) *out_clicked = clicked; if (out_hovered) *out_hovered = hovered;