PosFunc.cs 1.1 KB

12345678910111213141516171819202122232425262728
  1. namespace Terminal.Gui.ViewBase;
  2. /// <summary>
  3. /// Represents a position that is computed by executing a function that returns an integer position.
  4. /// </summary>
  5. /// <remarks>
  6. /// This is a low-level API that is typically used internally by the layout system. Use the various static
  7. /// methods on the <see cref="Pos"/> class to create <see cref="Pos"/> objects instead.
  8. /// </remarks>
  9. /// <param name="Fn">The function that computes the position. If this function throws <see cref="LayoutException"/>... </param>
  10. /// <param name="View">The <see cref="Pos"/> returned from the function based on the passed view.</param>
  11. public record PosFunc (Func<View?, int> Fn, View? View = null) : Pos
  12. {
  13. /// <summary>
  14. /// Gets the function that computes the position.
  15. /// </summary>
  16. public Func<View?, int> Fn { get; } = Fn;
  17. /// <summary>
  18. /// Gets the passed view that the position is based on.
  19. /// </summary>
  20. public View? View { get; } = View;
  21. /// <inheritdoc/>
  22. public override string ToString () { return $"PosFunc({Fn (View)})"; }
  23. internal override int GetAnchor (int size) { return Fn (View); }
  24. }