DimFunc.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Represents a function <see cref="Dim"/> object that computes the dimension by 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="dim"></param>
  11. public class DimFunc (Func<int> dim) : Dim
  12. {
  13. /// <inheritdoc/>
  14. public override bool Equals (object? other) { return other is DimFunc f && f.Func () == Func (); }
  15. /// <summary>
  16. /// Gets the function that computes the dimension.
  17. /// </summary>
  18. public new Func<int> Func { get; } = dim;
  19. /// <inheritdoc/>
  20. public override int GetHashCode () { return Func.GetHashCode (); }
  21. /// <inheritdoc/>
  22. public override string ToString () { return $"DimFunc({Func ()})"; }
  23. internal override int GetAnchor (int size) { return Func (); }
  24. }