Vixen
02b45cc4
csharp
public sealed class ColorInput

A colour as a field: a swatch you click, and a picker that drops out of it.

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

Remarks

What a colour looks like in a property row. ColorPicker is the whole apparatus — a field, two bands, a hex box, an intensity slider and a palette — and it is the right thing to open. It is the wrong thing to leave sitting in an inspector: eight components with a tint each is eight of those stacked down the panel, and the row somebody scrolled to is off the bottom of it. Every editor that has solved this has solved it the same way, and it is the way a colour input works on the web: a swatch, and a picker on demand.

⚠ The picker lives in a popover that is a root child, which is SelectBase's arrangement and is here for its reason. A panel that dropped out of the field would be clipped by every scrolling ancestor between the two, which for a property row in an inspector in a docked panel is three of them. The cost is that the popover is not this control's child, so the subtree removal does not take it — OnRemoved is what pays that.

⚠ The value is this control's and the picker is a view of it. The picker is built once and kept, so re-opening it returns to the hue the user was on rather than to whatever the RGB happens to reconstruct — which is the distinction ColorPicker's own remarks are about, and it would be lost by building a fresh picker per open.

Fields and properties (11)

  • 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 ColorSwatch Swatch

    The box that is drawn in the row.

  • public Popover Popup

    The floating picker.

  • public ColorPicker Picker

    The picker inside it.

  • public bool IsOpen

    Whether the picker is showing.

  • public Color4 Value

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

  • public Color4 HdrValue
  • public bool AllowAlpha
  • public bool AllowHdr
  • public float Intensity

Events (1)

  • public Action<ColorInput, Color4>? ValueChanged

    Raised when the colour changes, however it changed.

Methods (4)

  • protected override void OnCreated()

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

  • protected override void OnRemoved()
  • public void Open()

    Shows the picker.

  • public void Close(CloseReason reason = Code)

    Hides it.

Used by (4)

  • ColorInputTestsVixen.Ui.Controls.Advanced.Tests
  • Color3DrawerVixen.Editor.Inspector
  • ColorDrawerVixen.Editor.Inspector
  • EditorAffordanceTestsVixen.Editor.App.Tests