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 new ColorSlider & ColorPreviewer Primitives #8050

Merged
merged 39 commits into from
May 3, 2022

Conversation

robloo
Copy link
Contributor

@robloo robloo commented Apr 26, 2022

What does the pull request do?

Adds two new ColorSlider and ColorPreviewer control primitives (in the Avalonia.Controls.Primitives namespace). These are stand-alone controls not based on WinUI code. This relates to #4179.

These are the second and third major controls towards implementing the ColorPicker and the last primitives.

What is the current behavior?

Only the ColorSpectrum primitive exists so far for implementing a ColorPicker.

What is the updated/expected behavior with this PR?

Two additional primitives for the ColorPicker are added: ColorSlider and ColorPreviewer. These composable primitives allow making a nearly fully-functional color picker.

image

Video.mp4

How was the solution implemented (if it's not obvious)?

  • Both ColorSlider and ColorPreviewer are brand-new controls and not based on WinUI code. They share some code with an internal implementation and ColorPreviewer is currently in a PR updating the UWP (now Windows) community toolkit: ColorPicker Updates CommunityToolkit/WindowsCommunityToolkit#4502.
  • ColorSlider has been heavily updated improving upon past implementations. It is now a fully stand-alone primitive that can render itself and in no way depends on other higher-level controls. (The WinUI ColorPickerSlider cannot be used independently and earlier ColorPickerSlider implementations by myself were not this advanced).
  • The checkered background brush code is based on @maxkatz6 port here: https://github.com/maxkatz6/AvaloniaWinUI.ColorPicker/blob/d774fb6e287471145bef0e10173802a9450a4904/src/AvaloniaWinUI.ColorPicker/Styles/ColorPicker.xaml#L36-L47. This allows a nice simplification not possible in UWP/WinUI which don't support tiled brushes like WPF did.
  • All color picker primitives (ColorSpectrum, ColorSlider and ColorPreviewer) can be two-way bound together through the HsvColor property which supports a lot of the color picker functionality already.
  • The ColorSpectrum now renders to device DPI/pixels instead of the device-independent pixels/DPI of Avalonia itself. This removes banding caused by Skia scaling the spectrum to fit the full rectangle Fill when desktop scaling is greater than 100%. This now introduces two coordinate systems to keep track of internally. These can be converted between using the LayoutScale factor.
    1. The actual bitmap which follows the physical device pixels regardless of scaling.
    2. The standard Avalonia control coordinates
  • ToDisplayName was implemented for the English language using a new algorithm and KnownColor enum. The algorithm is not open source so a best-guess was done. This enables the color name tooltips in the spectrum now.

Checklist

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

Relates to #4179.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020131-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@robloo robloo changed the title Add ColorSlider & ColorPreviewer Primitives Add new ColorSlider & ColorPreviewer Primitives Apr 27, 2022
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020132-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@robloo robloo marked this pull request as ready for review April 27, 2022 02:52
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020133-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020147-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020157-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@robloo
Copy link
Contributor Author

robloo commented Apr 29, 2022

@maxkatz6 This is also ready for review. I know you all are busy but if this is merged soon I can get started on the final PR for the full color-picker. That should actually not be too difficult compared to what is already done. The final PR can also be lower priority as it isn't blocking anything.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020159-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. ColorSlider is definitely way more useful here comparing with one in WinUI implementation.

@maxkatz6 maxkatz6 enabled auto-merge May 3, 2022 20:47
@maxkatz6 maxkatz6 merged commit b231395 into AvaloniaUI:master May 3, 2022
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0020195-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@robloo robloo deleted the color-slider-previewer branch May 3, 2022 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants