Vixen
02b45cc4
csharp
public sealed class ColorPicker

Choosing a colour: a field, two strips, a number, a palette and a dropper.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

⚠ The model is the source of truth, not the RGB. Grey has no hue and black has no saturation, so a picker that recomputed its axes from the colour would lose which hue the user was on the moment they dragged the saturation to nothing — and the field would snap back to red when they dragged it out again. Every picker that has had that bug has had it for that reason. What is stored is Hue, the field's position and the alpha; Value is derived, and assigning to it is the only thing that reconstructs them.

HDR is a multiplier beside a colour, not a colour with big numbers in it. An artist picks a hue and then says how bright the light is, and those are two decisions: keeping them apart means changing the intensity does not move the picker, and the chromaticity survives a round trip through a value of forty. Intensity is that number and HdrValue is the product.

⚠ The eyedropper cannot read the screen and does not pretend to. Sampling a pixel is a platform capability — a screen capture permission on macOS, a compositor protocol on Wayland — and this assembly has no platform. EyedropperRequested is what an app head answers, and Pick is how it answers.

Fields and properties (25)

  • public const float MaximumChroma

    The chroma the perceptual field runs out to.

  • protected override string TagName

    The element name this type answers to when a caller does not choose one.

  • protected override bool AcceptsFocus

    Whether the focus can rest on this kind of control at all.

  • public ColorField Field

    The two-dimensional field.

  • public ColorStrip HueStrip

    The hue band.

  • public ColorStrip AlphaStrip

    The alpha band.

  • public ColorSwatch Preview

    The current colour, shown large.

  • public TextBox HexField

    The hexadecimal field.

  • public IconButton Eyedropper

    The dropper.

  • public Slider IntensitySlider

    The brightness multiplier, shown only when AllowHdr is set.

  • public UiElement Palette

    Where the saved colours go.

  • public IReadOnlyList<Color4> Swatches

    The saved colours.

  • public Color4 Value

    The chosen colour, with its alpha and without the intensity.

  • public Color4 HdrValue

    The colour times the intensity, which is what a light or an emissive material wants.

  • public ColorModel Model
  • public bool AllowAlpha
  • public bool AllowHdr
  • public float Intensity
  • public float Hue

    The hue, in degrees, whichever model is in use.

  • public bool IsPicking

    Whether the dropper is waiting for a colour.

  • public string HexText

    The colour as #rrggbb, or #rrggbbaa when it is not opaque.

  • public static readonly UiPropertyKey ModelProperty

    Identity for Model.

  • public static readonly UiPropertyKey AllowAlphaProperty

    Identity for AllowAlpha.

  • public static readonly UiPropertyKey AllowHdrProperty

    Identity for AllowHdr.

  • public static readonly UiPropertyKey IntensityProperty

    Identity for Intensity.

Events (2)

  • public Action<ColorPicker, Color4>? ValueChanged

    Raised whenever the colour changes, however it changed.

  • public Action<ColorPicker>? EyedropperRequested

    Raised when the dropper is pressed. Answer it with Pick.

Methods (9)

  • protected override void OnCreated()

    Builds whatever this element is made of, once, as it joins a document.

  • public void SetPalette(params ReadOnlySpan<Color4> colors)

    Replaces the saved colours.

  • public bool AddToPalette()

    Saves the current colour.

  • public void RequestEyedropper()

    Asks the application for a colour from the screen.

  • public void Pick(Color4 colour)

    Answers an eyedropper request, or just sets the colour.

  • public void ClearModel()

    Unsets Model, so it takes its default or its ancestor's value again.

  • public void ClearAllowAlpha()

    Unsets AllowAlpha, so it takes its default or its ancestor's value again.

  • public void ClearAllowHdr()

    Unsets AllowHdr, so it takes its default or its ancestor's value again.

  • public void ClearIntensity()

    Unsets Intensity, so it takes its default or its ancestor's value again.

Used by (7)

  • ColorFieldVixen.Ui.Controls.Advanced
  • ColorInputVixen.Ui.Controls.Advanced
  • ColorInputTestsVixen.Ui.Controls.Advanced.Tests
  • ColorPickerTestsVixen.Ui.Controls.Advanced.Tests
  • ColorStripVixen.Ui.Controls.Advanced
  • GradientEditorVixen.Ui.Controls.Advanced
  • GradientEditorTestsVixen.Ui.Controls.Advanced.Tests