Skip to content

Commit d65a2be

Browse files
feat: add vertical and horizontal markers (#702)
* Add Vertical and Horizontal markers * feat: centralize markers/texts in marker demo --------- Co-authored-by: Breno Cunha Queiroz <brenocq.br@gmail.com>
1 parent 63cf6c7 commit d65a2be

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

implot.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ const char* GetMarkerName(ImPlotMarker marker) {
308308
case ImPlotMarker_Cross: return "Cross";
309309
case ImPlotMarker_Plus: return "Plus";
310310
case ImPlotMarker_Asterisk: return "Asterisk";
311+
case ImPlotMarker_Vertical: return "Vertical";
312+
case ImPlotMarker_Horizontal: return "Horizontal";
311313
default: return "";
312314
}
313315
}

implot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ enum ImPlotMarker_ {
448448
ImPlotMarker_Cross, // a cross marker (not fill-able)
449449
ImPlotMarker_Plus, // a plus marker (not fill-able)
450450
ImPlotMarker_Asterisk, // a asterisk marker (not fill-able)
451+
ImPlotMarker_Vertical, // a vertical line marker (not fill-able)
452+
ImPlotMarker_Horizontal, // a horizontal line marker (not fill-able)
451453
ImPlotMarker_COUNT
452454
};
453455

implot_demo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ void Demo_MarkersAndText() {
10781078
if (ImPlot::BeginPlot("##MarkerStyles", ImVec2(-1,0), ImPlotFlags_CanvasOnly)) {
10791079

10801080
ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations);
1081-
ImPlot::SetupAxesLimits(0, 10, 0, 12);
1081+
ImPlot::SetupAxesLimits(0, 10, -2, 12);
10821082

10831083
ImS8 xs[2] = {1,4};
10841084
ImS8 ys[2] = {10,11};
@@ -1101,11 +1101,11 @@ void Demo_MarkersAndText() {
11011101
ys[0]--; ys[1]--;
11021102
}
11031103

1104-
ImPlot::PlotText("Filled Markers", 2.5f, 6.0f);
1105-
ImPlot::PlotText("Open Markers", 7.5f, 6.0f);
1104+
ImPlot::PlotText("Filled Markers", 2.5f, 5.0f);
1105+
ImPlot::PlotText("Open Markers", 7.5f, 5.0f);
11061106

11071107
ImPlot::PushStyleColor(ImPlotCol_InlayText, ImVec4(1,0,1,1));
1108-
ImPlot::PlotText("Vertical Text", 5.0f, 6.0f, ImVec2(0,0), {ImPlotProp_Flags, ImPlotTextFlags_Vertical});
1108+
ImPlot::PlotText("Vertical Text", 5.0f, 5.0f, ImVec2(0,0), {ImPlotProp_Flags, ImPlotTextFlags_Vertical});
11091109
ImPlot::PopStyleColor();
11101110

11111111
ImPlot::EndPlot();

implot_items.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,8 @@ constexpr ImVec2 MARKER_LINE_RIGHT[6] = {ImVec2(1,0), ImVec2(-0.5, SQRT_3_2)
18211821
constexpr ImVec2 MARKER_LINE_ASTERISK[6] = {ImVec2(-SQRT_3_2, -0.5f), ImVec2(SQRT_3_2, 0.5f), ImVec2(-SQRT_3_2, 0.5f), ImVec2(SQRT_3_2, -0.5f), ImVec2(0, -1), ImVec2(0, 1)};
18221822
constexpr ImVec2 MARKER_LINE_PLUS[4] = {ImVec2(-1, 0), ImVec2(1, 0), ImVec2(0, -1), ImVec2(0, 1)};
18231823
constexpr ImVec2 MARKER_LINE_CROSS[4] = {ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
1824+
constexpr ImVec2 MARKER_LINE_VERTICAL[2] = {ImVec2(0, -1), ImVec2(0, 1)};
1825+
constexpr ImVec2 MARKER_LINE_HORIZONTAL[2] = {ImVec2(-1, 0), ImVec2(1, 0)};
18241826

18251827
template <typename _Getter, typename _GetterFillColor, typename _GetterLineColor, typename _GetterSize>
18261828
void RenderMarkers(const _Getter& getter, ImPlotMarker marker, bool rend_fill, const _GetterFillColor& col_fill_getter, bool rend_line, const _GetterLineColor& col_line_getter, const _GetterSize& size_getter, float weight) {
@@ -1847,6 +1849,8 @@ void RenderMarkers(const _Getter& getter, ImPlotMarker marker, bool rend_fill, c
18471849
case ImPlotMarker_Asterisk : RenderPrimitives3<RendererMarkersLine>(getter,col_line_getter,size_getter,MARKER_LINE_ASTERISK,6,weight); break;
18481850
case ImPlotMarker_Plus : RenderPrimitives3<RendererMarkersLine>(getter,col_line_getter,size_getter,MARKER_LINE_PLUS, 4,weight); break;
18491851
case ImPlotMarker_Cross : RenderPrimitives3<RendererMarkersLine>(getter,col_line_getter,size_getter,MARKER_LINE_CROSS, 4,weight); break;
1852+
case ImPlotMarker_Vertical : RenderPrimitives3<RendererMarkersLine>(getter,col_line_getter,size_getter,MARKER_LINE_VERTICAL,2,weight); break;
1853+
case ImPlotMarker_Horizontal: RenderPrimitives3<RendererMarkersLine>(getter,col_line_getter,size_getter,MARKER_LINE_HORIZONTAL,2,weight); break;
18501854
}
18511855
}
18521856
}

0 commit comments

Comments
 (0)