| 2488 | //----------------------------------------------------------------------------- |
| 2489 | |
| 2490 | void Demo_CustomDataAndGetters() { |
| 2491 | IMGUI_DEMO_MARKER("Custom/Custom Data and Getters"); |
| 2492 | ImGui::BulletText("You can plot custom structs using the stride feature."); |
| 2493 | ImGui::BulletText("Most plotters can also be passed a function pointer for getting data."); |
| 2494 | ImGui::Indent(); |
| 2495 | ImGui::BulletText("You can optionally pass user data to be given to your getter function."); |
| 2496 | ImGui::BulletText("C++ lambdas can be passed as function pointers as well!"); |
| 2497 | ImGui::Unindent(); |
| 2498 | |
| 2499 | MyImPlot::Vector2f vec2_data[2] = { MyImPlot::Vector2f(0,0), MyImPlot::Vector2f(1,1) }; |
| 2500 | |
| 2501 | if (ImPlot::BeginPlot("##Custom Data")) { |
| 2502 | |
| 2503 | // custom structs using stride example: |
| 2504 | ImPlot::PlotLine("Vector2f", &vec2_data[0].x, &vec2_data[0].y, 2, {ImPlotProp_Stride, sizeof(MyImPlot::Vector2f)}); |
| 2505 | |
| 2506 | // custom getter example 1: |
| 2507 | ImPlot::PlotLineG("Spiral", MyImPlot::Spiral, nullptr, 1000); |
| 2508 | |
| 2509 | // custom getter example 2: |
| 2510 | static MyImPlot::WaveData data1(0.001, 0.2, 2, 0.75); |
| 2511 | static MyImPlot::WaveData data2(0.001, 0.2, 4, 0.25); |
| 2512 | ImPlot::PlotLineG("Waves", MyImPlot::SineWave, &data1, 1000); |
| 2513 | ImPlot::PlotLineG("Waves", MyImPlot::SawWave, &data2, 1000); |
| 2514 | ImPlot::PlotShadedG("Waves", MyImPlot::SineWave, &data1, MyImPlot::SawWave, &data2, 1000, {ImPlotProp_FillAlpha, 0.25f}); |
| 2515 | |
| 2516 | // you can also pass C++ lambdas: |
| 2517 | // auto lambda = [](void* data, int idx) { ... return ImPlotPoint(x,y); }; |
| 2518 | // ImPlot::PlotLine("My Lambda", lambda, data, 1000); |
| 2519 | |
| 2520 | ImPlot::EndPlot(); |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | //----------------------------------------------------------------------------- |
| 2525 |
nothing calls this directly
no test coverage detected