diff --git a/implot.h b/implot.h index def7d32..acdd460 100644 --- a/implot.h +++ b/implot.h @@ -302,13 +302,17 @@ void EndPlot(); //----------------------------------------------------------------------------- // Plots a standard 2D line plot. -void PlotLine(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); -void PlotLine(const char* label_id, const double* values, int count, int offset = 0, int stride = sizeof(double)); -void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); -void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double)); -void PlotLine(const char* label_id, const ImVec2* data, int count, int offset = 0); -void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset = 0); -void PlotLine(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0); +// void PlotLine(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); +// void PlotLine(const char* label_id, const double* values, int count, int offset = 0, int stride = sizeof(double)); +// void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); +// void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double)); +// void PlotLine(const char* label_id, const ImVec2* data, int count, int offset = 0); +// void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset = 0); + +template void PlotLine(const char* label_id, const T* values, int count, int offset = 0, int stride = sizeof(T)); +template void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset = 0, int stride = sizeof(T)); +void PlotLineG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0); + // Plots a standard 2D scatter plot. Default marker is ImPlotMarker_Circle. void PlotScatter(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); diff --git a/implot_demo.cpp b/implot_demo.cpp index 9ea4472..84b67af 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -1063,11 +1063,11 @@ void ShowDemoWindow(bool* p_open) { ImGui::BulletText("You can optionally pass user data to be given to your getter."); ImGui::BulletText("C++ lambdas can be passed as function pointers as well."); if (ImPlot::BeginPlot("##Custom Getters")) { - ImPlot::PlotLine("Spiral", MyImPlot::Spiral, NULL, 1000); + ImPlot::PlotLineG("Spiral", MyImPlot::Spiral, NULL, 1000); static MyImPlot::WaveData data1(0.001, 0.2, 2, 0.75); static MyImPlot::WaveData data2(0.001, 0.2, 4, 0.25); - ImPlot::PlotLine("Waves", MyImPlot::SineWave, &data1, 1000); - ImPlot::PlotLine("Waves", MyImPlot::SawWave, &data2, 1000); + ImPlot::PlotLineG("Waves", MyImPlot::SineWave, &data1, 1000); + ImPlot::PlotLineG("Waves", MyImPlot::SawWave, &data2, 1000); ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); ImPlot::PlotShaded("Waves", MyImPlot::SineWave, &data1, MyImPlot::SawWave, &data2, 1000); ImPlot::PopStyleVar(); diff --git a/implot_items.cpp b/implot_items.cpp index 3c9656c..6594d59 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -851,40 +851,56 @@ inline void PlotLineEx(const char* label_id, Getter getter) { } } -// float -void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) { - GetterYs getter(values,count,offset,stride); +template +void PlotLine(const char* label_id, const T* values, int count, int offset, int stride) { + GetterYs getter(values,count,offset,stride); PlotLineEx(label_id, getter); } -void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); - return PlotLineEx(label_id, getter); -} +template void PlotLine(const char* label_id, const ImS8* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU8* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImS16* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU16* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImS32* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU32* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImS64* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU64* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const float* values, int count, int offset, int stride); +template void PlotLine(const char* label_id, const double* values, int count, int offset, int stride); -void PlotLine(const char* label_id, const ImVec2* data, int count, int offset) { +template <> +void PlotLine(const char* label_id, const ImVec2* data, int count, int offset, int) { GetterImVec2 getter(data, count, offset); return PlotLineEx(label_id, getter); } -// double -void PlotLine(const char* label_id, const double* values, int count, int offset, int stride) { - GetterYs getter(values,count,offset,stride); - PlotLineEx(label_id, getter); -} - -void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); - return PlotLineEx(label_id, getter); -} - -void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset) { +template <> +void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset, int) { GetterImPlotPoint getter(data, count, offset); return PlotLineEx(label_id, getter); } + + +template +void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) { + GetterXsYs getter(xs,ys,count,offset,stride); + return PlotLineEx(label_id, getter); +} + +template void PlotLine(const char* label_id, const ImS8* xs, const ImS8* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU8* xs, const ImU8* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImS16* xs, const ImS16* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU16* xs, const ImU16* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImS32* xs, const ImS32* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU32* xs, const ImU32* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImS64* xs, const ImS64* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const ImU64* xs, const ImU64* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride); +template void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride); + // custom -void PlotLine(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) { +void PlotLineG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) { GetterFuncPtrImPlotPoint getter(getter_func,data, count, offset); return PlotLineEx(label_id, getter); }