mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +01:00
class Dim -> struct Dim
This commit is contained in:
@@ -78,7 +78,7 @@ namespace Terminal.Gui;
|
||||
/// </para>
|
||||
/// <para></para>
|
||||
/// </remarks>
|
||||
public abstract class Dim
|
||||
public abstract record Dim
|
||||
{
|
||||
#region static Dim creation methods
|
||||
|
||||
|
||||
@@ -11,14 +11,8 @@ namespace Terminal.Gui;
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="size"></param>
|
||||
public class DimAbsolute (int size) : Dim
|
||||
public record DimAbsolute (int size) : Dim
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals (object? other) { return other is DimAbsolute abs && abs.Size == Size; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode () { return Size.GetHashCode (); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the dimension.
|
||||
/// </summary>
|
||||
|
||||
@@ -15,31 +15,8 @@ namespace Terminal.Gui;
|
||||
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class DimAuto : Dim
|
||||
public record DimAuto : Dim
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool Equals (object? other)
|
||||
{
|
||||
if (ReferenceEquals (this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (other is not DimAuto auto)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return EqualityComparer<Dim?>.Default.Equals (MinimumContentDim, auto.MinimumContentDim) &&
|
||||
EqualityComparer<Dim?>.Default.Equals (MaximumContentDim, auto.MaximumContentDim) &&
|
||||
Style == auto.Style;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return HashCode.Combine (MinimumContentDim, MaximumContentDim, Style);
|
||||
}
|
||||
private readonly Dim? _maximumContentDim;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Terminal.Gui;
|
||||
/// </remarks>
|
||||
/// <param name="left">The left dimension.</param>
|
||||
/// <param name="right">The right dimension.</param>
|
||||
public class DimCombine (AddOrSubtract add, Dim left, Dim right) : Dim
|
||||
public record DimCombine (AddOrSubtract add, Dim left, Dim right) : Dim
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether the two dimensions are added or subtracted.
|
||||
|
||||
@@ -9,14 +9,8 @@ namespace Terminal.Gui;
|
||||
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||
/// </remarks>
|
||||
/// <param name="margin">The margin to not fill.</param>
|
||||
public class DimFill (int margin) : Dim
|
||||
public record DimFill (int margin) : Dim
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals (object? other) { return other is DimFill fill && fill.Margin == Margin; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode () { return Margin.GetHashCode (); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the margin to not fill.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,11 +9,8 @@ namespace Terminal.Gui;
|
||||
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||
/// </remarks>
|
||||
/// <param name="dim"></param>
|
||||
public class DimFunc (Func<int> dim) : Dim
|
||||
public record DimFunc (Func<int> dim) : Dim
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals (object? other) { return other is DimFunc f && f.Func () == Func (); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the function that computes the dimension.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,14 +13,8 @@ namespace Terminal.Gui;
|
||||
/// If <see cref="DimPercentMode.Position"/> the dimension is computed using the View's position (<see cref="View.X"/> or
|
||||
/// <see cref="View.Y"/>); otherwise, the dimension is computed using the View's <see cref="View.GetContentSize ()"/>.
|
||||
/// </param>
|
||||
public class DimPercent (int percent, DimPercentMode mode = DimPercentMode.ContentSize) : Dim
|
||||
public record DimPercent (int percent, DimPercentMode mode = DimPercentMode.ContentSize) : Dim
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals (object? other) { return other is DimPercent f && f.Percent == Percent && f.Mode == Mode; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode () { return Percent.GetHashCode (); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the percentage.
|
||||
/// </summary>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Terminal.Gui;
|
||||
/// This is a low-level API that is typically used internally by the layout system. Use the various static
|
||||
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||
/// </remarks>
|
||||
public class DimView : Dim
|
||||
public record DimView : Dim
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DimView"/> class.
|
||||
@@ -26,12 +26,6 @@ public class DimView : Dim
|
||||
/// </summary>
|
||||
public Dimension Dimension { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals (object? other) { return other is DimView abs && abs.Target == Target && abs.Dimension == Dimension; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode () { return Target!.GetHashCode (); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the View the dimension is anchored to.
|
||||
/// </summary>
|
||||
|
||||
@@ -14,9 +14,12 @@ public class DimFuncTests (ITestOutputHelper output)
|
||||
Func<int> f2 = () => 0;
|
||||
|
||||
Dim dim1 = Func (f1);
|
||||
Dim dim2 = Func (f2);
|
||||
Dim dim2 = Func (f1);
|
||||
Assert.Equal (dim1, dim2);
|
||||
|
||||
dim2 = Func (f2);
|
||||
Assert.NotEqual (dim1, dim2);
|
||||
|
||||
f2 = () => 1;
|
||||
dim2 = Func (f2);
|
||||
Assert.NotEqual (dim1, dim2);
|
||||
|
||||
Reference in New Issue
Block a user