< Summary

Information
Class: Allyaria.Theming.Helpers.ThemeColorApplier
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Helpers/ThemeColorApplier.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 79
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%44100%
AddColor(...)100%11100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Helpers/ThemeColorApplier.cs

#LineLine coverage
 1namespace Allyaria.Theming.Helpers;
 2
 3/// <summary>
 4/// Applies color-related styles from a specified <see cref="PaletteType" /> to a given <see cref="ComponentType" />.
 5/// </summary>
 6/// <remarks>
 7///     <para>
 8///     The <see cref="ThemeColorApplier" /> class generates and adds <see cref="ThemeUpdater" /> instances representing
 9///     color mappings between <see cref="BrandPalette" /> values and component-level style properties such as
 10///     <see cref="StyleType.BackgroundColor" />, <see cref="StyleType.Color" />, and <see cref="StyleType.BorderColor" 
 11///     </para>
 12///     <para>
 13///     It is primarily used by <see cref="ThemeBuilder" /> to construct theming layers that ensure color consistency
 14///     across component surfaces, text, outlines, and decorations.
 15///     </para>
 16/// </remarks>
 17internal sealed class ThemeColorApplier : ThemeApplierBase
 18{
 19    /// <summary>Indicates whether this applier targets variant palettes (e.g., light/dark inversion).</summary>
 20    private readonly bool _isVariant;
 21
 22    /// <summary>Represents the <see cref="PaletteType" /> from which colors will be derived.</summary>
 23    private readonly PaletteType _paletteType;
 24
 25    /// <summary>
 26    /// Initializes a new instance of the <see cref="ThemeColorApplier" /> class, configuring color propagation for a sp
 27    /// component and palette type.
 28    /// </summary>
 29    /// <param name="themeMapper">The <see cref="ThemeMapper" /> responsible for resolving color mappings.</param>
 30    /// <param name="isHighContrast">Indicates whether high-contrast color mapping should be applied.</param>
 31    /// <param name="componentType">The <see cref="ComponentType" /> to which color styles will be applied.</param>
 32    /// <param name="paletteType">The <see cref="PaletteType" /> defining which brand color group to use.</param>
 33    /// <param name="isVariant">Determines whether variant theme colors should be applied (e.g., light/dark inversion).<
 34    /// <param name="hasBackground">Specifies whether the component includes a background color layer.</param>
 35    /// <param name="isOutline">Specifies whether the component is outline-only (no fill).</param>
 36    public ThemeColorApplier(ThemeMapper themeMapper,
 37        bool isHighContrast,
 38        ComponentType componentType,
 39        PaletteType paletteType,
 40        bool isVariant,
 41        bool hasBackground,
 42        bool isOutline)
 7443        : base(themeMapper: themeMapper, isHighContrast: isHighContrast, componentType: componentType)
 44    {
 7445        _isVariant = isVariant;
 7446        _paletteType = paletteType;
 47
 7448        if (hasBackground)
 49        {
 51050            AddColor(styleType: StyleType.BackgroundColor, getColor: palette => palette.BackgroundColor);
 51        }
 52
 7453        if (!isOutline)
 54        {
 79555            AddColor(styleType: StyleType.AccentColor, getColor: palette => palette.AccentColor);
 79556            AddColor(styleType: StyleType.BorderColor, getColor: palette => palette.BorderColor);
 79557            AddColor(styleType: StyleType.CaretColor, getColor: palette => palette.CaretColor);
 79558            AddColor(styleType: StyleType.Color, getColor: palette => palette.ForegroundColor);
 79559            AddColor(styleType: StyleType.TextDecorationColor, getColor: palette => palette.TextDecorationColor);
 60        }
 61
 111062        AddColor(styleType: StyleType.OutlineColor, getColor: palette => palette.OutlineColor);
 7463    }
 64
 65    /// <summary>Adds a color mapping for the specified <see cref="StyleType" /> using the provided color selector.</sum
 66    /// <param name="styleType">The <see cref="StyleType" /> to which the color should apply.</param>
 67    /// <param name="getColor">A function that extracts a <see cref="HexColor" /> from a <see cref="BrandPalette" />.</p
 68    private void AddColor(StyleType styleType, Func<BrandPalette, HexColor?> getColor)
 37369        => AddRange(
 37370            collection: ThemeMapper.GetColors(
 37371                isHighContrast: IsHighContrast,
 37372                isVariant: _isVariant,
 37373                paletteType: _paletteType,
 37374                componentType: ComponentType,
 37375                styleType: styleType,
 37376                getColor: getColor
 37377            )
 37378        );
 79}