#nullable enable namespace Terminal.Gui; public static partial class Application // Screen related stuff { private static Size _screenSize = new (2048, 2048); /// /// INTERNAL API for Unit Tests. Only works if there's no driver. /// /// internal static void SetScreenSize (Size size) { if (Driver is { }) { throw new InvalidOperationException ("Cannot set the screen size when the ConsoleDriver is already initialized."); } _screenSize = size; } /// /// Gets the size of the screen. 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 => Driver?.Screen ?? new (new (0, 0), _screenSize); /// 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; } foreach (Toplevel t in TopLevels) { t.OnSizeChanging (new (args.Size)); t.SetLayoutNeeded (); } Refresh (); return true; } }