#nullable enable
namespace Terminal.Gui;
public static partial class Application // Screen related stuff
{
///
/// 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 (0, 0, 2048, 2048);
/// 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.SetRelativeLayout (args.Size.Value);
t.LayoutSubviews ();
t.PositionToplevels ();
t.OnSizeChanging (new (args.Size));
if (PositionCursor (t))
{
Driver?.UpdateCursor ();
}
}
Refresh ();
return true;
}
}