PosPercent.cs 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Represents a position that is a percentage of the width or height of the SuperView.
  5. /// </summary>
  6. /// <remarks>
  7. /// <para>
  8. /// This is a low-level API that is typically used internally by the layout system. Use the various static
  9. /// methods on the <see cref="Pos"/> class to create <see cref="Pos"/> objects instead.
  10. /// </para>
  11. /// </remarks>
  12. /// <param name="percent"></param>
  13. public class PosPercent (int percent) : Pos
  14. {
  15. /// <summary>
  16. /// Gets the percentage of the width or height of the SuperView.
  17. /// </summary>
  18. public new int Percent { get; } = percent;
  19. /// <inheritdoc/>
  20. public override bool Equals (object? other) { return other is PosPercent i && i.Percent == Percent; }
  21. /// <inheritdoc/>
  22. public override int GetHashCode () { return Percent.GetHashCode (); }
  23. /// <inheritdoc/>
  24. public override string ToString () { return $"Percent({Percent})"; }
  25. internal override int GetAnchor (int size) { return (int)(size * (Percent / 100f)); }
  26. }