Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider moving MAUI's Color type into the base .NET #16903

Open
aaronfranke opened this issue Aug 21, 2023 · 3 comments
Open

Consider moving MAUI's Color type into the base .NET #16903

aaronfranke opened this issue Aug 21, 2023 · 3 comments
Labels
area-architecture Issues with code structure, SDK structure, implementation details proposal/open t/enhancement ☀️ New feature or request
Milestone

Comments

@aaronfranke
Copy link
Contributor

aaronfranke commented Aug 21, 2023

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.

@BretJohnson
Copy link
Member

@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.

@aaronfranke
Copy link
Contributor Author

aaronfranke commented Aug 22, 2023

I work on Godot Engine. We define our own Color type in C#. And Unity does too. And Stride 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.

Footnotes

  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.

@rachelkang rachelkang added the t/enhancement ☀️ New feature or request label Aug 23, 2023
@rachelkang rachelkang added this to the Backlog milestone Aug 23, 2023
@ghost
Copy link

ghost commented Aug 23, 2023

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.

@Eilon Eilon added the area-architecture Issues with code structure, SDK structure, implementation details label Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-architecture Issues with code structure, SDK structure, implementation details proposal/open t/enhancement ☀️ New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants