#nullable enable namespace Terminal.Gui; /// /// Represents a dimension that is a percentage of the width or height of the SuperView. /// /// /// 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 percentage. /// /// If the dimension is computed using the View's position ( or /// ); otherwise, the dimension is computed using the View's . /// public class DimPercent (int percent, DimPercentMode mode = DimPercentMode.ContentSize) : Dim { /// public override bool Equals (object? other) { return other is DimPercent f && f.Percent == Percent && f.Mode == Mode; } /// public override int GetHashCode () { return Percent.GetHashCode (); } /// /// Gets the percentage. /// public new int Percent { get; } = percent; /// /// /// public override string ToString () { return $"Percent({Percent},{Mode})"; } /// /// Gets whether the dimension is computed using the View's position or GetContentSize (). /// public DimPercentMode Mode { get; } = mode; internal override int GetAnchor (int size) { return (int)(size * (Percent / 100f)); } internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { return Mode == DimPercentMode.Position ? Math.Max (GetAnchor (superviewContentSize - location), 0) : GetAnchor (superviewContentSize); } }