1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 23:57:26 -04:00

C++11 extensions update after enums with ImPlot

This commit is contained in:
ozlb 2020-05-13 17:24:11 +02:00 committed by GitHub
parent ff4f27175c
commit 595d04c0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,7 +156,7 @@ void ShowDemoWindow(bool* p_open) {
} }
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", ImVec2(-1,300))) { if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", ImVec2(-1,300))) {
ImPlot::Plot("sin(50*x)", xs1, ys1, 1001); ImPlot::Plot("sin(50*x)", xs1, ys1, 1001);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::Plot("x^2", xs2, ys2, 11); ImPlot::Plot("x^2", xs2, ys2, 11);
ImPlot::PopStyleVar(); ImPlot::PopStyleVar();
ImPlot::EndPlot(); ImPlot::EndPlot();
@ -177,11 +177,11 @@ void ShowDemoWindow(bool* p_open) {
} }
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, ImVec2(-1,300))) { if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, ImVec2(-1,300))) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3);
ImPlot::Plot("Data 1", xs1, ys1, 100); ImPlot::Plot("Data 1", xs1, ys1, 100);
ImPlot::PopStyleVar(2); ImPlot::PopStyleVar(2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f)); ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f));
ImPlot::Plot("Data 2", xs2, ys2, 50); ImPlot::Plot("Data 2", xs2, ys2, 50);
ImPlot::PopStyleColor(); ImPlot::PopStyleColor();
@ -227,7 +227,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::Bar("Bar", xs, bar, 5, 0.5f); ImPlot::Bar("Bar", xs, bar, 5, 0.5f);
ImPlot::ErrorBars("Bar", xs, bar, err1, 5); ImPlot::ErrorBars("Bar", xs, bar, err1, 5);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3);
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImVec4(1,0,0,1)); ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImVec4(1,0,0,1));
ImPlot::ErrorBars("Line", xs, lin, err1, err2, 5); ImPlot::ErrorBars("Line", xs, lin, err1, err2, 5);
@ -286,7 +286,7 @@ void ShowDemoWindow(bool* p_open) {
rdata2.AddPoint(t, mouse.y * 0.0005f); rdata2.AddPoint(t, mouse.y * 0.0005f);
} }
ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always); ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
static int rt_axis = ImAxisFlags_Default & ~ImAxisFlags_TickLabels; static int rt_axis = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) { if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
ImPlot::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float)); ImPlot::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float));
ImPlot::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float)); ImPlot::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float));
@ -306,50 +306,50 @@ void ShowDemoWindow(bool* p_open) {
float xs[2] = {1,4}; float xs[2] = {1,4};
float ys[2] = {10,11}; float ys[2] = {10,11};
// filled // filled
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::Plot("Circle##Fill", xs, ys, 2); ImPlot::Plot("Circle##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); ys[0]--; ys[1]--;
ImPlot::Plot("Square##Fill", xs, ys, 2); ImPlot::Plot("Square##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); ys[0]--; ys[1]--;
ImPlot::Plot("Diamond##Fill", xs, ys, 2); ImPlot::Plot("Diamond##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Up); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Up); ys[0]--; ys[1]--;
ImPlot::Plot("Up##Fill", xs, ys, 2); ImPlot::Plot("Up##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Down); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Down); ys[0]--; ys[1]--;
ImPlot::Plot("Down##Fill", xs, ys, 2); ImPlot::Plot("Down##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Left); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Left); ys[0]--; ys[1]--;
ImPlot::Plot("Left##Fill", xs, ys, 2); ImPlot::Plot("Left##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Right); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Right); ys[0]--; ys[1]--;
ImPlot::Plot("Right##Fill", xs, ys, 2); ImPlot::Plot("Right##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ys[0]--; ys[1]--;
ImPlot::Plot("Cross##Fill", xs, ys, 2); ImPlot::Plot("Cross##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Plus); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Plus); ys[0]--; ys[1]--;
ImPlot::Plot("Plus##Fill", xs, ys, 2); ImPlot::Plot("Plus##Fill", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Asterisk); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Asterisk); ys[0]--; ys[1]--;
ImPlot::Plot("Asterisk##Fill", xs, ys, 2); ImPlot::Plot("Asterisk##Fill", xs, ys, 2);
ImPlot::PopStyleVar(10); ImPlot::PopStyleVar(10);
xs[0] = 6; xs[1] = 9; xs[0] = 6; xs[1] = 9;
ys[0] = 10; ys[1] = 11; ys[0] = 10; ys[1] = 11;
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0)); ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0));
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::Plot("Circle", xs, ys, 2); ImPlot::Plot("Circle", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square); ys[0]--; ys[1]--;
ImPlot::Plot("Square", xs, ys, 2); ImPlot::Plot("Square", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond); ys[0]--; ys[1]--;
ImPlot::Plot("Diamond", xs, ys, 2); ImPlot::Plot("Diamond", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Up); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Up); ys[0]--; ys[1]--;
ImPlot::Plot("Up", xs, ys, 2); ImPlot::Plot("Up", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Down); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Down); ys[0]--; ys[1]--;
ImPlot::Plot("Down", xs, ys, 2); ImPlot::Plot("Down", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Left); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Left); ys[0]--; ys[1]--;
ImPlot::Plot("Left", xs, ys, 2); ImPlot::Plot("Left", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Right); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Right); ys[0]--; ys[1]--;
ImPlot::Plot("Right", xs, ys, 2); ImPlot::Plot("Right", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ys[0]--; ys[1]--;
ImPlot::Plot("Cross", xs, ys, 2); ImPlot::Plot("Cross", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Plus); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Plus); ys[0]--; ys[1]--;
ImPlot::Plot("Plus", xs, ys, 2); ImPlot::Plot("Plus", xs, ys, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Asterisk); ys[0]--; ys[1]--; ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Asterisk); ys[0]--; ys[1]--;
ImPlot::Plot("Asterisk", xs, ys, 2); ImPlot::Plot("Asterisk", xs, ys, 2);
ImPlot::PopStyleColor(); ImPlot::PopStyleColor();
ImPlot::PopStyleVar(10); ImPlot::PopStyleVar(10);
@ -360,7 +360,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 8); ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 8);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, 2); ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, 2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle | ImMarker_Cross); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle | ImPlotMarker_Cross);
ImPlot::PushStyleColor(ImPlotCol_MarkerOutline, ImVec4(0,0,0,1)); ImPlot::PushStyleColor(ImPlotCol_MarkerOutline, ImVec4(0,0,0,1));
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,1,1,1)); ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,1,1,1));
ImPlot::PushStyleColor(ImPlotCol_Line, ImVec4(0,0,0,1)); ImPlot::PushStyleColor(ImPlotCol_Line, ImVec4(0,0,0,1));
@ -386,7 +386,7 @@ void ShowDemoWindow(bool* p_open) {
ys3[i] = pow(10.0f, xs[i]); ys3[i] = pow(10.0f, xs[i]);
} }
ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10); ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10);
if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_Default | ImAxisFlags_LogScale )) { if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImPlotAxisFlags_Default | ImPlotAxisFlags_LogScale )) {
ImPlot::Plot("f(x) = x", xs, xs, 1001); ImPlot::Plot("f(x) = x", xs, xs, 1001);
ImPlot::Plot("f(x) = sin(x)+1", xs, ys1, 1001); ImPlot::Plot("f(x) = sin(x)+1", xs, ys1, 1001);
ImPlot::Plot("f(x) = log(x)", xs, ys2, 1001); ImPlot::Plot("f(x) = log(x)", xs, ys2, 1001);
@ -460,11 +460,11 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Unindent(); ImGui::Unindent();
static ImVector<ImVec2> data; static ImVector<ImVec2> data;
ImPlotLimits range, query; ImPlotLimits range, query;
if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default | ImPlotFlags_Query, ImAxisFlags_GridLines, ImAxisFlags_GridLines)) { if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default | ImPlotFlags_Query, ImPlotAxisFlags_GridLines, ImPlotAxisFlags_GridLines)) {
if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl)
data.push_back(ImPlot::GetPlotMousePos()); data.push_back(ImPlot::GetPlotMousePos());
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond);
if (data.size() > 0) if (data.size() > 0)
ImPlot::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float)); ImPlot::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float));
if (ImPlot::IsPlotQueried() && data.size() > 0) { if (ImPlot::IsPlotQueried() && data.size() > 0) {
@ -511,7 +511,7 @@ void ShowDemoWindow(bool* p_open) {
} }
ImGui::BulletText("Query the first plot to render a subview in the second plot (see above for controls)."); ImGui::BulletText("Query the first plot to render a subview in the second plot (see above for controls).");
ImPlot::SetNextPlotLimits(0,0.01f,-1,1); ImPlot::SetNextPlotLimits(0,0.01f,-1,1);
ImAxisFlags flgs = ImAxisFlags_Default & ~ImAxisFlags_TickLabels; ImPlotAxisFlags flgs = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
ImPlotLimits query; ImPlotLimits query;
if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) { if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) {
ImPlot::Plot("Signal 1", x_data, y_data1, 512); ImPlot::Plot("Signal 1", x_data, y_data1, 512);
@ -713,6 +713,20 @@ void ShowDemoWindow(bool* p_open) {
} }
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Offset Data")) {
float xs[50], ys[50];
for (int i = 0; i < 50; ++i) {
xs[i] = 0.5 + 0.4 * cos(i/50.f * 6.28);
ys[i] = 0.5 + 0.4 * sin(i/50.f * 6.28);
}
static int offset = 0;
ImGui::SliderInt("Offset", &offset, -100, 100);
if (ImPlot::BeginPlot("##offset")) {
ImPlot::Plot("circle", xs, ys, 50, offset);
ImPlot::EndPlot();
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Styles")) { if (ImGui::CollapsingHeader("Custom Styles")) {
static ImVec4 my_palette[3] = { static ImVec4 my_palette[3] = {
ImVec4(0.000f, 0.980f, 0.604f, 1.0f), ImVec4(0.000f, 0.980f, 0.604f, 1.0f),
@ -734,7 +748,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::Bar("Bar", bar, 10, 0.5f); ImPlot::Bar("Bar", bar, 10, 0.5f);
ImPlot::Plot("Line", lin, 10); ImPlot::Plot("Line", lin, 10);
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
ImPlot::Plot("Dot", dot, 10); ImPlot::Plot("Dot", dot, 10);
ImPlot::PopStyleVar(2); ImPlot::PopStyleVar(2);
ImPlot::EndPlot(); ImPlot::EndPlot();
@ -778,4 +792,4 @@ void ShowDemoWindow(bool* p_open) {
ImGui::End(); ImGui::End();
} }
} // namespace ImGui } // namespace ImPlot