DimView.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. namespace Terminal.Gui.ViewBase;
  2. /// <summary>
  3. /// Represents a dimension that tracks the Height or Width of the specified View.
  4. /// </summary>
  5. /// <remarks>
  6. /// This is a low-level API that is typically used internally by the layout system. Use the various static
  7. /// methods on the <see cref="Dim"/> class to create <see cref="Dim"/> objects instead.
  8. /// </remarks>
  9. public record DimView : Dim
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="DimView"/> class.
  13. /// </summary>
  14. /// <param name="view">The view the dimension is anchored to.</param>
  15. /// <param name="dimension">Indicates which dimension is tracked.</param>
  16. public DimView (View? view, Dimension dimension)
  17. {
  18. Target = view;
  19. Dimension = dimension;
  20. }
  21. /// <summary>
  22. /// Gets the indicated dimension of the View.
  23. /// </summary>
  24. public Dimension Dimension { get; }
  25. /// <summary>
  26. /// Gets the View the dimension is anchored to.
  27. /// </summary>
  28. public View? Target { get; init; }
  29. /// <inheritdoc/>
  30. public override string ToString ()
  31. {
  32. if (Target == null)
  33. {
  34. throw new NullReferenceException ();
  35. }
  36. return $"View({Dimension},{Target})";
  37. }
  38. internal override int GetAnchor (int size)
  39. {
  40. return Dimension switch
  41. {
  42. Dimension.Height => Target!.Frame.Height,
  43. Dimension.Width => Target!.Frame.Width,
  44. _ => 0
  45. };
  46. }
  47. internal override bool ReferencesOtherViews () { return true; }
  48. }