From 7a470b2e174584d1d62ea5ebe713fea9c18beb6c Mon Sep 17 00:00:00 2001 From: Evan Pezent Date: Thu, 7 Jul 2022 20:27:24 -0500 Subject: [PATCH] add ImPlotAxisFlags_NoSideSwitch and ImPlotAxisFlags_NoHighlight --- implot.cpp | 8 ++++++-- implot.h | 22 ++++++++++++---------- implot_demo.cpp | 11 ++++++++--- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/implot.cpp b/implot.cpp index b167caa..e18e71d 100644 --- a/implot.cpp +++ b/implot.cpp @@ -2640,7 +2640,7 @@ void SetupFinish() { ImPlotAxis& ax = plot.XAxis(i); if (!ax.Enabled) continue; - if ((ax.Hovered || ax.Held) && !plot.Held) + if ((ax.Hovered || ax.Held) && !plot.Held && !ImHasFlag(ax.Flags, ImPlotAxisFlags_NoHighlight)) DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov); else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) { DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi); @@ -2679,7 +2679,7 @@ void SetupFinish() { ImPlotAxis& ax = plot.YAxis(i); if (!ax.Enabled) continue; - if ((ax.Hovered || ax.Held) && !plot.Held) + if ((ax.Hovered || ax.Held) && !plot.Held && !ImHasFlag(ax.Flags, ImPlotAxisFlags_NoHighlight)) DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov); else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) { DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi); @@ -2939,6 +2939,8 @@ void EndPlot() { trigger_rect.Expand(-10); for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { ImPlotAxis& x_axis = plot.XAxis(i); + if (ImHasFlag(x_axis.Flags, ImPlotAxisFlags_NoSideSwitch)) + continue; if (x_axis.Held && plot.PlotRect.Contains(mouse_pos)) { const bool opp = ImHasFlag(x_axis.Flags, ImPlotAxisFlags_Opposite); if (!opp) { @@ -2961,6 +2963,8 @@ void EndPlot() { } for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { ImPlotAxis& y_axis = plot.YAxis(i); + if (ImHasFlag(y_axis.Flags, ImPlotAxisFlags_NoSideSwitch)) + continue; if (y_axis.Held && plot.PlotRect.Contains(mouse_pos)) { const bool opp = ImHasFlag(y_axis.Flags, ImPlotAxisFlags_Opposite); if (!opp) { diff --git a/implot.h b/implot.h index 4a08f3b..f4174eb 100644 --- a/implot.h +++ b/implot.h @@ -145,20 +145,22 @@ enum ImPlotFlags_ { // Options for plot axes (see SetupAxis). enum ImPlotAxisFlags_ { ImPlotAxisFlags_None = 0, // default - ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels also hidden if the supplied string name is NULL) + ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels are also hidden if the supplied string name is NULL) ImPlotAxisFlags_NoGridLines = 1 << 1, // no grid lines will be displayed ImPlotAxisFlags_NoTickMarks = 1 << 2, // no tick marks will be displayed ImPlotAxisFlags_NoTickLabels = 1 << 3, // no text labels will be displayed ImPlotAxisFlags_NoInitialFit = 1 << 4, // axis will not be initially fit to data extents on the first rendered frame ImPlotAxisFlags_NoMenus = 1 << 5, // the user will not be able to open context menus with right-click - ImPlotAxisFlags_Opposite = 1 << 6, // axis ticks and labels will be rendered on the conventionally opposite side (i.e, right or top) - ImPlotAxisFlags_Foreground = 1 << 7, // grid lines will be displayed in the foreground (i.e. on top of data) in stead of the background - ImPlotAxisFlags_Invert = 1 << 8, // the axis will be inverted - ImPlotAxisFlags_AutoFit = 1 << 9, // axis will be auto-fitting to data extents - ImPlotAxisFlags_RangeFit = 1 << 10, // axis will only fit points if the point is in the visible range of the **orthogonal** axis - ImPlotAxisFlags_PanStretch = 1 << 11, // panning in a locked or constrained state will cause the axis to stretch if possible - ImPlotAxisFlags_LockMin = 1 << 12, // the axis minimum value will be locked when panning/zooming - ImPlotAxisFlags_LockMax = 1 << 13, // the axis maximum value will be locked when panning/zooming + ImPlotAxisFlags_NoSideSwitch = 1 << 6, // the user will not be able to switch the axis side by dragging it + ImPlotAxisFlags_NoHighlight = 1 << 7, // the axis will not have its background highlighted when hovered or held + ImPlotAxisFlags_Opposite = 1 << 8, // axis ticks and labels will be rendered on the conventionally opposite side (i.e, right or top) + ImPlotAxisFlags_Foreground = 1 << 9, // grid lines will be displayed in the foreground (i.e. on top of data) instead of the background + ImPlotAxisFlags_Invert = 1 << 10, // the axis will be inverted + ImPlotAxisFlags_AutoFit = 1 << 11, // axis will be auto-fitting to data extents + ImPlotAxisFlags_RangeFit = 1 << 12, // axis will only fit points if the point is in the visible range of the **orthogonal** axis + ImPlotAxisFlags_PanStretch = 1 << 13, // panning in a locked or constrained state will cause the axis to stretch if possible + ImPlotAxisFlags_LockMin = 1 << 14, // the axis minimum value will be locked when panning/zooming + ImPlotAxisFlags_LockMax = 1 << 15, // the axis maximum value will be locked when panning/zooming ImPlotAxisFlags_Lock = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax, ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels, ImPlotAxisFlags_AuxDefault = ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_Opposite @@ -923,7 +925,7 @@ IMPLOT_API bool DragLineX(int id, double* x, const ImVec4& col, float thickness // Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text. IMPLOT_API bool DragLineY(int id, double* y, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags=0); // Shows a draggable and resizeable rectangle. -IMPLOT_API bool DragRect(int id, double* x_min, double* y_min, double* x_max, double* y_max, const ImVec4& col, ImPlotDragToolFlags flags=0); +IMPLOT_API bool DragRect(int id, double* x1, double* y1, double* x2, double* y2, const ImVec4& col, ImPlotDragToolFlags flags=0); // Shows an annotation callout at a chosen point. Clamping keeps annotations in the plot area. Annotations are always rendered on top. IMPLOT_API void Annotation(double x, double y, const ImVec4& col, const ImVec2& pix_offset, bool clamp, bool round = false); diff --git a/implot_demo.cpp b/implot_demo.cpp index d0b9227..c828b4d 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -1508,11 +1508,16 @@ void Demo_DragRects() { //----------------------------------------------------------------------------- -ImPlotPoint FindCentroid(const ImVector& data, ImPlotRect& bounds, int& cnt) { +ImPlotPoint FindCentroid(const ImVector& data, const ImPlotRect& bounds, int& cnt) { cnt = 0; ImPlotPoint avg; + ImPlotRect bounds_fixed; + bounds_fixed.X.Min = bounds.X.Min < bounds.X.Max ? bounds.X.Min : bounds.X.Max; + bounds_fixed.X.Max = bounds.X.Min < bounds.X.Max ? bounds.X.Max : bounds.X.Min; + bounds_fixed.Y.Min = bounds.Y.Min < bounds.Y.Max ? bounds.Y.Min : bounds.Y.Max; + bounds_fixed.Y.Max = bounds.Y.Min < bounds.Y.Max ? bounds.Y.Max : bounds.Y.Min; for (int i = 0; i < data.size(); ++i) { - if (bounds.Contains(data[i].x, data[i].y)) { + if (bounds_fixed.Contains(data[i].x, data[i].y)) { avg.x += data[i].x; avg.y += data[i].y; cnt++; @@ -1702,7 +1707,7 @@ void Demo_DragAndDrop() { ImGui::SameLine(); ImGui::BeginChild("DND_RIGHT",ImVec2(-1,400)); // plot 1 (time series) - ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines; + ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoHighlight; if (ImPlot::BeginPlot("##DND1", ImVec2(-1,195))) { ImPlot::SetupAxis(ImAxis_X1, NULL, flags|ImPlotAxisFlags_Lock); ImPlot::SetupAxis(ImAxis_Y1, "[drop here]", flags);