Skip to content

Color ToString formats #18725

Open
Open
@maxkatz6

Description

@maxkatz6

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

Currently, Avalonia Color.Parse supports multiple color formats as an input. But ToString() cannot be configured to reliably output any of them.

Minimum required:

  1. Default - well-known const or fallback to XAML hex
  2. Well formatted XAML hex format (with forced leading alpha) - #aarrggbb
  3. Short XAML hex format (with optional leading alpha) - #aarrggbb, #rrggbb, #argb, #rgb

Optional for CSS compat:

  1. Well formatted HTML hex format (with forced trailing alpha) - #rrggbbaa
  2. Short HTML hex format (with optional trailing alpha) - #rrggbbaa, #rrggbb, #rgba, #rgb
  3. Well formatted absolute CSS rgb - rgb(31, 120, 50, 255)
  4. Well formatted relative CSS rgb - rgb(50%, 50%, 50%, 50%)

Note: there is way more css formats that can be supported, but we can't/don't need to support all of them.

Describe the solution you'd like

This proposal suggests implementing standard IFormattable.ToString(string? format, IFormatProvider?).
Similarly to well-known integer/float/date/time formats, there should be a set of formats for colors. IFormatProvider won't be used.

Describe alternatives you've considered

No response

Additional context

Color.ParseExact would be a reasonable proposal on its own. But let's keep it out of the scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp-wantedA contribution from the community would be most welcome.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions