PosCombine.cs 2.1 KB

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