#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 class 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) { int la = Left!.GetAnchor (size); int ra = Right!.GetAnchor (size); if (Add == AddOrSubtract.Add) { return la + ra; } return la - ra; } internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { int leftNewDim = Left!.Calculate (location, superviewContentSize, us, dimension); int rightNewDim = Right!.Calculate (location, superviewContentSize, us, dimension); int newDimension; if (Add == AddOrSubtract.Add) { newDimension = leftNewDim + rightNewDim; } else { newDimension = Math.Max (0, leftNewDim - rightNewDim); } return newDimension; } /// /// Diagnostics API to determine if this Dim object references other views. /// /// internal override bool ReferencesOtherViews () { if (Left!.ReferencesOtherViews ()) { return true; } if (Right!.ReferencesOtherViews ()) { return true; } return false; } }