Skip to content

Implement IFormattable on HslColor and HsvColor #20927

Description

@NathanDrake2406

Is your feature request related to a problem? Please describe.

Follow-up to #18725 and #20919. Color is getting IFormattable support for configurable ToString formats. HslColor and HsvColor should get the same treatment for consistency.

Currently these types have a single ToString() that outputs a fixed format. There's no way to control alpha inclusion or output representation.

Describe the solution you'd like

Implement IFormattable on both HslColor and HsvColor with format specifiers following the same convention established in #20919: uppercase includes alpha, lowercase excludes it.

Proposed specifiers for HslColor:

Specifier Output
H hsl(h, s%, l%, a) — with alpha
h hsl(h, s%, l%) — without alpha

Proposed specifiers for HsvColor:

Specifier Output
V hsv(h, s%, v%, a) — with alpha
v hsv(h, s%, v%) — without alpha

Default ToString() behavior unchanged for both types.

Additional context

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions