Table of Contents

Class PaletteColors

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Color derivation helpers for palette-based theme generation: tint (toward white), shade (toward black), mix (toward another color), relative luminance, and a readable contrast color. All are reflection-free and built on BlendColor(Color, Color, float).

public static class PaletteColors
Inheritance
PaletteColors
Inherited Members

Methods

ContrastOn(Color)

A readable foreground for the given background: near-white on dark, near-black on light.

public static Color ContrastOn(Color background)

Parameters

background Color

Returns

Color

EffectiveSurface(Color?, Color)

The opaque surface a control actually composites onto: its own background if opaque, otherwise the supplied window/parent background (transparent or default backgrounds show that through).

public static Color EffectiveSurface(Color? controlBackground, Color windowBackground)

Parameters

controlBackground Color?
windowBackground Color

Returns

Color

EnsureContrast(Color, Color, double)

Returns color unchanged if it already has at least minGap luminance separation from background; otherwise nudges it away from the background (lighter on a dark bg, darker on a light bg) until it reaches the gap, preserving its hue as much as possible. Guarantees the color stays visible against the background.

public static Color EnsureContrast(Color color, Color background, double minGap = 80)

Parameters

color Color

The color to keep visible.

background Color

The surface it sits on.

minGap double

Minimum luminance gap (0..255). 80 is a reasonable readable minimum.

Returns

Color

IsDark(Color)

Whether the color reads as dark (luminance below mid-grey).

public static bool IsDark(this Color color)

Parameters

color Color

Returns

bool

Luminance(Color)

Relative luminance (0..255, Rec.709 weights).

public static double Luminance(this Color color)

Parameters

color Color

Returns

double

Mix(Color, Color, double)

Blends color toward other. amount 0..1.

public static Color Mix(this Color color, Color other, double amount)

Parameters

color Color
other Color
amount double

Returns

Color

ReadableOn(Color)

A readable foreground for background that stays palette-dependent: starts from ContrastOn(Color) (near-white/near-black) then blends a small amount of the background back in so the text picks up the surface's hue. High contrast is preserved while the result genuinely tracks the palette rather than snapping to one of two fixed constants.

public static Color ReadableOn(Color background)

Parameters

background Color

Returns

Color

Shade(Color, double)

Darkens color by blending it toward black. amount 0..1.

public static Color Shade(this Color color, double amount)

Parameters

color Color
amount double

Returns

Color

Tint(Color, double)

Lightens color by blending it toward white. amount 0..1.

public static Color Tint(this Color color, double amount)

Parameters

color Color
amount double

Returns

Color