ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.81k stars 298 forks source link

How do you use ImGui.PlotLines? #394

Closed c-schembri closed 1 year ago

c-schembri commented 1 year ago

The C++ implementation accepts a pointer to an array of values like so:

static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));

However, this API only accepts a reference to a single float:

public static unsafe void PlotLines(string label, ref float values, int values_count)

I'm probably missing something but I don't know what.

c-schembri commented 1 year ago

I figured it out and am documenting here if anyone else comes across this problem.

Instead of writing something like this:

float value = 1.0f;
ImGui.PlotLines("Plot Lines", ref value, n);

Use an array (like the C++ implementation) and simply pass the reference to the first element of the array:

float[] values = new[] { 0, 1.1f, 2.2f, 3.3f, 40.4f, 5.5f, 6.6f, 7.7f, 80.8f, 9.9f, 10.0f };
ImGui.PlotLines("Plot Lines", ref values[0], values.Length);