#nullable enable namespace Terminal.Gui; public static partial class Application // Screen related stuff { private static Rectangle? _screen; /// /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the . /// /// /// /// If the has not been initialized, this will return a default size of 2048x2048; useful for unit tests. /// /// public static Rectangle Screen { get { if (_screen == null) { _screen = Driver?.Screen ?? new (new (0, 0), new (2048, 2048)); } return _screen.Value; } set { if (value is {} && (value.X != 0 || value.Y != 0)) { throw new NotImplementedException ($"Screen locations other than 0, 0 are not yet supported"); } _screen = value; } } /// Invoked when the terminal's size changed. The new size of the terminal is provided. /// /// Event handlers can set to to prevent /// from changing it's size to match the new terminal size. /// public static event EventHandler? SizeChanging; /// /// Called when the application's size changes. Sets the size of all s and fires the /// event. /// /// The new size. /// if the size was changed. public static bool OnSizeChanging (SizeChangedEventArgs args) { SizeChanging?.Invoke (null, args); if (args.Cancel || args.Size is null) { return false; } Screen = new (Point.Empty, args.Size.Value); foreach (Toplevel t in TopLevels) { t.OnSizeChanging (new (args.Size)); t.SetNeedsLayout (); } LayoutAndDrawToplevels (); return true; } }