epezent / implot

Immediate Mode Plotting
MIT License
4.64k stars 516 forks source link

Lambda support is advertised and documented, but apparently not implemented. #446

Open ATell-SoundTheory opened 1 year ago

ATell-SoundTheory commented 1 year ago

In ImPlot 0.14, PlotLineG (or any other getter-enabled function) does not implement a lambda getter argument. The only getter defined is a c-style function pointer named ImPlotGetter and lambdas are not convertible to c-style function pointers. Is this an oversight in the documentation or the implementation?

nuuSolutions commented 1 year ago

they are 'convertible' when they have this signature: auto my_lambda = [](int idx, void*) { ... } but it confused me as well, and could be improved imo - see #445

ATell-SoundTheory commented 1 year ago

The conversion of non-capturing lambdas to function pointers is a compiler feature though, and not a library feature. So the library de-facto does not support lambdas.

nuuSolutions commented 1 year ago

What would be your use-case? your make lambdas which capture your data and return the transformed data you want to plot? or captureless lambdas taking a data* and index? or third option?

prlw1 commented 12 months ago

Your first option, e.g.,

auto getter = [t, y](int idx, void *unused) -> ImPlotPoint {
                return ImPlotPoint(t[idx], y[idx].x);
};

instead of having to create a struct containing t and y, and passing in a pointer to that struct.