ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.87k stars 305 forks source link

Fix backwards incompatibility with .NET standard 2.0 by re-adding overloads with string parameters #439

Closed NoahStolk closed 11 months ago

NoahStolk commented 11 months ago

If the tests in the sample project are not needed I'm fine with removing them. Please let me know if I've missed anything. Any feedback is appreciated.

zaafar commented 11 months ago

So on .net6 users have to explicitly pass/convert string to span in order to use span variant?

NoahStolk commented 11 months ago

So on .net6 users have to explicitly pass/convert string to span in order to use span variant?

Well, you already kind of had to do that. ReadOnlySpan<char> doesn't really make a difference for string literals (e.g. ImGui.Text("Hello, world!"); regarding heap allocations, since that string will only allocate once. But it does make sense to use spans for interpolated strings, since those always result in some allocations. If you want to prevent all those allocations you already had to provide a custom InterpolatedStringHandler anyway, and a method accepting that custom InterpolatedStringHandler can just return ReadOnlySpan<char> which is then passed to ImGui.

I don't believe this makes a difference for .NET 6+ users, and even if it does it should only be very small string allocations which are far less important than the entire library just not working properly for multi-targeted libraries supporting .NET Standard 2.0.