| 2619 | //----------------------------------------------------------------------------- |
| 2620 | |
| 2621 | void Demo_LegendPopups() { |
| 2622 | IMGUI_DEMO_MARKER("Tools/Legend Popups"); |
| 2623 | ImGui::BulletText("You can implement legend context menus to inject per-item controls and widgets."); |
| 2624 | ImGui::BulletText("Right click the legend label/icon to edit custom item attributes."); |
| 2625 | |
| 2626 | static float frequency = 0.1f; |
| 2627 | static float amplitude = 0.5f; |
| 2628 | static ImVec4 color = ImVec4(1,1,0,1); |
| 2629 | static float alpha = 1.0f; |
| 2630 | static bool line = false; |
| 2631 | static float thickness = 1; |
| 2632 | static bool markers = false; |
| 2633 | static bool shaded = false; |
| 2634 | |
| 2635 | static float vals[101]; |
| 2636 | for (int i = 0; i < 101; ++i) |
| 2637 | vals[i] = amplitude * sinf(frequency * i); |
| 2638 | |
| 2639 | if (ImPlot::BeginPlot("Right Click the Legend")) { |
| 2640 | ImPlot::SetupAxesLimits(0,100,-1,1); |
| 2641 | // rendering logic |
| 2642 | if (!line) { |
| 2643 | ImPlot::PlotBars("Right Click Me", vals, 101, 0.67, 0, { |
| 2644 | ImPlotProp_FillAlpha, alpha, |
| 2645 | ImPlotProp_FillColor, color |
| 2646 | }); |
| 2647 | } |
| 2648 | else { |
| 2649 | ImPlot::PlotLine("Right Click Me", vals, 101, 1, 0, { |
| 2650 | ImPlotProp_LineColor, color, |
| 2651 | ImPlotProp_LineWeight, thickness |
| 2652 | }); |
| 2653 | if (markers) { |
| 2654 | ImPlot::PlotScatter("Right Click Me", vals, 101, 1, 0, { |
| 2655 | ImPlotProp_Marker, ImPlotMarker_Square, |
| 2656 | ImPlotProp_LineColor, color |
| 2657 | }); |
| 2658 | } |
| 2659 | if (shaded) { |
| 2660 | ImPlot::PlotShaded("Right Click Me",vals,101, 0, 1, 0, { |
| 2661 | ImPlotProp_FillAlpha, alpha, |
| 2662 | }); |
| 2663 | } |
| 2664 | } |
| 2665 | // custom legend context menu |
| 2666 | if (ImPlot::BeginLegendPopup("Right Click Me")) { |
| 2667 | ImGui::SliderFloat("Frequency",&frequency,0,1,"%0.2f"); |
| 2668 | ImGui::SliderFloat("Amplitude",&litude,0,1,"%0.2f"); |
| 2669 | ImGui::Separator(); |
| 2670 | ImGui::ColorEdit3("Color",&color.x); |
| 2671 | ImGui::SliderFloat("Transparency",&alpha,0,1,"%.2f"); |
| 2672 | ImGui::Checkbox("Line Plot", &line); |
| 2673 | if (line) { |
| 2674 | ImGui::SliderFloat("Thickness", &thickness, 0, 5); |
| 2675 | ImGui::Checkbox("Markers", &markers); |
| 2676 | ImGui::Checkbox("Shaded",&shaded); |
| 2677 | } |
| 2678 | ImPlot::EndLegendPopup(); |
nothing calls this directly
no test coverage detected