Demo: Tweak handling of "animate" flag in graph demo so it doesn't keep running.

This commit is contained in:
ocornut 2016-08-01 20:55:54 +02:00
parent 2e52bee12e
commit d0801057ba

View File

@ -774,16 +774,16 @@ void ImGui::ShowTestWindow(bool* p_open)
// Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter. // Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter.
static float values[90] = { 0 }; static float values[90] = { 0 };
static int values_offset = 0; static int values_offset = 0;
if (animate) static float refresh_time = 0.0f;
if (!animate || refresh_time == 0.0f)
refresh_time = ImGui::GetTime();
while (refresh_time < ImGui::GetTime()) // Create dummy data at fixed 60 hz rate for the demo
{ {
static float refresh_time = ImGui::GetTime(); // Create dummy data at fixed 60 hz rate for the demo static float phase = 0.0f;
for (; ImGui::GetTime() > refresh_time + 1.0f/60.0f; refresh_time += 1.0f/60.0f) values[values_offset] = cosf(phase);
{ values_offset = (values_offset+1) % IM_ARRAYSIZE(values);
static float phase = 0.0f; phase += 0.10f*values_offset;
values[values_offset] = cosf(phase); refresh_time += 1.0f/60.0f;
values_offset = (values_offset+1) % IM_ARRAYSIZE(values);
phase += 0.10f*values_offset;
}
} }
ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80)); ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));