| | | 1 | | namespace Allyaria.Theming.Contracts; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Provides a base implementation for applying theme updates across components, managing a collection of |
| | | 5 | | /// <see cref="ThemeUpdater" /> instances that describe style changes for various theme states and components. |
| | | 6 | | /// </summary> |
| | | 7 | | internal abstract class ThemeApplierBase : IReadOnlyList<ThemeUpdater> |
| | | 8 | | { |
| | | 9 | | /// <summary>Internal backing list for theme updaters.</summary> |
| | 454 | 10 | | private readonly List<ThemeUpdater> _internalList = new(); |
| | | 11 | | |
| | | 12 | | /// <summary>Initializes a new instance of the <see cref="ThemeApplierBase" /> class.</summary> |
| | | 13 | | /// <param name="themeMapper">The <see cref="ThemeMapper" /> instance used to resolve style mappings.</param> |
| | | 14 | | /// <param name="isHighContrast">A value indicating whether the theme is high-contrast.</param> |
| | | 15 | | /// <param name="componentType">The <see cref="ComponentType" /> to which the theme applies.</param> |
| | 454 | 16 | | protected ThemeApplierBase(ThemeMapper themeMapper, bool isHighContrast, ComponentType componentType) |
| | | 17 | | { |
| | 454 | 18 | | ThemeMapper = themeMapper; |
| | 454 | 19 | | IsHighContrast = isHighContrast; |
| | 454 | 20 | | ComponentType = componentType; |
| | 454 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary>Gets the component type this applier targets.</summary> |
| | 1292 | 24 | | protected ComponentType ComponentType { get; } |
| | | 25 | | |
| | | 26 | | /// <summary>Gets the number of <see cref="ThemeUpdater" /> items contained within this instance.</summary> |
| | 15 | 27 | | public int Count => _internalList.Count; |
| | | 28 | | |
| | | 29 | | /// <summary>Gets a value indicating whether the current theme is high-contrast.</summary> |
| | 1292 | 30 | | protected bool IsHighContrast { get; } |
| | | 31 | | |
| | | 32 | | /// <summary>Gets the <see cref="ThemeMapper" /> responsible for mapping style data to theme properties.</summary> |
| | 373 | 33 | | protected ThemeMapper ThemeMapper { get; } |
| | | 34 | | |
| | | 35 | | /// <summary>Gets the <see cref="ThemeUpdater" /> at the specified index.</summary> |
| | | 36 | | /// <param name="index">The zero-based index of the element to retrieve.</param> |
| | | 37 | | /// <returns>The <see cref="ThemeUpdater" /> at the specified index.</returns> |
| | 4 | 38 | | public ThemeUpdater this[int index] => _internalList[index: index]; |
| | | 39 | | |
| | | 40 | | /// <summary>Adds a single <see cref="ThemeUpdater" /> to the internal collection.</summary> |
| | | 41 | | /// <param name="item">The <see cref="ThemeUpdater" /> to add.</param> |
| | 937 | 42 | | protected void Add(ThemeUpdater item) => _internalList.Add(item: item); |
| | | 43 | | |
| | | 44 | | /// <summary>Adds a range of <see cref="ThemeUpdater" /> items to the internal collection.</summary> |
| | | 45 | | /// <param name="collection">A read-only list of <see cref="ThemeUpdater" /> instances to append.</param> |
| | 411 | 46 | | protected void AddRange(IReadOnlyList<ThemeUpdater> collection) => _internalList.AddRange(collection: collection); |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Creates a new <see cref="ThemeUpdater" /> for the specified style type and value, automatically setting the rele |
| | | 50 | | /// <see cref="ThemeNavigator" /> parameters. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <param name="styleType">The style type associated with this updater.</param> |
| | | 53 | | /// <param name="value">The value to apply for the style type.</param> |
| | | 54 | | /// <returns>A constructed <see cref="ThemeUpdater" /> with navigation and value set.</returns> |
| | | 55 | | protected ThemeUpdater CreateUpdater(StyleType styleType, IStyleValue value) |
| | 919 | 56 | | => new( |
| | 919 | 57 | | Navigator: ThemeNavigator.Initialize |
| | 919 | 58 | | .SetComponentTypes(items: ComponentType) |
| | 919 | 59 | | .SetContrastThemeTypes(isHighContrast: IsHighContrast) |
| | 919 | 60 | | .SetAllComponentStates() |
| | 919 | 61 | | .SetStyleTypes(styleType), |
| | 919 | 62 | | Value: value |
| | 919 | 63 | | ); |
| | | 64 | | |
| | | 65 | | /// <summary>Returns an enumerator that iterates through the contained <see cref="ThemeUpdater" /> collection.</summ |
| | | 66 | | /// <returns>An enumerator for the collection.</returns> |
| | 471 | 67 | | public IEnumerator<ThemeUpdater> GetEnumerator() => _internalList.GetEnumerator(); |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Returns a non-generic enumerator that iterates through the contained <see cref="ThemeUpdater" /> collection. |
| | | 71 | | /// </summary> |
| | | 72 | | /// <returns>A non-generic enumerator for the collection.</returns> |
| | 1 | 73 | | IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_internalList).GetEnumerator(); |
| | | 74 | | } |