DimView.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 record 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. /// <summary>
  27. /// Gets the View the dimension is anchored to.
  28. /// </summary>
  29. public View? Target { get; init; }
  30. /// <inheritdoc/>
  31. public override string ToString ()
  32. {
  33. if (Target == null)
  34. {
  35. throw new NullReferenceException ();
  36. }
  37. return $"View({Dimension},{Target})";
  38. }
  39. internal override int GetAnchor (int size)
  40. {
  41. return Dimension switch
  42. {
  43. Dimension.Height => Target!.Frame.Height,
  44. Dimension.Width => Target!.Frame.Width,
  45. _ => 0
  46. };
  47. }
  48. internal override bool ReferencesOtherViews () { return true; }
  49. }