PosCombine.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. namespace Terminal.Gui.ViewBase;
  2. /// <summary>
  3. /// Represents a position that is a combination of two other positions.
  4. /// </summary>
  5. /// <remarks>
  6. /// <para>
  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="Pos"/> class to create <see cref="Pos"/> objects instead.
  9. /// </para>
  10. /// </remarks>
  11. /// <param name="Add">
  12. /// Indicates whether the two positions are added or subtracted.
  13. /// </param>
  14. /// <param name="Left">The left position.</param>
  15. /// <param name="Right">The right position.</param>
  16. public record PosCombine (AddOrSubtract Add, Pos Left, Pos Right) : Pos
  17. {
  18. /// <summary>
  19. /// Gets whether the two positions are added or subtracted.
  20. /// </summary>
  21. public AddOrSubtract Add { get; } = Add;
  22. /// <summary>
  23. /// Gets the left position.
  24. /// </summary>
  25. public new Pos Left { get; } = Left;
  26. /// <summary>
  27. /// Gets the right position.
  28. /// </summary>
  29. public new Pos Right { get; } = Right;
  30. /// <inheritdoc/>
  31. public override string ToString () { return $"Combine({Left}{(Add == AddOrSubtract.Add ? '+' : '-')}{Right})"; }
  32. internal override int GetAnchor (int size)
  33. {
  34. if (Add == AddOrSubtract.Add)
  35. {
  36. return Left.GetAnchor (size) + Right.GetAnchor (size);
  37. }
  38. return Left.GetAnchor (size) - Right.GetAnchor (size);
  39. }
  40. internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension)
  41. {
  42. if (Add == AddOrSubtract.Add)
  43. {
  44. return Left.Calculate (superviewDimension, dim, us, dimension) + Right.Calculate (superviewDimension, dim, us, dimension);
  45. }
  46. return Left.Calculate (superviewDimension, dim, us, dimension) - Right.Calculate (superviewDimension, dim, us, dimension);
  47. }
  48. internal override bool ReferencesOtherViews ()
  49. {
  50. if (Left.ReferencesOtherViews ())
  51. {
  52. return true;
  53. }
  54. if (Right.ReferencesOtherViews ())
  55. {
  56. return true;
  57. }
  58. return false;
  59. }
  60. }