DimFunc.cs 1.2 KB

1234567891011121314151617181920212223242526272829
  1. namespace Terminal.Gui.ViewBase;
  2. /// <summary>
  3. /// Represents a function <see cref="Dim"/> object that computes the dimension based on the passed view and by
  4. /// executing the provided function.
  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="Dim"/> class to create <see cref="Dim"/> objects instead.
  9. /// </remarks>
  10. /// <param name="Fn">The function that computes the dimension. If this function throws <see cref="LayoutException"/>... </param>
  11. /// <param name="View">The <see cref="Dim"/> returned from the function based on the passed view.</param>
  12. public record DimFunc (Func<View?, int> Fn, View? View = null) : Dim
  13. {
  14. /// <summary>
  15. /// Gets the function that computes the dimension.
  16. /// </summary>
  17. public Func<View?, int> Fn { get; } = Fn;
  18. /// <summary>
  19. /// Gets the passed view that the dimension is based on.
  20. /// </summary>
  21. public View? View { get; } = View;
  22. /// <inheritdoc/>
  23. public override string ToString () { return $"DimFunc({Fn (View)})"; }
  24. internal override int GetAnchor (int size) { return Fn (View); }
  25. }