| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>alignment-baseline</c> value used within the Allyaria theming system. Provides a strongly typed |
| | | 5 | | /// wrapper around standard CSS alignment-baseline keywords. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleAlignmentBaseline : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleAlignmentBaseline" /> record with the specified baseline align |
| | | 11 | | /// kind. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="kind">The baseline alignment kind to represent.</param> |
| | | 14 | | public StyleAlignmentBaseline(Kind kind) |
| | 54 | 15 | | : base(value: kind.GetDescription()) { } |
| | | 16 | | |
| | | 17 | | /// <summary>Defines the supported CSS <c>alignment-baseline</c> values.</summary> |
| | | 18 | | public enum Kind |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Aligns the element with the alphabetic baseline of its parent. Typically used for Latin-based scripts. |
| | | 22 | | /// </summary> |
| | | 23 | | [Description(description: "alphabetic")] |
| | | 24 | | Alphabetic, |
| | | 25 | | |
| | | 26 | | /// <summary>Aligns the element with the dominant baseline of its parent.</summary> |
| | | 27 | | [Description(description: "baseline")] |
| | | 28 | | Baseline, |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Aligns the element so that the geometric center of its box aligns with the parent's alignment baseline. |
| | | 32 | | /// </summary> |
| | | 33 | | [Description(description: "central")] |
| | | 34 | | Central, |
| | | 35 | | |
| | | 36 | | /// <summary>Aligns the element with the ideographic baseline used for East Asian text.</summary> |
| | | 37 | | [Description(description: "ideographic")] |
| | | 38 | | Ideographic, |
| | | 39 | | |
| | | 40 | | /// <summary>Aligns the element with the mathematical baseline, used for math formulas or similar content.</summ |
| | | 41 | | [Description(description: "mathematical")] |
| | | 42 | | Mathematical, |
| | | 43 | | |
| | | 44 | | /// <summary>Aligns the element with the vertical middle of its parent’s box.</summary> |
| | | 45 | | [Description(description: "middle")] |
| | | 46 | | Middle, |
| | | 47 | | |
| | | 48 | | /// <summary>Aligns the element with the bottom of the parent's text content area.</summary> |
| | | 49 | | [Description(description: "text-bottom")] |
| | | 50 | | TextBottom, |
| | | 51 | | |
| | | 52 | | /// <summary>Aligns the element with the top of the parent's text content area.</summary> |
| | | 53 | | [Description(description: "text-top")] |
| | | 54 | | TextTop |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Parses a string representation of a CSS <c>alignment-baseline</c> value into a <see cref="StyleAlignmentBaseline |
| | | 59 | | /// instance. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="value">The string representation of the alignment-baseline value.</param> |
| | | 62 | | /// <returns>A new <see cref="StyleAlignmentBaseline" /> instance representing the parsed value.</returns> |
| | | 63 | | /// <exception cref="AryArgumentException"> |
| | | 64 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 65 | | /// </exception> |
| | | 66 | | public static StyleAlignmentBaseline Parse(string? value) |
| | 15 | 67 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 15 | 68 | | ? new StyleAlignmentBaseline(kind: kind) |
| | 15 | 69 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 70 | | |
| | | 71 | | /// <summary>Attempts to parse a string into a <see cref="StyleAlignmentBaseline" /> instance.</summary> |
| | | 72 | | /// <param name="value">The string representation of the alignment-baseline value to parse.</param> |
| | | 73 | | /// <param name="result"> |
| | | 74 | | /// When this method returns, contains the parsed <see cref="StyleAlignmentBaseline" /> instance or <see langword="n |
| | | 75 | | /// if parsing failed. |
| | | 76 | | /// </param> |
| | | 77 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 78 | | public static bool TryParse(string? value, out StyleAlignmentBaseline? result) |
| | | 79 | | { |
| | | 80 | | try |
| | | 81 | | { |
| | 3 | 82 | | result = Parse(value: value); |
| | | 83 | | |
| | 1 | 84 | | return true; |
| | | 85 | | } |
| | 2 | 86 | | catch |
| | | 87 | | { |
| | 2 | 88 | | result = null; |
| | | 89 | | |
| | 2 | 90 | | return false; |
| | | 91 | | } |
| | 3 | 92 | | } |
| | | 93 | | |
| | | 94 | | /// <summary>Implicitly converts a string into a <see cref="StyleAlignmentBaseline" /> instance.</summary> |
| | | 95 | | /// <param name="value">The string value representing the baseline alignment.</param> |
| | | 96 | | /// <returns>A <see cref="StyleAlignmentBaseline" /> instance equivalent to the provided value.</returns> |
| | | 97 | | /// <exception cref="AryArgumentException">Thrown when the string cannot be parsed into a valid alignment baseline k |
| | 2 | 98 | | public static implicit operator StyleAlignmentBaseline(string? value) => Parse(value: value); |
| | | 99 | | |
| | | 100 | | /// <summary>Implicitly converts a <see cref="StyleAlignmentBaseline" /> instance into its string value.</summary> |
| | | 101 | | /// <param name="value">The <see cref="StyleAlignmentBaseline" /> instance to convert.</param> |
| | | 102 | | /// <returns> |
| | | 103 | | /// The underlying CSS <c>alignment-baseline</c> string value, or an empty string if <paramref name="value" /> is |
| | | 104 | | /// <see langword="null" />. |
| | | 105 | | /// </returns> |
| | 2 | 106 | | public static implicit operator string(StyleAlignmentBaseline? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 107 | | } |