Application.Screen.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. public static event EventHandler<EventArgs<Rectangle>>? ScreenChanged;
  20. /// <summary>
  21. /// Called when the application's size has changed. Sets the size of all <see cref="Toplevel"/>s and fires the
  22. /// <see cref="ScreenChanged"/> event.
  23. /// </summary>
  24. /// <param name="screen">The new screen size and position.</param>
  25. public static void RaiseScreenChangedEvent (Rectangle screen)
  26. {
  27. Screen = new (Point.Empty, screen.Size);
  28. ScreenChanged?.Invoke (ApplicationImpl.Instance, new (screen));
  29. foreach (Toplevel t in TopLevels)
  30. {
  31. t.OnSizeChanging (new (screen.Size));
  32. t.SetNeedsLayout ();
  33. }
  34. LayoutAndDraw (true);
  35. }
  36. /// <summary>
  37. /// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
  38. /// </summary>
  39. /// <remarks>
  40. /// This is typical set to true when a View's <see cref="View.Frame"/> changes and that view has no
  41. /// SuperView (e.g. when <see cref="Application.Top"/> is moved or resized.
  42. /// </remarks>
  43. internal static bool ClearScreenNextIteration
  44. {
  45. get => ApplicationImpl.Instance.ClearScreenNextIteration;
  46. set => ApplicationImpl.Instance.ClearScreenNextIteration = value;
  47. }
  48. }