Application .Screen.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. public static partial class Application // Screen related stuff
  4. {
  5. /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
  6. /// <remarks>
  7. /// Event handlers can set <see cref="SizeChangedEventArgs.Cancel"/> to <see langword="true"/> to prevent
  8. /// <see cref="Application"/> from changing it's size to match the new terminal size.
  9. /// </remarks>
  10. public static event EventHandler<SizeChangedEventArgs>? SizeChanging;
  11. /// <summary>
  12. /// Called when the application's size changes. Sets the size of all <see cref="Toplevel"/>s and fires the
  13. /// <see cref="SizeChanging"/> event.
  14. /// </summary>
  15. /// <param name="args">The new size.</param>
  16. /// <returns><see lanword="true"/>if the size was changed.</returns>
  17. public static bool OnSizeChanging (SizeChangedEventArgs args)
  18. {
  19. SizeChanging?.Invoke (null, args);
  20. if (args.Cancel || args.Size is null)
  21. {
  22. return false;
  23. }
  24. foreach (Toplevel t in TopLevels)
  25. {
  26. t.SetRelativeLayout (args.Size.Value);
  27. t.LayoutSubviews ();
  28. t.PositionToplevels ();
  29. t.OnSizeChanging (new (args.Size));
  30. if (PositionCursor (t))
  31. {
  32. Driver?.UpdateCursor ();
  33. }
  34. }
  35. Refresh ();
  36. return true;
  37. }
  38. }