// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osuTK; using System; using osu.Framework.Graphics.Transforms; using osu.Framework.Utils; namespace osu.Framework.Graphics { /// /// Holds data about the margin or padding of a . /// The margin describes the size of an empty area around its , while the padding describes the size of an empty area inside its container. /// public struct MarginPadding : IInterpolable, IEquatable { /// /// The absolute size of the space that should be left empty above the if used as margin, or /// the absolute size of the space that should be left empty from the top of the container if used as padding. /// public float Top; /// /// The absolute size of the space that should be left empty to the left of the if used as margin, or /// the absolute size of the space that should be left empty from the left of the container if used as padding. /// public float Left; /// /// The absolute size of the space that should be left empty below the if used as margin, or /// the absolute size of the space that should be left empty from the bottom of the container if used as padding. /// public float Bottom; /// /// The absolute size of the space that should be left empty to the right of the if used as margin, or /// the absolute size of the space that should be left empty from the right of the container if used as padding. /// public float Right; /// /// Gets the total absolute size of the empty space horizontally around the if used as margin, or /// the absolute size of the space left empty from the right and left of the container if used as padding. /// Effectively + . /// public readonly float TotalHorizontal => Left + Right; /// /// Sets the values of both and to the assigned value. /// public float Horizontal { set => Left = Right = value; } /// /// Gets the total absolute size of the empty space vertically around the or /// the absolute size of the space left empty from the top and bottom of the container if used as padding. /// Effectively + . /// public readonly float TotalVertical => Top + Bottom; /// /// Sets the values of both and to the assigned value. /// public float Vertical { set => Top = Bottom = value; } /// /// Gets the total absolute size of the empty space horizontally (x coordinate) and vertically (y coordinate) around the or inside the container if used as padding. /// public readonly Vector2 Total => new Vector2(TotalHorizontal, TotalVertical); /// /// Initializes all four sides (, , and ) to the given value. /// /// The absolute size of the space that should be left around every side of the . public MarginPadding(float allSides) { Top = Left = Bottom = Right = allSides; } public readonly bool Equals(MarginPadding other) => Top == other.Top && Left == other.Left && Bottom == other.Bottom && Right == other.Right; public override readonly string ToString() => $@"({Top}, {Left}, {Bottom}, {Right})"; public static MarginPadding operator -(MarginPadding mp) => new MarginPadding { Left = -mp.Left, Top = -mp.Top, Right = -mp.Right, Bottom = -mp.Bottom, }; public MarginPadding ValueAt(double time, MarginPadding startValue, MarginPadding endValue, double startTime, double endTime, in TEasing easing) where TEasing : IEasingFunction => new MarginPadding { Left = Interpolation.ValueAt(time, startValue.Left, endValue.Left, startTime, endTime, easing), Top = Interpolation.ValueAt(time, startValue.Top, endValue.Top, startTime, endTime, easing), Right = Interpolation.ValueAt(time, startValue.Right, endValue.Right, startTime, endTime, easing), Bottom = Interpolation.ValueAt(time, startValue.Bottom, endValue.Bottom, startTime, endTime, easing), }; } }