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

TPropertyValue::ensureHexColor to ensure a web color '#RRGGBB' #861

Closed
belisoful opened this issue Jan 12, 2023 · 4 comments
Closed

TPropertyValue::ensureHexColor to ensure a web color '#RRGGBB' #861

belisoful opened this issue Jan 12, 2023 · 4 comments

Comments

@belisoful
Copy link
Member

In working on the TAsset publishing sub-system, there is a some color processing. Colors need to be specified.

I think it would be great to have a TPropertyValue::ensureHexColor that ensures web colors and web hex colors.

Here is what I propose. Prado\Web\UI\TWebColor Enumerable with all the web color names and their # hex color value.

The ensureHexColor would index TWebColor to translate web colors to their hex colors. It would ensure that #RGB is converted into #RRGGBB. and nothing but a web hex color will validate. A numeric color value (0xAARRGGBB) would be translated into a web hex color. (no alpha, obviously)

I suggest that 3 parameters be provided. When the 3rd parameter is provided, ensureHexColor will accept a red, green, and blue color value [0..255] and translate that into a web hex color.

This will be part of the updated publishing sub-system. I wanted to put it into an Issue for commentary and documentation.

I already have it coded, working and have the unit tests written. It's looking really great. It's a good addition to the "ensure" functionality.

@belisoful
Copy link
Member Author

This is looking easy and is working right. It just needs to be isolated and uploaded.

belisoful added a commit to belisoful/prado that referenced this issue Apr 12, 2023
This adds all the web colors into a TEnumerable.
TPropertyValue::ensureHexColor uses the new TWebColors to convert colors into their hex color.
We finally have basic unit tests for TPropertyValue.  While this may seem redundant, It provides very clear cases on how it works and is to be used.
ctrlaltca pushed a commit that referenced this issue Apr 12, 2023
This adds all the web colors into a TEnumerable.
TPropertyValue::ensureHexColor uses the new TWebColors to convert colors into their hex color.
We finally have basic unit tests for TPropertyValue.  While this may seem redundant, It provides very clear cases on how it works and is to be used.
belisoful added a commit to belisoful/prado that referenced this issue Apr 12, 2023
I got very tired last night and forgot this one little edit before submitting the merge.  Easy enough to fix.
ctrlaltca pushed a commit that referenced this issue Apr 12, 2023
I got very tired last night and forgot this one little edit before submitting the merge.  Easy enough to fix.
@belisoful
Copy link
Member Author

excellent. We've been needing this standardized list of Web Colors and associated ensure function. The unit test for TPropertyValue has been sorely needed too. I'm a fan of the multi-utility of the ensureHexColor.

@belisoful belisoful reopened this Apr 14, 2023
@belisoful
Copy link
Member Author

belisoful commented Apr 14, 2023

One more edit before completion.

Checking the $value for is_array. and set the $blue, $green, and $value to their $value['blue', 'green', 'red'] or [2, 1, 0], and then proceed with the rest of the method.

if (is_array($value)) {
	$blue = $value['blue'] ?? $value[2] ?? null;
	$green = $value['green'] ?? $value[1] ?? true;
	$value = $value['red'] ?? $value[0] ?? 0
}
...

belisoful added a commit to belisoful/prado that referenced this issue Apr 15, 2023
This adds support for an array of color [$r, $g, $b] or ['red' => $r, 'green' => $g, 'blue' => $b].  eg. a color can be retrieved by GD and converted into an RGB Hex Color.

Proper documentation and unit tests included.
belisoful added a commit to belisoful/prado that referenced this issue Apr 15, 2023
ctrlaltca pushed a commit that referenced this issue Apr 16, 2023
* #861 Added support for array type colors

This adds support for an array of color [$r, $g, $b] or ['red' => $r, 'green' => $g, 'blue' => $b].  eg. a color can be retrieved by GD and converted into an RGB Hex Color.

Proper documentation and unit tests included.

* #861 Proper bad array handling
@belisoful
Copy link
Member Author

I am very happy with this merge. I like all the web colors finally being available in a list in PRADO. I like the ensureHexColor in TPropertyValue. the new #835 Asset publishing uses color and color processing in configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant