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

Add a Gray color trait #13206

Closed
alice-i-cecile opened this issue May 3, 2024 · 4 comments
Closed

Add a Gray color trait #13206

alice-i-cecile opened this issue May 3, 2024 · 4 comments
Labels
A-Color Color spaces and color math A-Rendering Drawing game state to the screen C-Enhancement A new feature D-Straightforward Simple bug fixes and API improvements, docs, test and examples X-Uncontroversial This work is generally agreed upon

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

Creating uniformly gray colors is a common task for prototyping and even some finished UIs.

Doing so is currently tedious and doesn't show intent well. Rather than Srgba::gray(0.9), users must type Srgba::rgb(0.9, 0.9, 0.9).

What solution would you like?

Add an extension trait for the color spaces that support the creation of grey colors, and use that.

What alternative(s) have you considered?

Using the clearly superior but not style-guide approved Canadian spelling of Grey.

Additional context

Our examples use grays a ton: these could be cleaned up as part of the same PR.

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-Rendering Drawing game state to the screen X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples A-Color Color spaces and color math labels May 3, 2024
@Earthmark
Copy link
Contributor

I'll take a whack at this.

@Earthmark
Copy link
Contributor

Earthmark commented May 4, 2024

This came up when drafting the PR, but is the goal with this interface to have a specific input value (say grey(0.5)), to mean the same color in every color format?

I implemented a linear traversal of the color values, not so much the color space. I can adapt the code as needed though!
EDIT: It now uses mix instead, which I think deals with traversing the color space appropriately.

@NthTensor
Copy link
Contributor

I don't think gray should mean the same color in every format. Using mix between the black and the whitepoint of the space is what I would expect.

Also Color probably shouldn't implement this (pointing this out only because we just added a bunch of extra methods to it.

github-merge-queue bot pushed a commit that referenced this issue May 26, 2024
 (#13237)

Added a Grey trait to allow colors to create a generic "grey" color.

This currently assumes the color spaces follow the same gradient, which
I'm pretty sure isn't true, but it should make a "grey-ish" color
relative to the provided intensity.

# Objective

- Implements #13206 

## Solution

- A small `Grey` trait was added and implemented for the common color
kinds.

## Testing

- Currently untested, unit tests exposed the non-linear relation between
colors. I am debating adding an example to show this, as I have no idea
what color space represents what relation of grey, and I figure others
may be similarly confused.

## Changelog

- The `Grey` trait was added, and the corresponding `grey` 

## BREAKING CHANGES

The const qualifier for LinearRGBA::gray was removed (the symbol still
exists via a trait, it's just not const anymore)
@bugsweeper
Copy link
Contributor

bugsweeper commented May 27, 2024

@alice-i-cecile I think this issue should be closed due to merge commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Color Color spaces and color math A-Rendering Drawing game state to the screen C-Enhancement A new feature D-Straightforward Simple bug fixes and API improvements, docs, test and examples X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

No branches or pull requests

4 participants