using System.Diagnostics.CodeAnalysis; namespace RhythmBase.Components.RichText { /// /// Represents a rich string style. /// public struct RDRichStringStyle : IRDRichStringStyle { /// /// 获取或设置文本的颜色。 /// public RDColor? Color { get; set; } /// public static bool HasPhrase => false; /// public static string GetXmlTag(RDRichStringStyle before, RDRichStringStyle after) { string tag = ""; IRDRichStringStyle.TryAddTag(ref tag, "color", before.Color?.TryGetName(out string[] namesbefore) == true ? namesbefore[0].ToLower() : before.Color?.ToString(before.Color?.A == 255 ? "#RRGGBB" : "#RRGGBBAA"), after.Color?.TryGetName(out string[] namesafter) == true ? namesafter[0].ToLower() : after.Color?.ToString(after.Color?.A == 255 ? "#RRGGBB" : "#RRGGBBAA")); return tag; } /// public readonly bool Equals(RDRichStringStyle other) => this == other; /// public readonly override bool Equals([NotNullWhen(true)] object? obj) => obj is RDRichStringStyle e && Equals(e); /// public bool ResetProperty(string name) { switch (name) { case "color": Color = null; break; default: return false; } return true; } /// public bool SetProperty(string name, string value) { switch (name) { case "color": if (RDColor.TryFromName(value, out RDColor color)) Color = color; else if (RDColor.TryFromRgba(value, out color)) Color = color; else return false; break; default: return false; } return true; } /// public static bool operator ==(RDRichStringStyle left, RDRichStringStyle right) => left.Color == right.Color; /// public static bool operator !=(RDRichStringStyle left, RDRichStringStyle right) => !(left == right); /// public readonly override int GetHashCode() => Color.GetHashCode(); } }