Input fields and refactors required to support them
This commit is contained in:
@@ -3,23 +3,61 @@ 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 class Rect(float width = 0.0f, float height = 0.0f)
|
||||
{
|
||||
public float Width { get; set; } = Width;
|
||||
public float Height { get; set; } = Height;
|
||||
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 int CompareTo(Rect other) => 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;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rectangle with the smallest width.
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <returns></returns>
|
||||
public static Rect MinWidth(Rect a, Rect b)
|
||||
{
|
||||
if (a < b)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else if (a > b)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
public static Rect MaxWidth(Rect a, Rect b)
|
||||
{
|
||||
if (a > b)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
if (a < b)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
public static Rect operator +(Rect left, Rect right)
|
||||
{
|
||||
var width = left.Width + right.Width;
|
||||
var height = left.Height + right.Height;
|
||||
return new(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,6 +70,8 @@ public struct Size : IEquatable<Size>
|
||||
public float Top;
|
||||
public float Bottom;
|
||||
|
||||
public static Size Zero => new Size(0.0f);
|
||||
|
||||
public Size(float uniform)
|
||||
{
|
||||
Left = Right = Top = Bottom = uniform;
|
||||
@@ -51,8 +91,6 @@ public struct Size : IEquatable<Size>
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
public static Size Zero => new Size(0);
|
||||
|
||||
public static Rect operator +(Size margin, Rect rect) =>
|
||||
new Rect(rect.Width + margin.Left + margin.Right,
|
||||
rect.Height + margin.Top + margin.Bottom);
|
||||
|
||||
Reference in New Issue
Block a user