PosCenter.cs 616 B

123456789101112131415161718192021
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Represents a position that is centered.
  5. /// </summary>
  6. public class PosCenter : Pos
  7. {
  8. /// <inheritdoc/>
  9. public override string ToString () { return "Center"; }
  10. internal override int GetAnchor (int size) { return size / 2; }
  11. internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension)
  12. {
  13. // Protect against negative dimensions
  14. int newDimension = Math.Max (dim.Calculate (0, superviewDimension, us, dimension), 0);
  15. return superviewDimension / 2 - newDimension / 2;
  16. }
  17. }