#nullable enable
namespace Terminal.Gui;
///
/// Represents a dimension that is a combination of two other dimensions.
///
///
/// Indicates whether the two dimensions are added or subtracted.
///
///
/// This is a low-level API that is typically used internally by the layout system. Use the various static
/// methods on the class to create objects instead.
///
/// The left dimension.
/// The right dimension.
public record DimCombine (AddOrSubtract Add, Dim Left, Dim Right) : Dim
{
///
/// Gets whether the two dimensions are added or subtracted.
///
public AddOrSubtract Add { get; } = Add;
///
/// Gets the left dimension.
///
public Dim Left { get; } = Left;
///
/// Gets the right dimension.
///
public Dim Right { get; } = Right;
///
public override string ToString () { return $"Combine({Left}{(Add == AddOrSubtract.Add ? '+' : '-')}{Right})"; }
internal override int GetAnchor (int size)
{
if (Add == AddOrSubtract.Add)
{
return Left!.GetAnchor (size) + Right!.GetAnchor (size);
}
return Left!.GetAnchor (size) - Right!.GetAnchor (size);
}
internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension)
{
int newDimension;
if (Add == AddOrSubtract.Add)
{
newDimension = Left!.Calculate (location, superviewContentSize, us, dimension) + Right!.Calculate (location, superviewContentSize, us, dimension);
}
else
{
newDimension = Math.Max (
0,
Left!.Calculate (location, superviewContentSize, us, dimension)
- Right!.Calculate (location, superviewContentSize, us, dimension));
}
return newDimension;
}
}