Open aaronfranke opened 1 year ago
@aaronfranke (or others) - can you say more about how you personally would like to use this, perhaps describing the use case that led you to create this issue. Conceptually it makes sense, but understanding specific customer scenarios that would benefit from this can help us prioritize.
I work on Godot Engine. We define our own Color type in C#. And Unity does too.
If I want to make a library that can be used in both Unity and Godot, I may require some #if
preprocessor directives for the parts that hook in the engines, but I would prefer to minimize this where possible. I would hope that at least the basic data types are automatically interoperable. This is already the case with types like int
and float
.
Thankfully as of .NET Core 1.0 and .NET Standard 2.1+ C# provides System.Numerics
in the core library, so data types like Vector2
and Vector3
can be used as a general-purpose data interchange type that is compatible with both engines, similar to int
or float
.[^1] But I can't do this with colors.
There have been arguments against this because of the complexity of color spaces, but I think the existence of color spaces should not be a blocker to having a general-purpose Color
type that stores float RGBA values. It would be like saying we can't have Vector3
if we don't define how it can be used to store meters, inches, etc.
The existence of a Color
type in Godot, Unity, MAUI, and others shows that a simple float RGBA color representation is a commonly desired feature. There is also System.Drawing.Color
, which desperately needs to be deprecated and superseded by a better color type, because it does silly things like storing a string for the color's name.
The API I propose in my proposal is very similar to the color types in Godot, Unity, MAUI, etc. I included Color8
in the proposal, but I would be happy to get rid of that if it helps get Color
get merged, because a portable general-purpose floating-point RGBA Color type is the most important goal here.
[^1]: Well, I will be able to do this in the future, it takes time for these things to arrive downstream. Some things are still using legacy technologies like Mono and .NET Framework.
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Description
https://github.com/dotnet/maui/blob/main/src/Graphics/src/Graphics/Color.cs
This data type is highly useful and general. I would appreciate having it defined outside of MAUI so that many C# applications and libraries can use it as a data interchange type for floating-point RGBA colors.
Since Color is very similar in structure to other numeric types like Vector2, Vector3, etc, I would suggest adding it to the System.Numerics namespace in .NET.
See also these previous discussions:
Public API Changes
Immediately, nothing would change for MAUI. Long-term, MAUI would use the .NET Color type as a drop-in replacement for the current Color type, since it would be very similar (or identical) to the format already in MAUI.
Intended Use-Case
Interoperability between different C# applications and libraries to have one common Color type that can be used to transfer simple floating-point RGBA values in a standard format.