Make Rect a core type, move Color out of Utils.
This commit is contained in:
23
Voile/Source/Rect.cs
Normal file
23
Voile/Source/Rect.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace Voile;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a rectangle. Used to determine widget confines for UI layout.
|
||||
/// </summary>
|
||||
public record Rect(float Width = 0.0f, float Height = 0.0f)
|
||||
{
|
||||
public float Width { get; set; } = Width;
|
||||
public float Height { get; set; } = Height;
|
||||
public static Rect Zero => new Rect(0.0f, 0.0f);
|
||||
public float Area => Width * Height;
|
||||
|
||||
public int CompareTo(Rect? other)
|
||||
{
|
||||
if (other is null) return 1;
|
||||
return Area.CompareTo(other.Area);
|
||||
}
|
||||
|
||||
public static bool operator >(Rect left, Rect right) => left.CompareTo(right) > 0;
|
||||
public static bool operator <(Rect left, Rect right) => left.CompareTo(right) < 0;
|
||||
public static bool operator >=(Rect left, Rect right) => left.CompareTo(right) >= 0;
|
||||
public static bool operator <=(Rect left, Rect right) => left.CompareTo(right) <= 0;
|
||||
}
|
||||
Reference in New Issue
Block a user