PosFunc.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Represents a position that is computed by executing a function that returns an integer position.
  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="pos">The position.</param>
  13. public class PosFunc (Func<int> pos) : Pos
  14. {
  15. /// <summary>
  16. /// Gets the function that computes the position.
  17. /// </summary>
  18. public new Func<int> Func { get; } = pos;
  19. /// <inheritdoc/>
  20. public override bool Equals (object? other) { return other is PosFunc f && f.Func () == Func (); }
  21. /// <inheritdoc/>
  22. public override int GetHashCode () { return Func.GetHashCode (); }
  23. /// <inheritdoc/>
  24. public override string ToString () { return $"PosFunc({Func ()})"; }
  25. internal override int GetAnchor (int size) { return Func (); }
  26. }