Color conversion not behaving as expected#2874
Color conversion not behaving as expected#2874reck1610 wants to merge 10 commits intoCommunityToolkit:mainfrom
Conversation
|
@dotnet-policy-service agree company="Hartburg GmbH & Co. KG" |
|
Thanks for this. I wonder though - rather than marking the old methods as Obsolete can't we let developers provide the culture if they wish but introduce your new methods to shortcut to Invariant? |
|
Other locales produce broken output like RGBA(0,0,0,0,5). An RGBA string like that is unusable. I think the format of this should be strict, because it is not unlikely to get interpreted at some point. E.g. passed as CSS. I think localized output can only hurt in this case. I don't think this was ever supposed to be localized in the first place. |
There was a problem hiding this comment.
I would like to get some feedback on this method. I don't really like it, but I wanted to ensure the same rounding behavior as before my commit.
If the change in rounding behavior is ok. I would prefer to use only "0%", remove the method and update the failing tests.
failed CommunityToolkit.Maui.UnitTests.Converters.ColorToHslaStringConverterTests.ColorToRgbStringConverterValidInputTest(red: 0,25, green: 1, blue: 0,25, alpha: 1, expectedResult: "HSLA(120,100%,62%,1)")[en-US] (0ms)
Assert.Equal() Failure: Values differ
Expected: HSLA(120,100%,62%,1)
Actual: HSLA(120,100%,63%,1)
There was a problem hiding this comment.
I implemented the change in a separate commit (fce5451).
If this change in behavior is not wanted, I will just drop the commit.
@TheCodeTraveler Would this be considered a breaking change? If so, do I need to do something in that case, e.g.: mark the commit with "BREAKING CHANGE"?
|
We should maintain the existing methods as they are. It's up to me which culture I provide in parameters and what the expected output format is. As for the tests, we should set the invariant culture to the culture info parameter. |
|
Yes its up you which culture you provide. But its the up the method to ignore it if its not relevant. The culture info was passed as fix for the tests in #552. Those methods are supposed to create well defined output.
RGBA, CMYKA and HSLA are just broken in There is no upside in localizing this. This can only cause bugs. The methods are already documented to have a well defined behavior. Here is a full list of the possible output for CMYKA I think the 4. example contains a control character making the values appear on the wrong side of the comma. |
src/CommunityToolkit.Maui.Core/Extensions/ColorConversionExtensions.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Extensions/ColorConversionExtensions.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Extensions/ColorConversionExtensions.shared.cs
Outdated
Show resolved
Hide resolved
40320c3 to
fce5451
Compare
Wrap template string in FormattableString.Invariant Mark culture dependend versions from CommunityToolkit#552 obsolete
Co-authored-by: Pedro Jesus <[email protected]>
fce5451 to
882f08b
Compare
Description of Change
Every locale produces the documented output.
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information