mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
class Dim -> struct Dim
This commit is contained in:
@@ -78,7 +78,7 @@ namespace Terminal.Gui;
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// <para></para>
|
/// <para></para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public abstract class Dim
|
public abstract record Dim
|
||||||
{
|
{
|
||||||
#region static Dim creation methods
|
#region static Dim creation methods
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,8 @@ namespace Terminal.Gui;
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="size"></param>
|
/// <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>
|
/// <summary>
|
||||||
/// Gets the size of the dimension.
|
/// Gets the size of the dimension.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -15,31 +15,8 @@ namespace Terminal.Gui;
|
|||||||
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </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;
|
private readonly Dim? _maximumContentDim;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Terminal.Gui;
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="left">The left dimension.</param>
|
/// <param name="left">The left dimension.</param>
|
||||||
/// <param name="right">The right 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>
|
/// <summary>
|
||||||
/// Gets whether the two dimensions are added or subtracted.
|
/// 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.
|
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="margin">The margin to not fill.</param>
|
/// <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>
|
/// <summary>
|
||||||
/// Gets the margin to not fill.
|
/// Gets the margin to not fill.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ namespace Terminal.Gui;
|
|||||||
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="dim"></param>
|
/// <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>
|
/// <summary>
|
||||||
/// Gets the function that computes the dimension.
|
/// Gets the function that computes the dimension.
|
||||||
/// </summary>
|
/// </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
|
/// 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 ()"/>.
|
/// <see cref="View.Y"/>); otherwise, the dimension is computed using the View's <see cref="View.GetContentSize ()"/>.
|
||||||
/// </param>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets the percentage.
|
/// Gets the percentage.
|
||||||
/// </summary>
|
/// </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
|
/// 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.
|
/// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class DimView : Dim
|
public record DimView : Dim
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DimView"/> class.
|
/// Initializes a new instance of the <see cref="DimView"/> class.
|
||||||
@@ -26,12 +26,6 @@ public class DimView : Dim
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Dimension Dimension { get; }
|
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>
|
/// <summary>
|
||||||
/// Gets the View the dimension is anchored to.
|
/// Gets the View the dimension is anchored to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ public class DimFuncTests (ITestOutputHelper output)
|
|||||||
Func<int> f2 = () => 0;
|
Func<int> f2 = () => 0;
|
||||||
|
|
||||||
Dim dim1 = Func (f1);
|
Dim dim1 = Func (f1);
|
||||||
Dim dim2 = Func (f2);
|
Dim dim2 = Func (f1);
|
||||||
Assert.Equal (dim1, dim2);
|
Assert.Equal (dim1, dim2);
|
||||||
|
|
||||||
|
dim2 = Func (f2);
|
||||||
|
Assert.NotEqual (dim1, dim2);
|
||||||
|
|
||||||
f2 = () => 1;
|
f2 = () => 1;
|
||||||
dim2 = Func (f2);
|
dim2 = Func (f2);
|
||||||
Assert.NotEqual (dim1, dim2);
|
Assert.NotEqual (dim1, dim2);
|
||||||
|
|||||||
Reference in New Issue
Block a user