PosView.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Represents a position that is anchored to the side of another view.
  5. /// </summary>
  6. /// <remarks>
  7. /// <para>
  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="Pos"/> class to create <see cref="Pos"/> objects instead.
  10. /// </para>
  11. /// </remarks>
  12. /// <param name="View">The View the position is anchored to.</param>
  13. /// <param name="Side">The side of the View the position is anchored to.</param>
  14. public record PosView (View? View, Side Side) : Pos
  15. {
  16. /// <summary>
  17. /// Gets the View the position is anchored to.
  18. /// </summary>
  19. public View? Target { get; } = View;
  20. /// <summary>
  21. /// Gets the side of the View the position is anchored to.
  22. /// </summary>
  23. public Side Side { get; } = Side;
  24. /// <inheritdoc/>
  25. public override string ToString ()
  26. {
  27. string sideString = Side.ToString ();
  28. if (Target == null)
  29. {
  30. throw new NullReferenceException (nameof (Target));
  31. }
  32. return $"View(Side={sideString},Target={Target})";
  33. }
  34. internal override int GetAnchor (int size)
  35. {
  36. return Side switch
  37. {
  38. Side.Left => Target!.Frame.X,
  39. Side.Top => Target!.Frame.Y,
  40. Side.Right => Target!.Frame.Right,
  41. Side.Bottom => Target!.Frame.Bottom,
  42. _ => 0
  43. };
  44. }
  45. internal override bool ReferencesOtherViews () { return true; }
  46. }