Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ThemeProvider/ColorRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ public readonly record struct ColorRange(Color Start, Color End)
/// </summary>
public double Distance => Start.DistanceTo(End);

/// <summary>
/// The perceptual (Oklab) distance below which the start and end colors are treated as a single color.
/// </summary>
private const double SingleColorDistanceThreshold = 1e-6;

/// <summary>
/// Indicates whether this range represents a single color (start equals end).
/// </summary>
public bool IsSingleColor => Distance < double.Epsilon;
public bool IsSingleColor => Distance < SingleColorDistanceThreshold;

/// <summary>
/// Creates a color range from two colors, automatically ordering them
Expand Down
3 changes: 1 addition & 2 deletions ThemeProvider/SemanticColorMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ private static double CalculateTargetLightnessForSemantic(

if (allPriorities.Length == 1)
{
double globalCenter = (globalMinLightness + globalMaxLightness) / 2.0;
return meaning == SemanticMeaning.Neutral ? globalCenter : globalCenter;
return (globalMinLightness + globalMaxLightness) / 2.0;
}

// Calculate position in range (0.0 to 1.0)
Expand Down
14 changes: 7 additions & 7 deletions ThemeProviderDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -754,19 +754,19 @@ private static IReadOnlyDictionary<SemanticColorRequest, Color> GetCompleteMappi
return cachedCompletePalette;
}

private static Vector4 ToImVec4(Color color, float alpha = 1.0f)
private static Vector4 ToImVec4(Color color, float? alpha = null)
{
Srgb srgb = color.ToSrgb();
return new Vector4((float)srgb.R, (float)srgb.G, (float)srgb.B, alpha);
return new Vector4((float)srgb.R, (float)srgb.G, (float)srgb.B, alpha ?? (float)color.A);
}

private static Color AdjustBrightness(Color color, float factor)
{
Srgb srgb = color.ToSrgb();
return Color.FromSrgb(
Math.Clamp(srgb.R * factor, 0.0, 1.0),
Math.Clamp(srgb.G * factor, 0.0, 1.0),
Math.Clamp(srgb.B * factor, 0.0, 1.0),
// Multiplicative brightness is a linear-light operation; scale the linear channels, not the gamma-encoded sRGB ones.
return Color.FromLinear(
Math.Clamp(color.R * factor, 0.0, 1.0),
Math.Clamp(color.G * factor, 0.0, 1.0),
Math.Clamp(color.B * factor, 0.0, 1.0),
color.A
);
}
Expand Down
Loading