mirror of
https://github.com/gwm17/implot.git
synced 2024-11-26 20:28:50 -05:00
prevent guides drag outside plot
This commit is contained in:
parent
4ed7d01637
commit
0e9ceb6bc0
|
@ -2509,9 +2509,9 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
|
||||||
ImGui::SetCursorScreenPos(new_cursor_pos);
|
ImGui::SetCursorScreenPos(new_cursor_pos);
|
||||||
ImGui::InvisibleButton(id, ImVec2(xr - xl, grab_size));
|
ImGui::InvisibleButton(id, ImVec2(xr - xl, grab_size));
|
||||||
ImGui::SetCursorScreenPos(old_cursor_pos);
|
ImGui::SetCursorScreenPos(old_cursor_pos);
|
||||||
|
int yax = GetCurrentYAxis();
|
||||||
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
|
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
|
||||||
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
|
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
|
||||||
int yax = GetCurrentYAxis();
|
|
||||||
double range_y = gp.YTicks[yax].Size > 1 ? (gp.YTicks[yax].Ticks[1].PlotPos - gp.YTicks[yax].Ticks[0].PlotPos) : gp.CurrentPlot->YAxis[yax].Range.Size();
|
double range_y = gp.YTicks[yax].Size > 1 ? (gp.YTicks[yax].Ticks[1].PlotPos - gp.YTicks[yax].Ticks[0].PlotPos) : gp.CurrentPlot->YAxis[yax].Range.Size();
|
||||||
char buf[32];
|
char buf[32];
|
||||||
snprintf(buf, 32, "%s = %.*f", id, Precision(range_y), *value);
|
snprintf(buf, 32, "%s = %.*f", id, Precision(range_y), *value);
|
||||||
|
@ -2531,6 +2531,7 @@ bool HorizontalGuide(const char* id, double* value, const ImVec4& col, float thi
|
||||||
bool dragging = false;
|
bool dragging = false;
|
||||||
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {
|
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {
|
||||||
*value = ImPlot::GetPlotMousePos().y;
|
*value = ImPlot::GetPlotMousePos().y;
|
||||||
|
*value = ImClamp(*value, gp.Y[yax].Axis->Range.Min, gp.Y[yax].Axis->Range.Max);
|
||||||
dragging = true;
|
dragging = true;
|
||||||
}
|
}
|
||||||
return dragging;
|
return dragging;
|
||||||
|
@ -2577,6 +2578,7 @@ bool VerticalGuide(const char* id, double* value, const ImVec4& col, float thick
|
||||||
bool dragging = false;
|
bool dragging = false;
|
||||||
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {
|
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {
|
||||||
*value = ImPlot::GetPlotMousePos().x;
|
*value = ImPlot::GetPlotMousePos().x;
|
||||||
|
*value = ImClamp(*value, gp.X.Axis->Range.Min, gp.X.Axis->Range.Max);
|
||||||
dragging = true;
|
dragging = true;
|
||||||
}
|
}
|
||||||
return dragging;
|
return dragging;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user