PosFunc.cs 1.1 KB

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