-
Notifications
You must be signed in to change notification settings - Fork 460
Color conversion not behaving as expected #2874
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
base: main
Are you sure you want to change the base?
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. |
/// </summary> | ||
/// <param name="percentage">percentage</param> | ||
/// <returns></returns> | ||
static string ToPercentage(this float percentage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Wrap template string in FormattableString.Invariant Mark culture dependend versions from CommunityToolkit#552 obsolete
4dfad93
to
40320c3
Compare
40320c3
to
fce5451
Compare
Description of Change
Every locale produces the documented output.
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information