DimView.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Represents a dimension that tracks the Height or Width of the specified View.
  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. public class DimView : Dim
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="DimView"/> class.
  14. /// </summary>
  15. /// <param name="view">The view the dimension is anchored to.</param>
  16. /// <param name="dimension">Indicates which dimension is tracked.</param>
  17. public DimView (View? view, Dimension dimension)
  18. {
  19. Target = view;
  20. Dimension = dimension;
  21. }
  22. /// <summary>
  23. /// Gets the indicated dimension of the View.
  24. /// </summary>
  25. public Dimension Dimension { get; }
  26. /// <inheritdoc/>
  27. public override bool Equals (object? other) { return other is DimView abs && abs.Target == Target && abs.Dimension == Dimension; }
  28. /// <inheritdoc/>
  29. public override int GetHashCode () { return Target!.GetHashCode (); }
  30. /// <summary>
  31. /// Gets the View the dimension is anchored to.
  32. /// </summary>
  33. public View? Target { get; init; }
  34. /// <inheritdoc/>
  35. public override string ToString ()
  36. {
  37. if (Target == null)
  38. {
  39. throw new NullReferenceException ();
  40. }
  41. return $"View({Dimension},{Target})";
  42. }
  43. internal override int GetAnchor (int size)
  44. {
  45. return Dimension switch
  46. {
  47. Dimension.Height => Target.Frame.Height,
  48. Dimension.Width => Target.Frame.Width,
  49. _ => 0
  50. };
  51. }
  52. internal override bool ReferencesOtherViews () { return true; }
  53. }