From 1911116b3bba6eaf731696c51fc832fd91a28dc6 Mon Sep 17 00:00:00 2001 From: epezent Date: Sat, 19 Sep 2020 21:25:44 -0500 Subject: [PATCH] remove ImPlotStyleVar_AnnotationOffset --- implot.cpp | 19 ++++++++----------- implot.h | 12 +++++------- implot_demo.cpp | 26 ++++++++------------------ 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/implot.cpp b/implot.cpp index 8b8d8a2..6adaf15 100644 --- a/implot.cpp +++ b/implot.cpp @@ -118,7 +118,6 @@ ImPlotStyle::ImPlotStyle() { LegendPadding = ImVec2(10,10); InfoPadding = ImVec2(10,10); AnnotationPadding = ImVec2(2,2); - AnnotationOffset = ImVec2(10,10); PlotMinSize = ImVec2(300,225); ImPlot::StyleColorsAuto(this); @@ -240,7 +239,6 @@ static const ImPlotStyleVarInfo GPlotStyleVarInfo[] = { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImPlotStyle, LegendPadding) }, // ImPlotStyleVar_LegendPadding { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImPlotStyle, InfoPadding) }, // ImPlotStyleVar_InfoPadding { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImPlotStyle, AnnotationPadding) }, // ImPlotStyleVar_AnnotationPadding - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImPlotStyle, AnnotationOffset) }, // ImPlotStyleVar_AnnotationOffset { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImPlotStyle, PlotMinSize) } // ImPlotStyleVar_PlotMinSize }; @@ -2540,31 +2538,31 @@ void AnnotateEx(double x, double y, bool clamp, const ImVec4& col, const ImVec2& gp.Annotations.AppendV(pos, off, bg, fg, clamp, fmt, args); } -void Annotate(double x, double y, const char* fmt, ...) { +void Annotate(double x, double y, const ImVec2& offset, const char* fmt, ...) { va_list args; va_start(args, fmt); - AnnotateEx(x,y,false,ImVec4(0,0,0,0),GImPlot->Style.AnnotationOffset,fmt,args); + AnnotateEx(x,y,false,ImVec4(0,0,0,0),offset,fmt,args); va_end(args); } -void Annotate(double x, double y, const ImVec4& col, const char* fmt, ...) { +void Annotate(double x, double y, const ImVec2& offset, const ImVec4& col, const char* fmt, ...) { va_list args; va_start(args, fmt); - AnnotateEx(x,y,false,col,GImPlot->Style.AnnotationOffset,fmt,args); + AnnotateEx(x,y,false,col,offset,fmt,args); va_end(args); } -void AnnotateClamped(double x, double y, const char* fmt, ...) { +void AnnotateClamped(double x, double y, const ImVec2& offset, const char* fmt, ...) { va_list args; va_start(args, fmt); - AnnotateEx(x,y,true,ImVec4(0,0,0,0),GImPlot->Style.AnnotationOffset,fmt,args); + AnnotateEx(x,y,true,ImVec4(0,0,0,0),offset,fmt,args); va_end(args); } -void AnnotateClamped(double x, double y, const ImVec4& col, const char* fmt, ...) { +void AnnotateClamped(double x, double y, const ImVec2& offset, const ImVec4& col, const char* fmt, ...) { va_list args; va_start(args, fmt); - AnnotateEx(x,y,true,col,GImPlot->Style.AnnotationOffset,fmt,args); + AnnotateEx(x,y,true,col,offset,fmt,args); va_end(args); } @@ -3276,7 +3274,6 @@ void ShowStyleEditor(ImPlotStyle* ref) { ImGui::SliderFloat2("LegendPadding", (float*)&style.LegendPadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("InfoPadding", (float*)&style.InfoPadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("AnnotationPadding", (float*)&style.AnnotationPadding, 0.0f, 5.0f, "%.0f"); - ImGui::SliderFloat2("AnnotationOffset", (float*)&style.AnnotationOffset, -20.0f, 20.0f, "%.0f"); ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Colors")) { diff --git a/implot.h b/implot.h index 3d6c4bc..3424b27 100644 --- a/implot.h +++ b/implot.h @@ -148,7 +148,6 @@ enum ImPlotStyleVar_ { ImPlotStyleVar_LegendPadding, // ImVec2, legend padding from top-left of plot ImPlotStyleVar_InfoPadding, // ImVec2, padding between plot edge and interior info text ImPlotStyleVar_AnnotationPadding, // ImVec2, text padding around annotation labels - ImPlotStyleVar_AnnotationOffset, // ImVec2, annotation label offset in pixels (0,0 will center the label) ImPlotStyleVar_PlotMinSize, // ImVec2, minimum size plot frame can be when shrunk ImPlotStyleVar_COUNT }; @@ -241,7 +240,6 @@ struct ImPlotStyle { ImVec2 LegendPadding; // = 10,10 legend padding from top-left of plot ImVec2 InfoPadding; // = 10,10 padding between plot edge and interior info text ImVec2 AnnotationPadding; // = 2,2 text padding around annotation labels - ImVec2 AnnotationOffset; // = 10,10 annotation label offset in pixels (0,0 will center the label) ImVec2 PlotMinSize; // = 300,225 minimum size plot frame can be when shrunk // colors ImVec4 Colors[ImPlotCol_COUNT]; // array of plot specific colors @@ -466,12 +464,12 @@ IMPLOT_API ImPlotLimits GetPlotQuery(int y_axis = IMPLOT_AUTO); // Plot Tools //----------------------------------------------------------------------------- -// Shows an annotation callout at a chosen point. Annotations can be offset or centered with ImPlotStyleVar_AnnotationOffset. -IMPLOT_API void Annotate(double x, double y, const char* fmt, ...) IM_FMTARGS(3); -IMPLOT_API void Annotate(double x, double y, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(4); +// Shows an annotation callout at a chosen point. +IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4); +IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5); // Same as above, but the annotation will always be clamped to stay inside the plot area. -IMPLOT_API void AnnotateClamped(double x, double y, const char* fmt, ...) IM_FMTARGS(3); -IMPLOT_API void AnnotateClamped(double x, double y, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(4); +IMPLOT_API void AnnotateClamped(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4); +IMPLOT_API void AnnotateClamped(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5); // Shows a draggable vertical guide line at an x-value. #col defaults to ImGuiCol_Text. IMPLOT_API bool DragLineX(const char* id, double* x_value, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1); diff --git a/implot_demo.cpp b/implot_demo.cpp index 697c0dc..b394f54 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -659,7 +659,7 @@ void ShowDemoWindow(bool* p_open) { double t_now = (double)time(0); double y_now = HugeTimeData::GetY(t_now); ImPlot::PlotScatter("Now",&t_now,&y_now,1); - ImPlot::Annotate(t_now,y_now,ImPlot::GetLastItemColor(),"Now"); + ImPlot::Annotate(t_now,y_now,ImVec2(10,10),ImPlot::GetLastItemColor(),"Now"); ImPlot::EndPlot(); } } @@ -867,27 +867,17 @@ void ShowDemoWindow(bool* p_open) { static float p[] = {0.25f, 0.25f, 0.75f, 0.75f, 0.25f}; ImPlot::PlotScatter("##Points",&p[0],&p[1],4); ImVec4 col = GetLastItemColor(); - ImPlot::PushStyleVar(ImPlotStyleVar_AnnotationOffset, ImVec2(-15,15)); - clamp ? ImPlot::AnnotateClamped(0.25,0.25,col,"BL") : ImPlot::Annotate(0.25,0.25,col,"BL"); - ImPlot::PushStyleVar(ImPlotStyleVar_AnnotationOffset, ImVec2(15,15)); - clamp ? ImPlot::AnnotateClamped(0.75,0.25,col,"BR") : ImPlot::Annotate(0.75,0.25,col,"BR"); - ImPlot::PushStyleVar(ImPlotStyleVar_AnnotationOffset, ImVec2(15,-15)); - clamp ? ImPlot::AnnotateClamped(0.75,0.75,col,"TR") : ImPlot::Annotate(0.75,0.75,col,"TR"); - ImPlot::PushStyleVar(ImPlotStyleVar_AnnotationOffset, ImVec2(-15,-15)); - clamp ? ImPlot::AnnotateClamped(0.25,0.75,col,"TL") : ImPlot::Annotate(0.25,0.75,col,"TL"); - ImPlot::PushStyleVar(ImPlotStyleVar_AnnotationOffset, ImVec2(0,0)); - clamp ? ImPlot::AnnotateClamped(0.5,0.5,col,"Center") : ImPlot::Annotate(0.5,0.5,col,"Center"); - ImPlot::PopStyleVar(5); + clamp ? ImPlot::AnnotateClamped(0.25,0.25,ImVec2(-15,15),col,"BL") : ImPlot::Annotate(0.25,0.25,ImVec2(-15,15),col,"BL"); + clamp ? ImPlot::AnnotateClamped(0.75,0.25,ImVec2(15,15),col,"BR") : ImPlot::Annotate(0.75,0.25,ImVec2(15,15),col,"BR"); + clamp ? ImPlot::AnnotateClamped(0.75,0.75,ImVec2(15,-15),col,"TR") : ImPlot::Annotate(0.75,0.75,ImVec2(15,-15),col,"TR"); + clamp ? ImPlot::AnnotateClamped(0.25,0.75,ImVec2(-15,-15),col,"TL") : ImPlot::Annotate(0.25,0.75,ImVec2(-15,-15),col,"TL"); + clamp ? ImPlot::AnnotateClamped(0.5,0.5,ImVec2(0,0),col,"Center") : ImPlot::Annotate(0.5,0.5,ImVec2(0,0),col,"Center"); float bx[] = {1.2f,1.5f,1.8f}; float by[] = {0.25f, 0.5f, 0.75f}; ImPlot::PlotBars("##Bars",bx,by,4,0.2); - ImPlot::PushStyleVar(ImPlotStyleVar_AnnotationOffset, ImVec2(0,-5)); - for (int i = 0; i < 3; ++i) { - ImPlot::Annotate(bx[i],by[i],"B[%d]=%.2f",i,by[i]); - } - ImPlot::PopStyleVar(); - + for (int i = 0; i < 3; ++i) + ImPlot::Annotate(bx[i],by[i],ImVec2(0,-5),"B[%d]=%.2f",i,by[i]); ImPlot::EndPlot(); } }