// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using JetBrains.Annotations; namespace osu.Framework.Graphics.Sprites { /// /// Represents a specific usage of an icon. /// public readonly struct IconUsage : IEquatable { /// /// The font family name. /// [CanBeNull] public string Family { get; } /// /// The font weight. /// [CanBeNull] public string Weight { get; } /// /// The font's full name to be used for lookups. This is an aggregate of all other properties of . /// /// The format is of the form:
/// {Family}
/// {Family}-Italic
/// {Family}-{Weight}Italic ///
///
[NotNull] public string FontName { get; } /// /// The icon character. /// public char Icon { get; } /// /// Creates an instance of using the specified font , font and a value indicating whether the used font is italic or not. /// /// /// The icon. /// The font family name. /// The font weight. public IconUsage(char icon, [CanBeNull] string family = null, [CanBeNull] string weight = null) { Icon = icon; Family = family; Weight = weight; FontName = Family + "-"; if (!string.IsNullOrEmpty(weight)) FontName += weight; FontName = FontName.TrimEnd('-'); } /// /// Creates a new by applying adjustments to this . /// /// The font family. If null, the value is copied from this . /// The font weight. If null, the value is copied from this . /// The resulting . public IconUsage With([CanBeNull] string family = null, [CanBeNull] string weight = null) => new IconUsage(Icon, family ?? Family, weight ?? Weight); public override string ToString() => $"Icon={Icon} Font={FontName}"; public bool Equals(IconUsage other) => Icon == other.Icon && Family == other.Family && Weight == other.Weight; public override bool Equals(object obj) => obj is IconUsage other && Equals(other); public override int GetHashCode() => HashCode.Combine(Family, Icon, Weight); } }