MCPcopy Create free account
hub / github.com/brenocq/implot3d / RenderTickLabels

Function RenderTickLabels

implot3d.cpp:1013–1088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1011}
1012
1013void RenderTickLabels(ImDrawList* draw_list, const ImPlot3DPlot& plot, const ImPlot3DPoint* corners, const ImVec2* corners_pix,
1014 const int axis_corners[3][2]) {
1015 ImU32 col_tick_txt = GetStyleColorU32(ImPlot3DCol_AxisText);
1016
1017 for (int a = 0; a < 3; a++) {
1018 const ImPlot3DAxis& axis = plot.Axes[a];
1019 if (ImPlot3D::ImHasFlag(axis.Flags, ImPlot3DAxisFlags_NoTickLabels))
1020 continue;
1021
1022 // Corner indices for this axis
1023 int idx0 = axis_corners[a][0];
1024 int idx1 = axis_corners[a][1];
1025
1026 // If normal to the 2D plot, ignore the ticks
1027 if (idx0 == idx1)
1028 continue;
1029
1030 // Start and end points of the axis in plot and screen space
1031 ImPlot3DPoint axis_start = corners[idx0];
1032 ImPlot3DPoint axis_dir = corners[idx1] - axis_start;
1033 ImVec2 axis_start_pix = corners_pix[idx0];
1034 ImVec2 axis_end_pix = corners_pix[idx1];
1035
1036 // Screen space axis direction (normalized), needed for text angle
1037 ImVec2 axis_screen_dir = axis_end_pix - axis_start_pix;
1038 float axis_length = ImSqrt(ImLengthSqr(axis_screen_dir));
1039 axis_screen_dir = (axis_length > 0.0f) ? axis_screen_dir / axis_length : ImVec2(1.0f, 0.0f);
1040
1041 // Outward perpendicular direction and label offset
1042 ImVec2 outward_dir = ComputeEdgeOutwardDir(axis_start_pix, axis_end_pix, PlotToPixels(plot.RangeCenter()));
1043 float max_tick_extent = ComputeMaxTickLabelExtent(axis);
1044 ImVec2 offset_pix = outward_dir * (max_tick_extent + AXIS_TICK_INNER_PAD);
1045
1046 // Compute angle perpendicular to axis in screen space
1047 float angle = atan2f(-axis_screen_dir.y, axis_screen_dir.x) + IM_PI * 0.5f;
1048
1049 // Normalize angle to be between -π and π
1050 if (angle > IM_PI)
1051 angle -= 2 * IM_PI;
1052 if (angle < -IM_PI)
1053 angle += 2 * IM_PI;
1054
1055 // Adjust angle to keep labels upright
1056 if (angle > IM_PI * 0.5f)
1057 angle -= IM_PI;
1058 if (angle < -IM_PI * 0.5f)
1059 angle += IM_PI;
1060
1061 // Loop over ticks
1062 for (int t = 0; t < axis.Ticker.TickCount(); ++t) {
1063 const ImPlot3DTick& tick = axis.Ticker.Ticks[t];
1064 if (!tick.ShowLabel)
1065 continue;
1066
1067 // Compute position along the axis
1068 double t_axis = (tick.PlotPos - axis.Range.Min) / (axis.Range.Max - axis.Range.Min);
1069
1070 // Skip ticks that are out of range

Callers 1

RenderPlotBoxFunction · 0.85

Calls 9

GetStyleColorU32Function · 0.85
ImHasFlagFunction · 0.85
ComputeEdgeOutwardDirFunction · 0.85
PlotToPixelsFunction · 0.85
AddTextRotatedFunction · 0.85
RangeCenterMethod · 0.80
TickCountMethod · 0.80
GetTextMethod · 0.80

Tested by

no test coverage detected