Skip to content

Fix ColorSpectrum third-component slider showing wrong colors#20945

Open
NathanDrake2406 wants to merge 2 commits intoAvaloniaUI:masterfrom
NathanDrake2406:fix/color-spectrum-slider-perceptive
Open

Fix ColorSpectrum third-component slider showing wrong colors#20945
NathanDrake2406 wants to merge 2 commits intoAvaloniaUI:masterfrom
NathanDrake2406:fix/color-spectrum-slider-perceptive

Conversation

@NathanDrake2406
Copy link
Contributor

@NathanDrake2406 NathanDrake2406 commented Mar 19, 2026

Summary

Fixes #20925

  • Disable IsPerceptive on the ColorSpectrum's companion slider in all 4 theme templates (Fluent/Simple × ColorPicker/ColorView). The slider now renders using the actual HSV values from the 2D selection point instead of hardcoding S=1, V=1.
  • Add regression tests for ColorPickerHelpers.CreateComponentBitmapAsync verifying that the non-perceptive path produces accurate pixel output for all three component types (Hue, Saturation, Value), with assertions derived from HSV color math invariants.

Root cause

IsPerceptive="True" on ColorSpectrumThirdComponentSlider caused the slider gradient to force non-varying HSV components to 1.0 — producing a vibrant rainbow regardless of the actual selection. This is the correct behavior for standalone "pedagogical" sliders, but wrong for the spectrum's third axis where accuracy is the contract.

What changed

File Change
Themes/Fluent/ColorPicker.xaml IsPerceptive="True""False"
Themes/Fluent/ColorView.xaml IsPerceptive="True""False"
Themes/Simple/ColorPicker.xaml IsPerceptive="True""False"
Themes/Simple/ColorView.xaml IsPerceptive="True""False"
ColorPicker.csproj Add InternalsVisibleTo for test project
Controls.UnitTests.csproj Add ColorPicker project reference
ColorPickerHelpersTests.cs New: 5 tests (1 Fact + 1 Theory×3 + 1 Fact)

Test plan

  • All 3374 existing tests pass (0 failures, 1 pre-existing skip)
  • New tests verify pixel-level accuracy for Hue, Saturation, and Value slider bitmaps

The ColorSpectrum's companion slider should show what each hue/saturation/value
looks like at the actual 2D selection point — not at hardcoded S=1, V=1.

IsPerceptive="True" was forcing non-varying HSV components to 1.0, producing
vibrant gradients regardless of the current selection. This is correct for
standalone sliders (pedagogical mode) but wrong for the spectrum's third axis,
where accuracy is the contract.

Fixes AvaloniaUI#20925
Verify that CreateComponentBitmapAsync with isPerceptive=false produces
pixel output that reflects the actual HSV selection values. Covers all
three component types (Hue, Saturation, Value) with assertions derived
from HSV color math invariants.

Also adds InternalsVisibleTo and project reference to enable testing
the internal ColorPickerHelpers from Avalonia.Controls.UnitTests.
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063689-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Mar 19, 2026
@robloo
Copy link
Contributor

robloo commented Mar 20, 2026

I saw your issue but haven't had extra time to reply. The current functionality was intentional though so let's try reach consensus before this is merged.

@robloo
Copy link
Contributor

robloo commented Mar 20, 2026

Another point even for @MrJul, I don't think we should ever add unit tests for things like this. This is a configuration -- a theme configuration too -- that has to be thought of completely differently.

Nevermind after reading the tests. This is testing the color calculation itself not the color picker. It might be better to do image-based comparisons for these tests though. We already have infrastructure for that.

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

Labels

backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ColorSpectrum third-component slider doesn't reflect current 2D selection point

4 participants