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
backgroundColor
Returns
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
Returns
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
colorColorThe color to keep visible.
backgroundColorThe surface it sits on.
minGapdoubleMinimum luminance gap (0..255). 80 is a reasonable readable minimum.
Returns
IsDark(Color)
Whether the color reads as dark (luminance below mid-grey).
public static bool IsDark(this Color color)
Parameters
colorColor
Returns
Luminance(Color)
Relative luminance (0..255, Rec.709 weights).
public static double Luminance(this Color color)
Parameters
colorColor
Returns
Mix(Color, Color, double)
Blends color toward other. amount 0..1.
public static Color Mix(this Color color, Color other, double amount)
Parameters
Returns
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
backgroundColor
Returns
Shade(Color, double)
Darkens color by blending it toward black. amount 0..1.
public static Color Shade(this Color color, double amount)
Parameters
Returns
Tint(Color, double)
Lightens color by blending it toward white. amount 0..1.
public static Color Tint(this Color color, double amount)