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

[Common] Base Color Abstractions #1004

Closed
hawkerm opened this issue Nov 23, 2024 · 1 comment
Closed

[Common] Base Color Abstractions #1004

hawkerm opened this issue Nov 23, 2024 · 1 comment
Labels
common 💼 Issues/PRs for the Common package

Comments

@hawkerm
Copy link

hawkerm commented Nov 23, 2024

Overview

It'd be nice to have some baseline color abstraction/patterns for .NET. Something that helps create underlying data models/structures for MVVM apps that are UX agnostic.

Rather than re-implementing this type of base structure for every project, it'd be nice to have a common standard that folks can easily reference and then just extend with their own converters/extensions for interop with whatever image/graphics systems they may be using.

Also, other implementations may be hard to serialize. By having something simple and straight-forward it should be easy to serialize and use as data storage for base operations without having to rely on specific graphical requirements or OS quirks.

API breakdown

public record Color(byte Red, byte Green, byte Blue, byte Alpha = 255);

(Maybe it should be a record struct, I'm not sure of the pros/cons of each in this case.)

It could be handy to have some helpers like a Color.TryParse which could try and read values like <0.5,1.0,0.25> or #AAFF33FF

Maybe some other color space helpers/conversion methods for Hsl/Hsv? Then we would just simplify the WCT ones to provide the Windows Color type but use the implementation that's been abstracted here, see https://github.com/CommunityToolkit/Windows/tree/main/components/Helpers/src/ColorHelper

Usage example

In my .NET standard/'core' class library containing my data models:

public MyDataObject
{
    public Color TextColor { get; set; } = new(255, 0, 0);
}

Breaking change?

No

Alternatives

Things like System.Drawing.Common are Windows specific or other libraries do more with bitmaps and image manipulation. But generally with MVVM and abstracting your data model, you just want a simple object to represent a color value that can be stored in your data file. Your UI layer then takes that and uses a converter to map it to a brush or whatever else is needed to represent it on screen.

https://learn.microsoft.com/dotnet/api/system.drawing?view=net-8.0#remarks

Additional context

I know this isn't a fully fleshed out proposal here, but wanted to get the conversation started, as I was just about to go create a record struct for my underlying data model for file serialization in a project again...

Not sure if it makes sense to provide named colors as well: https://learn.microsoft.com/dotnet/api/system.windows.media.colors as those are Windows only as well.

Help us help you

Yes, but only if others can assist

@hawkerm hawkerm added the feature request 📬 A request for new changes to improve functionality label Nov 23, 2024
@hawkerm hawkerm changed the title [CommunityToolkit.Common] Base Color Abstractions [Common] Base Color Abstractions Nov 23, 2024
@Sergio0694
Copy link
Member

I like the idea, but I'm going to close this since this has already been approved for .NET, hopefully .NET 10 🙂
See dotnet/runtime#48615. There's also already an open PR.

@Sergio0694 Sergio0694 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2024
@Sergio0694 Sergio0694 added common 💼 Issues/PRs for the Common package and removed feature request 📬 A request for new changes to improve functionality labels Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common 💼 Issues/PRs for the Common package
Projects
None yet
Development

No branches or pull requests

2 participants