|
@@ -8,7 +8,10 @@ using Avalonia.Utilities;
|
|
|
|
|
|
|
|
namespace Avalonia
|
|
namespace Avalonia
|
|
|
{
|
|
{
|
|
|
- public struct CornerRadius
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Represents the radii of a rectangle's corners.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public readonly struct CornerRadius : IEquatable<CornerRadius>
|
|
|
{
|
|
{
|
|
|
static CornerRadius()
|
|
static CornerRadius()
|
|
|
{
|
|
{
|
|
@@ -33,22 +36,59 @@ namespace Avalonia
|
|
|
BottomLeft = bottomLeft;
|
|
BottomLeft = bottomLeft;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Radius of the top left corner.
|
|
|
|
|
+ /// </summary>
|
|
|
public double TopLeft { get; }
|
|
public double TopLeft { get; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Radius of the top right corner.
|
|
|
|
|
+ /// </summary>
|
|
|
public double TopRight { get; }
|
|
public double TopRight { get; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Radius of the bottom right corner.
|
|
|
|
|
+ /// </summary>
|
|
|
public double BottomRight { get; }
|
|
public double BottomRight { get; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Radius of the bottom left corner.
|
|
|
|
|
+ /// </summary>
|
|
|
public double BottomLeft { get; }
|
|
public double BottomLeft { get; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Gets a value indicating whether all corner radii are set to 0.
|
|
|
|
|
+ /// </summary>
|
|
|
public bool IsEmpty => TopLeft.Equals(0) && IsUniform;
|
|
public bool IsEmpty => TopLeft.Equals(0) && IsUniform;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Gets a value indicating whether all corner radii are equal.
|
|
|
|
|
+ /// </summary>
|
|
|
public bool IsUniform => TopLeft.Equals(TopRight) && BottomLeft.Equals(BottomRight) && TopRight.Equals(BottomRight);
|
|
public bool IsUniform => TopLeft.Equals(TopRight) && BottomLeft.Equals(BottomRight) && TopRight.Equals(BottomRight);
|
|
|
|
|
|
|
|
- public override bool Equals(object obj)
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Returns a boolean indicating whether the corner radius is equal to the other given corner radius.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="other">The other corner radius to test equality against.</param>
|
|
|
|
|
+ /// <returns>True if this corner radius is equal to other; False otherwise.</returns>
|
|
|
|
|
+ public bool Equals(CornerRadius other)
|
|
|
{
|
|
{
|
|
|
- if (obj is CornerRadius)
|
|
|
|
|
- {
|
|
|
|
|
- return this == (CornerRadius)obj;
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ // ReSharper disable CompareOfFloatsByEqualityOperator
|
|
|
|
|
+ return TopLeft == other.TopLeft &&
|
|
|
|
|
+
|
|
|
|
|
+ TopRight == other.TopRight &&
|
|
|
|
|
+ BottomRight == other.BottomRight &&
|
|
|
|
|
+ BottomLeft == other.BottomLeft;
|
|
|
|
|
+ // ReSharper restore CompareOfFloatsByEqualityOperator
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Returns a boolean indicating whether the given Object is equal to this corner radius instance.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="obj">The Object to compare against.</param>
|
|
|
|
|
+ /// <returns>True if the Object is equal to this corner radius; False otherwise.</returns>
|
|
|
|
|
+ public override bool Equals(object obj) => obj is CornerRadius other && Equals(other);
|
|
|
|
|
+
|
|
|
public override int GetHashCode()
|
|
public override int GetHashCode()
|
|
|
{
|
|
{
|
|
|
return TopLeft.GetHashCode() ^ TopRight.GetHashCode() ^ BottomLeft.GetHashCode() ^ BottomRight.GetHashCode();
|
|
return TopLeft.GetHashCode() ^ TopRight.GetHashCode() ^ BottomLeft.GetHashCode() ^ BottomRight.GetHashCode();
|
|
@@ -61,7 +101,9 @@ namespace Avalonia
|
|
|
|
|
|
|
|
public static CornerRadius Parse(string s)
|
|
public static CornerRadius Parse(string s)
|
|
|
{
|
|
{
|
|
|
- using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Thickness"))
|
|
|
|
|
|
|
+ const string exceptionMessage = "Invalid CornerRadius.";
|
|
|
|
|
+
|
|
|
|
|
+ using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage))
|
|
|
{
|
|
{
|
|
|
if (tokenizer.TryReadDouble(out var a))
|
|
if (tokenizer.TryReadDouble(out var a))
|
|
|
{
|
|
{
|
|
@@ -78,21 +120,18 @@ namespace Avalonia
|
|
|
return new CornerRadius(a);
|
|
return new CornerRadius(a);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- throw new FormatException("Invalid CornerRadius.");
|
|
|
|
|
|
|
+ throw new FormatException(exceptionMessage);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static bool operator ==(CornerRadius cr1, CornerRadius cr2)
|
|
|
|
|
|
|
+ public static bool operator ==(CornerRadius left, CornerRadius right)
|
|
|
{
|
|
{
|
|
|
- return cr1.TopLeft.Equals(cr2.TopLeft)
|
|
|
|
|
- && cr1.TopRight.Equals(cr2.TopRight)
|
|
|
|
|
- && cr1.BottomRight.Equals(cr2.BottomRight)
|
|
|
|
|
- && cr1.BottomLeft.Equals(cr2.BottomLeft);
|
|
|
|
|
|
|
+ return left.Equals(right);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static bool operator !=(CornerRadius cr1, CornerRadius cr2)
|
|
|
|
|
|
|
+ public static bool operator !=(CornerRadius left, CornerRadius right)
|
|
|
{
|
|
{
|
|
|
- return !(cr1 == cr2);
|
|
|
|
|
|
|
+ return !(left == right);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|