1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05:00

initial testing of templates

This commit is contained in:
epezent 2020-09-06 22:34:58 -05:00
parent 902cf44234
commit 930c4b2eb4
3 changed files with 51 additions and 31 deletions

View File

@ -302,13 +302,17 @@ void EndPlot();
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Plots a standard 2D line plot. // 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 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 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 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 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 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, 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);
template <typename T> void PlotLine(const char* label_id, const T* values, int count, int offset = 0, int stride = sizeof(T));
template <typename T> 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. // 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)); void PlotScatter(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float));

View File

@ -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("You can optionally pass user data to be given to your getter.");
ImGui::BulletText("C++ lambdas can be passed as function pointers as well."); ImGui::BulletText("C++ lambdas can be passed as function pointers as well.");
if (ImPlot::BeginPlot("##Custom Getters")) { 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 data1(0.001, 0.2, 2, 0.75);
static MyImPlot::WaveData data2(0.001, 0.2, 4, 0.25); static MyImPlot::WaveData data2(0.001, 0.2, 4, 0.25);
ImPlot::PlotLine("Waves", MyImPlot::SineWave, &data1, 1000); ImPlot::PlotLineG("Waves", MyImPlot::SineWave, &data1, 1000);
ImPlot::PlotLine("Waves", MyImPlot::SawWave, &data2, 1000); ImPlot::PlotLineG("Waves", MyImPlot::SawWave, &data2, 1000);
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
ImPlot::PlotShaded("Waves", MyImPlot::SineWave, &data1, MyImPlot::SawWave, &data2, 1000); ImPlot::PlotShaded("Waves", MyImPlot::SineWave, &data1, MyImPlot::SawWave, &data2, 1000);
ImPlot::PopStyleVar(); ImPlot::PopStyleVar();

View File

@ -851,40 +851,56 @@ inline void PlotLineEx(const char* label_id, Getter getter) {
} }
} }
// float template <typename T>
void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) { void PlotLine(const char* label_id, const T* values, int count, int offset, int stride) {
GetterYs<float> getter(values,count,offset,stride); GetterYs<T> getter(values,count,offset,stride);
PlotLineEx(label_id, getter); PlotLineEx(label_id, getter);
} }
void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { template void PlotLine<ImS8>(const char* label_id, const ImS8* values, int count, int offset, int stride);
GetterXsYs<float> getter(xs,ys,count,offset,stride); template void PlotLine<ImU8>(const char* label_id, const ImU8* values, int count, int offset, int stride);
return PlotLineEx(label_id, getter); template void PlotLine<ImS16>(const char* label_id, const ImS16* values, int count, int offset, int stride);
} template void PlotLine<ImU16>(const char* label_id, const ImU16* values, int count, int offset, int stride);
template void PlotLine<ImS32>(const char* label_id, const ImS32* values, int count, int offset, int stride);
template void PlotLine<ImU32>(const char* label_id, const ImU32* values, int count, int offset, int stride);
template void PlotLine<ImS64>(const char* label_id, const ImS64* values, int count, int offset, int stride);
template void PlotLine<ImU64>(const char* label_id, const ImU64* values, int count, int offset, int stride);
template void PlotLine<float>(const char* label_id, const float* values, int count, int offset, int stride);
template void PlotLine<double>(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<ImVec2>(const char* label_id, const ImVec2* data, int count, int offset, int) {
GetterImVec2 getter(data, count, offset); GetterImVec2 getter(data, count, offset);
return PlotLineEx(label_id, getter); return PlotLineEx(label_id, getter);
} }
// double template <>
void PlotLine(const char* label_id, const double* values, int count, int offset, int stride) { void PlotLine<ImPlotPoint>(const char* label_id, const ImPlotPoint* data, int count, int offset, int) {
GetterYs<double> 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<double> getter(xs,ys,count,offset,stride);
return PlotLineEx(label_id, getter);
}
void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset) {
GetterImPlotPoint getter(data, count, offset); GetterImPlotPoint getter(data, count, offset);
return PlotLineEx(label_id, getter); return PlotLineEx(label_id, getter);
} }
template <typename T>
void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) {
GetterXsYs<T> getter(xs,ys,count,offset,stride);
return PlotLineEx(label_id, getter);
}
template void PlotLine<ImS8>(const char* label_id, const ImS8* xs, const ImS8* ys, int count, int offset, int stride);
template void PlotLine<ImU8>(const char* label_id, const ImU8* xs, const ImU8* ys, int count, int offset, int stride);
template void PlotLine<ImS16>(const char* label_id, const ImS16* xs, const ImS16* ys, int count, int offset, int stride);
template void PlotLine<ImU16>(const char* label_id, const ImU16* xs, const ImU16* ys, int count, int offset, int stride);
template void PlotLine<ImS32>(const char* label_id, const ImS32* xs, const ImS32* ys, int count, int offset, int stride);
template void PlotLine<ImU32>(const char* label_id, const ImU32* xs, const ImU32* ys, int count, int offset, int stride);
template void PlotLine<ImS64>(const char* label_id, const ImS64* xs, const ImS64* ys, int count, int offset, int stride);
template void PlotLine<ImU64>(const char* label_id, const ImU64* xs, const ImU64* ys, int count, int offset, int stride);
template void PlotLine<float>(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride);
template void PlotLine<double>(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride);
// custom // 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); GetterFuncPtrImPlotPoint getter(getter_func,data, count, offset);
return PlotLineEx(label_id, getter); return PlotLineEx(label_id, getter);
} }