Added IsLoaded property to allow control if a change was done before or after the toplevel was loaded.

This commit is contained in:
BDisp
2023-03-02 03:24:21 +00:00
parent a7c13b5d48
commit 5840ad25e8
4 changed files with 95 additions and 0 deletions

View File

@@ -1031,5 +1031,53 @@ namespace Terminal.Gui.TopLevelTests {
Application.Driver.GetCursorVisibility (out cursor);
Assert.Equal (CursorVisibility.Invisible, cursor);
}
[Fact, AutoInitShutdown]
public void IsLoaded_Application_Begin ()
{
var top = Application.Top;
Assert.False (top.IsLoaded);
Application.Begin (top);
Assert.True (top.IsLoaded);
}
[Fact, AutoInitShutdown]
public void IsLoaded_With_Sub_Toplevel_Application_Begin_NeedDisplay ()
{
var top = Application.Top;
var subTop = new Toplevel ();
var view = new View (new Rect (0, 0, 20, 10));
subTop.Add (view);
top.Add (subTop);
Assert.False (top.IsLoaded);
Assert.False (subTop.IsLoaded);
Assert.Equal (new Rect (0, 0, 20, 10), view.Frame);
Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay);
view.LayoutStarted += view_LayoutStarted;
void view_LayoutStarted (View.LayoutEventArgs e)
{
Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay);
view.LayoutStarted -= view_LayoutStarted;
}
Application.Begin (top);
Assert.True (top.IsLoaded);
Assert.True (subTop.IsLoaded);
Assert.Equal (new Rect (0, 0, 20, 10), view.Frame);
view.Frame = new Rect (1, 3, 10, 5);
Assert.Equal (new Rect (1, 3, 10, 5), view.Frame);
Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay);
view.Redraw (view.Bounds);
view.Frame = new Rect (1, 3, 10, 5);
Assert.Equal (new Rect (1, 3, 10, 5), view.Frame);
Assert.Equal (new Rect (1, 3, 10, 5), view.NeedDisplay);
}
}
}