1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-13 22:48:50 -05:00

remove ImPlotStyleVar_AnnotationOffset

This commit is contained in:
epezent 2020-09-19 21:25:44 -05:00
parent 13e430a9e5
commit 1911116b3b
3 changed files with 21 additions and 36 deletions

View File

@ -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")) {

View File

@ -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);

View File

@ -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();
}
}