From 140dd2bd8a3db711a9dbced71545b070a2a146ee Mon Sep 17 00:00:00 2001 From: ozlb Date: Mon, 13 Jul 2020 06:44:51 +0200 Subject: [PATCH] IsPlotItemHighlight Returns true if plot item is highlight --- implot.cpp | 16 +++++++++++++++- implot.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/implot.cpp b/implot.cpp index e15342e..0e2456b 100644 --- a/implot.cpp +++ b/implot.cpp @@ -195,7 +195,10 @@ inline T Remap(T x, T x0, T x1, T y0, T y1) { // Returns always positive modulo inline int PosMod(int l, int r) { - return (l % r + r) % r; + if (r == 0) + return 0; + else + return (l % r + r) % r; } // Returns the intersection point of two lines A and B (assumes they are not parallel!) @@ -1935,6 +1938,17 @@ ImPlotLimits GetPlotQuery(int y_axis_in) { return result; } +bool IsPlotItemHighlight(const char* label_id) { + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotItemHighlight() needs to be called between BeginPlot() and EndPlot()!"); + + ImGuiID id = ImGui::GetID(label_id); + ImPlotItem* item = gp.CurrentPlot->Items.GetOrAddByKey(id); + if (item && item->Highlight) + return true; + else + return false; +} + //----------------------------------------------------------------------------- // STYLING //----------------------------------------------------------------------------- diff --git a/implot.h b/implot.h index b56455e..a13e625 100644 --- a/implot.h +++ b/implot.h @@ -298,6 +298,8 @@ ImPlotLimits GetPlotLimits(int y_axis = -1); bool IsPlotQueried(); // Returns the current or most recent plot query bounds. ImPlotLimits GetPlotQuery(int y_axis = -1); +// Returns true if plot item is highlight +bool IsPlotItemHighlight(const char* label_id); //----------------------------------------------------------------------------- // Plot Input Mapping