Application.Screen.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #nullable enable
  2. namespace Terminal.Gui.App;
  3. public static partial class Application // Screen related stuff; intended to hide Driver details
  4. {
  5. /// <summary>
  6. /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the <see cref="IConsoleDriver"/>.
  7. /// </summary>
  8. /// <remarks>
  9. /// <para>
  10. /// If the <see cref="IConsoleDriver"/> has not been initialized, this will return a default size of 2048x2048; useful for unit tests.
  11. /// </para>
  12. /// </remarks>
  13. public static Rectangle Screen
  14. {
  15. get => ApplicationImpl.Instance.Screen;
  16. set => ApplicationImpl.Instance.Screen = value;
  17. }
  18. /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
  19. /// <remarks>
  20. /// Event handlers can set <see cref="SizeChangedEventArgs.Cancel"/> to <see langword="true"/> to prevent
  21. /// <see cref="Application"/> from changing it's size to match the new terminal size.
  22. /// </remarks>
  23. public static event EventHandler<SizeChangedEventArgs>? SizeChanging
  24. {
  25. add
  26. {
  27. if (ApplicationImpl.Instance is ApplicationImpl impl)
  28. {
  29. impl.SizeChanging += value;
  30. }
  31. }
  32. remove
  33. {
  34. if (ApplicationImpl.Instance is ApplicationImpl impl)
  35. {
  36. impl.SizeChanging -= value;
  37. }
  38. }
  39. }
  40. // Internal helper method for ApplicationImpl.ResetState to clear this event
  41. internal static void ClearSizeChangingEvent ()
  42. {
  43. if (ApplicationImpl.Instance is ApplicationImpl impl)
  44. {
  45. impl.SizeChanging = null;
  46. }
  47. }
  48. /// <summary>
  49. /// Called when the application's size changes. Sets the size of all <see cref="Toplevel"/>s and fires the
  50. /// <see cref="SizeChanging"/> event.
  51. /// </summary>
  52. /// <param name="args">The new size.</param>
  53. /// <returns><see lanword="true"/>if the size was changed.</returns>
  54. public static bool OnSizeChanging (SizeChangedEventArgs args)
  55. {
  56. return ApplicationImpl.Instance.OnSizeChanging (args);
  57. }
  58. /// <summary>
  59. /// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
  60. /// </summary>
  61. /// <remarks>
  62. /// This is typical set to true when a View's <see cref="View.Frame"/> changes and that view has no
  63. /// SuperView (e.g. when <see cref="Application.Top"/> is moved or resized.
  64. /// </remarks>
  65. internal static bool ClearScreenNextIteration
  66. {
  67. get => ApplicationImpl.Instance.ClearScreenNextIteration;
  68. set => ApplicationImpl.Instance.ClearScreenNextIteration = value;
  69. }
  70. }