DimFunc.cs 1.2 KB

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