| | | 1 | | namespace 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> |
| | | 17 | | internal 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) |
| | 74 | 43 | | : base(themeMapper: themeMapper, isHighContrast: isHighContrast, componentType: componentType) |
| | | 44 | | { |
| | 74 | 45 | | _isVariant = isVariant; |
| | 74 | 46 | | _paletteType = paletteType; |
| | | 47 | | |
| | 74 | 48 | | if (hasBackground) |
| | | 49 | | { |
| | 510 | 50 | | AddColor(styleType: StyleType.BackgroundColor, getColor: palette => palette.BackgroundColor); |
| | | 51 | | } |
| | | 52 | | |
| | 74 | 53 | | if (!isOutline) |
| | | 54 | | { |
| | 795 | 55 | | AddColor(styleType: StyleType.AccentColor, getColor: palette => palette.AccentColor); |
| | 795 | 56 | | AddColor(styleType: StyleType.BorderColor, getColor: palette => palette.BorderColor); |
| | 795 | 57 | | AddColor(styleType: StyleType.CaretColor, getColor: palette => palette.CaretColor); |
| | 795 | 58 | | AddColor(styleType: StyleType.Color, getColor: palette => palette.ForegroundColor); |
| | 795 | 59 | | AddColor(styleType: StyleType.TextDecorationColor, getColor: palette => palette.TextDecorationColor); |
| | | 60 | | } |
| | | 61 | | |
| | 1110 | 62 | | AddColor(styleType: StyleType.OutlineColor, getColor: palette => palette.OutlineColor); |
| | 74 | 63 | | } |
| | | 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) |
| | 373 | 69 | | => AddRange( |
| | 373 | 70 | | collection: ThemeMapper.GetColors( |
| | 373 | 71 | | isHighContrast: IsHighContrast, |
| | 373 | 72 | | isVariant: _isVariant, |
| | 373 | 73 | | paletteType: _paletteType, |
| | 373 | 74 | | componentType: ComponentType, |
| | 373 | 75 | | styleType: styleType, |
| | 373 | 76 | | getColor: getColor |
| | 373 | 77 | | ) |
| | 373 | 78 | | ); |
| | | 79 | | } |