| 2791 | } |
| 2792 | |
| 2793 | void SetupLock() { |
| 2794 | ImPlot3DContext& gp = *GImPlot3D; |
| 2795 | IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr, "SetupLock() needs to be called between BeginPlot() and EndPlot()!"); |
| 2796 | ImPlot3DPlot& plot = *gp.CurrentPlot; |
| 2797 | if (plot.SetupLocked) |
| 2798 | return; |
| 2799 | // Lock setup |
| 2800 | plot.SetupLocked = true; |
| 2801 | |
| 2802 | ImGuiContext& g = *GImGui; |
| 2803 | ImGuiWindow* window = g.CurrentWindow; |
| 2804 | ImDrawList* draw_list = window->DrawList; |
| 2805 | |
| 2806 | // Set default formatter/locator |
| 2807 | for (int i = 0; i < 3; i++) { |
| 2808 | ImPlot3DAxis& axis = plot.Axes[i]; |
| 2809 | |
| 2810 | // Set formatter |
| 2811 | if (axis.Formatter == nullptr) { |
| 2812 | axis.Formatter = Formatter_Default; |
| 2813 | if (axis.FormatterData == nullptr) |
| 2814 | axis.FormatterData = (void*)IMPLOT3D_LABEL_FORMAT; |
| 2815 | } |
| 2816 | |
| 2817 | // Set locator |
| 2818 | if (axis.Locator == nullptr) |
| 2819 | axis.Locator = Locator_Default; |
| 2820 | } |
| 2821 | |
| 2822 | // Draw frame background |
| 2823 | ImU32 f_bg_color = GetStyleColorU32(ImPlot3DCol_FrameBg); |
| 2824 | draw_list->AddRectFilled(plot.FrameRect.Min, plot.FrameRect.Max, f_bg_color); |
| 2825 | |
| 2826 | // Compute canvas/canvas rectangle |
| 2827 | plot.CanvasRect = ImRect(plot.FrameRect.Min + gp.Style.PlotPadding, plot.FrameRect.Max - gp.Style.PlotPadding); |
| 2828 | plot.PlotRect = plot.CanvasRect; |
| 2829 | |
| 2830 | // Apply equal axis aspect constraint if not approximately equal |
| 2831 | const bool axis_equal = ImHasFlag(plot.Flags, ImPlot3DFlags_Equal); |
| 2832 | if (axis_equal) { |
| 2833 | double xar = plot.Axes[ImAxis3D_X].GetAspect(); |
| 2834 | double yar = plot.Axes[ImAxis3D_Y].GetAspect(); |
| 2835 | double zar = plot.Axes[ImAxis3D_Z].GetAspect(); |
| 2836 | if (!ImAlmostEqual(xar, yar) || !ImAlmostEqual(xar, zar)) { |
| 2837 | double aspect = (xar + yar + zar) / 3.0; |
| 2838 | plot.Axes[ImAxis3D_X].SetAspect(aspect); |
| 2839 | plot.Axes[ImAxis3D_Y].SetAspect(aspect); |
| 2840 | plot.Axes[ImAxis3D_Z].SetAspect(aspect); |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | // Compute ticks |
| 2845 | for (int i = 0; i < 3; i++) { |
| 2846 | ImPlot3DAxis& axis = plot.Axes[i]; |
| 2847 | if (axis.ShowDefaultTicks) { |
| 2848 | float pixels = float(plot.GetViewScale() * axis.NDCScale); |
| 2849 | axis.Locator(axis.Ticker, axis.Range, pixels, axis.Formatter, axis.FormatterData); |
| 2850 | } |
no test coverage detected