Vixen
dd8b0a81
csharp
public sealed class SystemPalette

What the platform fills the SystemColor roles with, right now.

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

Remarks

A mutable object rather than a value, and that is the whole point of it. A sheet that writes color: CanvasText is asking a question whose answer changes while the application runs — the user switches to dark, turns high contrast on, picks a different accent — and StyleEngine.SetMedia deliberately does not reload sheets when that happens. So the substitution cannot be baked into the parsed value at load time; the parsed value has to be able to come out different tomorrow from the same interned text.

⚠ Revision is how a cache knows, and it is a counter rather than an event for a reason. StyleValueParser caches a parse per interned value id and is created in eight places in this repository; wiring a change notification to each would have meant eight subscriptions to unsubscribe. A counter compared on the way into the cache costs one integer compare per parse and cannot leak.

⚠ Values are linear, like every other StyleValue colour, and the factories below therefore write sRGB bytes and convert. Handing this class an sRGB Color4 produces a palette that is visibly too bright and nothing will say so — see ToLinear.

Fields and properties (6)

  • public const string PlatformAccentClass

    The class a document wears while a platform accent is filling AccentColor.

  • public int Revision

    How many times any entry has changed.

  • public Color4 this[SystemColor colour]

    Reads one role.

  • public static ReadOnlySpan<uint> Light

    The light defaults, as sRGB bytes.

  • public static ReadOnlySpan<uint> Dark

    The dark defaults, as sRGB bytes.

  • public static ReadOnlySpan<uint> HighContrast

    The forced-colours defaults, as sRGB bytes.

Methods (9)

  • public SystemPalette()

    Creates a palette holding the light defaults.

  • public static bool TryParse(ReadOnlySpan<char> name, out SystemColor colour)

    Looks a CSS system colour keyword up.

  • public static string NameOf(SystemColor colour)

    The keyword a role is spelt with.

  • public bool Set(SystemColor colour, Color4 value)

    Sets one role, until the next Reset.

  • public bool SetPlatform(SystemColor colour, Color4 value)

    Fills one role from what the operating system says it is.

  • public bool ClearPlatform(SystemColor colour)

    Gives one role back to the default tables.

  • public bool ClearPlatform()

    Gives every role back to the default tables.

  • public bool IsFromPlatform(SystemColor colour)

    Whether one role is being filled by the platform rather than by a default table.

  • public bool Reset(ReadOnlySpan<uint> srgb)

    Replaces every role at once, from a table of sRGB bytes.

Used by (8)

  • DrawListBuilderVixen.Ui
  • ForcedColorsTestsVixen.Ui.Tests
  • PlatformInputVixen.Platform.Ui
  • StyleSheetLoaderVixen.Ui.Styling
  • StyleValueParserVixen.Ui.Styling
  • SystemPaletteWiringTestsVixen.Platform.Ui.Tests
  • ThemeAccentTokenTestsVixen.Ui.Controls.Tests
  • UiDocumentVixen.Ui