|
@@ -311,80 +311,7 @@ public class NeedsDrawTests : FakeDriverBase
|
|
|
Assert.Equal (new (1, 1, 5, 5), view.Viewport);
|
|
Assert.Equal (new (1, 1, 5, 5), view.Viewport);
|
|
|
Assert.Equal (new (1, 1, 5, 5), view.NeedsDrawRect);
|
|
Assert.Equal (new (1, 1, 5, 5), view.NeedsDrawRect);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- [Fact (Skip = "Not valid")]
|
|
|
|
|
- public void ClearNeedsDraw_WithSiblings_DoesNotClearSuperViewSubViewNeedsDraw ()
|
|
|
|
|
- {
|
|
|
|
|
- // This test verifies the fix for the bug where a subview clearing its NeedsDraw
|
|
|
|
|
- // would incorrectly clear the superview's SubViewNeedsDraw flag, even if other siblings
|
|
|
|
|
- // still needed drawing.
|
|
|
|
|
-
|
|
|
|
|
- IDriver driver = CreateFakeDriver (80, 25);
|
|
|
|
|
- driver.Clip = new Region (driver.Screen);
|
|
|
|
|
-
|
|
|
|
|
- var superView = new View
|
|
|
|
|
- {
|
|
|
|
|
- X = 0,
|
|
|
|
|
- Y = 0,
|
|
|
|
|
- Width = 50,
|
|
|
|
|
- Height = 50,
|
|
|
|
|
- Driver = driver
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- var subView1 = new View { X = 0, Y = 0, Width = 10, Height = 10, Id = "SubView1" };
|
|
|
|
|
- var subView2 = new View { X = 0, Y = 10, Width = 10, Height = 10, Id = "SubView2" };
|
|
|
|
|
- var subView3 = new View { X = 0, Y = 20, Width = 10, Height = 10, Id = "SubView3" };
|
|
|
|
|
-
|
|
|
|
|
- superView.Add (subView1, subView2, subView3);
|
|
|
|
|
- superView.BeginInit ();
|
|
|
|
|
- superView.EndInit ();
|
|
|
|
|
- superView.LayoutSubViews ();
|
|
|
|
|
-
|
|
|
|
|
- // All subviews should need drawing initially
|
|
|
|
|
- Assert.True (subView1.NeedsDraw);
|
|
|
|
|
- Assert.True (subView2.NeedsDraw);
|
|
|
|
|
- Assert.True (subView3.NeedsDraw);
|
|
|
|
|
- Assert.True (superView.SubViewNeedsDraw);
|
|
|
|
|
-
|
|
|
|
|
- // Draw subView1 - this will call ClearNeedsDraw() on subView1
|
|
|
|
|
- subView1.Draw ();
|
|
|
|
|
-
|
|
|
|
|
- // SubView1 should no longer need drawing
|
|
|
|
|
- Assert.False (subView1.NeedsDraw);
|
|
|
|
|
-
|
|
|
|
|
- // But subView2 and subView3 still need drawing
|
|
|
|
|
- Assert.True (subView2.NeedsDraw);
|
|
|
|
|
- Assert.True (subView3.NeedsDraw);
|
|
|
|
|
-
|
|
|
|
|
- // THE BUG: Before the fix, subView1.ClearNeedsDraw() would set superView.SubViewNeedsDraw = false
|
|
|
|
|
- // even though subView2 and subView3 still need drawing.
|
|
|
|
|
- // After the fix, superView.SubViewNeedsDraw should still be true because subView2 and subView3 need drawing.
|
|
|
|
|
- Assert.True (superView.SubViewNeedsDraw, "SuperView's SubViewNeedsDraw should still be true because subView2 and subView3 still need drawing");
|
|
|
|
|
-
|
|
|
|
|
- // Now draw subView2
|
|
|
|
|
- subView2.Draw ();
|
|
|
|
|
- Assert.False (subView2.NeedsDraw);
|
|
|
|
|
- Assert.True (subView3.NeedsDraw);
|
|
|
|
|
-
|
|
|
|
|
- // SuperView should still have SubViewNeedsDraw = true because subView3 needs drawing
|
|
|
|
|
- Assert.True (superView.SubViewNeedsDraw, "SuperView's SubViewNeedsDraw should still be true because subView3 still needs drawing");
|
|
|
|
|
-
|
|
|
|
|
- // Now draw subView3
|
|
|
|
|
- subView3.Draw ();
|
|
|
|
|
- Assert.False (subView3.NeedsDraw);
|
|
|
|
|
-
|
|
|
|
|
- // SuperView should STILL have SubViewNeedsDraw = true because it hasn't been cleared by the superview itself
|
|
|
|
|
- // Only the superview's own ClearNeedsDraw() should clear this flag
|
|
|
|
|
- Assert.True (superView.SubViewNeedsDraw, "SuperView's SubViewNeedsDraw should only be cleared by superView.ClearNeedsDraw(), not by subviews");
|
|
|
|
|
-
|
|
|
|
|
- // Finally, draw the superview - this will clear SubViewNeedsDraw
|
|
|
|
|
- superView.Draw ();
|
|
|
|
|
- Assert.False (superView.SubViewNeedsDraw, "SuperView's SubViewNeedsDraw should now be false after superView.Draw()");
|
|
|
|
|
- Assert.False (subView1.NeedsDraw);
|
|
|
|
|
- Assert.False (subView2.NeedsDraw);
|
|
|
|
|
- Assert.False (subView3.NeedsDraw);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
[Fact]
|
|
[Fact]
|
|
|
public void ClearNeedsDraw_ClearsOwnFlags ()
|
|
public void ClearNeedsDraw_ClearsOwnFlags ()
|
|
|
{
|
|
{
|
|
@@ -481,4 +408,281 @@ public class NeedsDrawTests : FakeDriverBase
|
|
|
Assert.False (middleView.SubViewNeedsDraw);
|
|
Assert.False (middleView.SubViewNeedsDraw);
|
|
|
Assert.False (bottomView.NeedsDraw);
|
|
Assert.False (bottomView.NeedsDraw);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ #region NeedsDraw Tests
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void NeedsDraw_InitiallyFalse_WhenNotVisible ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = new View { Visible = false };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.False (view.NeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void NeedsDraw_TrueAfterSetNeedsDraw ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = new View { X = 0, Y = 0, Width = 10, Height = 10 };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+ view.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ view.SetNeedsDraw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.True (view.NeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void NeedsDraw_ClearedAfterDraw ()
|
|
|
|
|
+ {
|
|
|
|
|
+ IDriver driver = CreateFakeDriver (80, 25);
|
|
|
|
|
+ driver.Clip = new Region (driver.Screen);
|
|
|
|
|
+
|
|
|
|
|
+ var view = new View
|
|
|
|
|
+ {
|
|
|
|
|
+ X = 0,
|
|
|
|
|
+ Y = 0,
|
|
|
|
|
+ Width = 10,
|
|
|
|
|
+ Height = 10,
|
|
|
|
|
+ Driver = driver
|
|
|
|
|
+ };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+ view.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ view.SetNeedsDraw ();
|
|
|
|
|
+ Assert.True (view.NeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ view.Draw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.False (view.NeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SetNeedsDraw_WithRectangle_UpdatesNeedsDrawRect ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = new View { Driver = CreateFakeDriver (), X = 0, Y = 0, Width = 20, Height = 20 };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+ view.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ // After layout, view will have NeedsDrawRect set to the viewport
|
|
|
|
|
+ // We need to clear it first
|
|
|
|
|
+ view.Draw ();
|
|
|
|
|
+ Assert.False (view.NeedsDraw);
|
|
|
|
|
+ Assert.Equal (Rectangle.Empty, view.NeedsDrawRect);
|
|
|
|
|
+
|
|
|
|
|
+ var rect = new Rectangle (5, 5, 10, 10);
|
|
|
|
|
+ view.SetNeedsDraw (rect);
|
|
|
|
|
+
|
|
|
|
|
+ Assert.True (view.NeedsDraw);
|
|
|
|
|
+ Assert.Equal (rect, view.NeedsDrawRect);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SetNeedsDraw_MultipleRectangles_Expands ()
|
|
|
|
|
+ {
|
|
|
|
|
+ IDriver driver = CreateFakeDriver (80, 25);
|
|
|
|
|
+ driver.Clip = new Region (driver.Screen);
|
|
|
|
|
+
|
|
|
|
|
+ var view = new View { X = 0, Y = 0, Width = 30, Height = 30, Driver = driver };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+ view.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ // After layout, clear NeedsDraw
|
|
|
|
|
+ view.Draw ();
|
|
|
|
|
+ Assert.False (view.NeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ view.SetNeedsDraw (new Rectangle (5, 5, 10, 10));
|
|
|
|
|
+ view.SetNeedsDraw (new Rectangle (15, 15, 10, 10));
|
|
|
|
|
+
|
|
|
|
|
+ // Should expand to cover the entire viewport when we have overlapping regions
|
|
|
|
|
+ // The current implementation expands to viewport size
|
|
|
|
|
+ Rectangle expected = new Rectangle (0, 0, 30, 30);
|
|
|
|
|
+ Assert.Equal (expected, view.NeedsDrawRect);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SetNeedsDraw_NotVisible_DoesNotSet ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = new View
|
|
|
|
|
+ {
|
|
|
|
|
+ X = 0,
|
|
|
|
|
+ Y = 0,
|
|
|
|
|
+ Width = 10,
|
|
|
|
|
+ Height = 10,
|
|
|
|
|
+ Visible = false
|
|
|
|
|
+ };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+
|
|
|
|
|
+ view.SetNeedsDraw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.False (view.NeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SetNeedsDraw_PropagatesToSuperView ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var parent = new View { X = 0, Y = 0, Width = 50, Height = 50 };
|
|
|
|
|
+ var child = new View { X = 10, Y = 10, Width = 20, Height = 20 };
|
|
|
|
|
+ parent.Add (child);
|
|
|
|
|
+ parent.BeginInit ();
|
|
|
|
|
+ parent.EndInit ();
|
|
|
|
|
+ parent.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ child.SetNeedsDraw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.True (child.NeedsDraw);
|
|
|
|
|
+ Assert.True (parent.SubViewNeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SetNeedsDraw_SetsAdornmentsNeedsDraw ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = new View { X = 0, Y = 0, Width = 20, Height = 20 };
|
|
|
|
|
+ view.Border!.Thickness = new Thickness (1);
|
|
|
|
|
+ view.Padding!.Thickness = new Thickness (1);
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+ view.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ view.SetNeedsDraw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.True (view.Border!.NeedsDraw);
|
|
|
|
|
+ Assert.True (view.Padding!.NeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [Fact (Skip = "This is a real bug discovered in PR #4431 that needs to be fixed")]
|
|
|
|
|
+ public void IndividualViewDraw_DoesNotClearSuperViewSubViewNeedsDraw ()
|
|
|
|
|
+ {
|
|
|
|
|
+ // This test validates that individual view Draw() calls should NOT clear the superview's
|
|
|
|
|
+ // SubViewNeedsDraw flag when sibling subviews still need drawing.
|
|
|
|
|
+ //
|
|
|
|
|
+ // This is the core behavior that enables the fix in the static Draw method.
|
|
|
|
|
+ IDriver driver = CreateFakeDriver ();
|
|
|
|
|
+ driver.Clip = new (driver.Screen);
|
|
|
|
|
+
|
|
|
|
|
+ View superview = new ()
|
|
|
|
|
+ {
|
|
|
|
|
+ X = 0,
|
|
|
|
|
+ Y = 0,
|
|
|
|
|
+ Width = 50,
|
|
|
|
|
+ Height = 50,
|
|
|
|
|
+ Driver = driver,
|
|
|
|
|
+ Id = "SuperView"
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ View subview1 = new () { X = 0, Y = 0, Width = 10, Height = 10, Id = "SubView1" };
|
|
|
|
|
+ View subview2 = new () { X = 0, Y = 10, Width = 10, Height = 10, Id = "SubView2" };
|
|
|
|
|
+
|
|
|
|
|
+ superview.Add (subview1, subview2);
|
|
|
|
|
+ superview.BeginInit ();
|
|
|
|
|
+ superview.EndInit ();
|
|
|
|
|
+ superview.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.True (superview.SubViewNeedsDraw);
|
|
|
|
|
+ Assert.True (subview1.NeedsDraw);
|
|
|
|
|
+ Assert.True (subview2.NeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ // Draw only subview1 (NOT using the static Draw method)
|
|
|
|
|
+ subview1.Draw ();
|
|
|
|
|
+
|
|
|
|
|
+ // SubView1 should be cleared
|
|
|
|
|
+ Assert.False (subview1.NeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ // SubView2 still needs drawing
|
|
|
|
|
+ Assert.True (subview2.NeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ // THE KEY ASSERTION: SuperView's SubViewNeedsDraw should STILL be true
|
|
|
|
|
+ // because subview2 still needs drawing
|
|
|
|
|
+ //
|
|
|
|
|
+ // This behavior is REQUIRED for the static Draw fix to work properly.
|
|
|
|
|
+ // ClearNeedsDraw() does NOT clear SuperView.SubViewNeedsDraw anymore.
|
|
|
|
|
+ Assert.True (superview.SubViewNeedsDraw,
|
|
|
|
|
+ "SuperView's SubViewNeedsDraw must remain true when subview2 still needs drawing");
|
|
|
|
|
+
|
|
|
|
|
+ // Now draw subview2
|
|
|
|
|
+ subview2.Draw ();
|
|
|
|
|
+ Assert.False (subview2.NeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ // SuperView's SubViewNeedsDraw should STILL be true because only the superview
|
|
|
|
|
+ // itself (or the static Draw method on all subviews) should clear it
|
|
|
|
|
+ Assert.True (superview.SubViewNeedsDraw,
|
|
|
|
|
+ "SuperView's SubViewNeedsDraw should only be cleared by superview.Draw() or static Draw() on all subviews");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region SubViewNeedsDraw Tests
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SubViewNeedsDraw_InitiallyFalse ()
|
|
|
|
|
+ {
|
|
|
|
|
+ IDriver driver = CreateFakeDriver (80, 25);
|
|
|
|
|
+ driver.Clip = new Region (driver.Screen);
|
|
|
|
|
+
|
|
|
|
|
+ var view = new View { Width = 10, Height = 10, Driver = driver };
|
|
|
|
|
+ view.BeginInit ();
|
|
|
|
|
+ view.EndInit ();
|
|
|
|
|
+ view.Draw (); // Draw once to clear initial NeedsDraw
|
|
|
|
|
+
|
|
|
|
|
+ Assert.False (view.SubViewNeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SetSubViewNeedsDraw_PropagatesUp ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var grandparent = new View { X = 0, Y = 0, Width = 100, Height = 100 };
|
|
|
|
|
+ var parent = new View { X = 10, Y = 10, Width = 50, Height = 50 };
|
|
|
|
|
+ var child = new View { X = 5, Y = 5, Width = 20, Height = 20 };
|
|
|
|
|
+
|
|
|
|
|
+ grandparent.Add (parent);
|
|
|
|
|
+ parent.Add (child);
|
|
|
|
|
+ grandparent.BeginInit ();
|
|
|
|
|
+ grandparent.EndInit ();
|
|
|
|
|
+ grandparent.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ child.SetSubViewNeedsDraw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.True (child.SubViewNeedsDraw);
|
|
|
|
|
+ Assert.True (parent.SubViewNeedsDraw);
|
|
|
|
|
+ Assert.True (grandparent.SubViewNeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Fact]
|
|
|
|
|
+ public void SubViewNeedsDraw_ClearedAfterDraw ()
|
|
|
|
|
+ {
|
|
|
|
|
+ IDriver driver = CreateFakeDriver (80, 25);
|
|
|
|
|
+ driver.Clip = new Region (driver.Screen);
|
|
|
|
|
+
|
|
|
|
|
+ var parent = new View
|
|
|
|
|
+ {
|
|
|
|
|
+ X = 0,
|
|
|
|
|
+ Y = 0,
|
|
|
|
|
+ Width = 50,
|
|
|
|
|
+ Height = 50,
|
|
|
|
|
+ Driver = driver
|
|
|
|
|
+ };
|
|
|
|
|
+ var child = new View { X = 10, Y = 10, Width = 20, Height = 20 };
|
|
|
|
|
+ parent.Add (child);
|
|
|
|
|
+ parent.BeginInit ();
|
|
|
|
|
+ parent.EndInit ();
|
|
|
|
|
+ parent.LayoutSubViews ();
|
|
|
|
|
+
|
|
|
|
|
+ child.SetNeedsDraw ();
|
|
|
|
|
+ Assert.True (parent.SubViewNeedsDraw);
|
|
|
|
|
+
|
|
|
|
|
+ parent.Draw ();
|
|
|
|
|
+
|
|
|
|
|
+ Assert.False (parent.SubViewNeedsDraw);
|
|
|
|
|
+ Assert.False (child.SubViewNeedsDraw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
}
|
|
}
|