Browse Source
Merge pull request #3118 from AvaloniaUI/fixes/3115-visualnode-disposed
Add VisualNode to scene even for invisible controls
pull/3121/head
Steven Kirk
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
77 additions and
1 deletions
-
src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
-
src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs
-
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs
-
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/VisualNodeTests.cs
|
|
|
@ -240,6 +240,10 @@ namespace Avalonia.Rendering.SceneGraph |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
contextImpl.BeginUpdate(node).Dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void UpdateSize(Scene scene) |
|
|
|
|
|
|
|
@ -218,7 +218,7 @@ namespace Avalonia.Rendering.SceneGraph |
|
|
|
if (first < _children?.Count) |
|
|
|
{ |
|
|
|
EnsureChildrenCreated(); |
|
|
|
for (int i = first; i < _children.Count - first; i++) |
|
|
|
for (int i = first; i < _children.Count; i++) |
|
|
|
{ |
|
|
|
_children[i].Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -577,6 +577,59 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Not_Dispose_Active_VisualNode_When_Control_Reparented_And_Child_Made_Invisible() |
|
|
|
{ |
|
|
|
// Issue #3115
|
|
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) |
|
|
|
{ |
|
|
|
StackPanel panel; |
|
|
|
Border border1; |
|
|
|
Border border2; |
|
|
|
var tree = new TestRoot |
|
|
|
{ |
|
|
|
Width = 100, |
|
|
|
Height = 100, |
|
|
|
Child = panel = new StackPanel |
|
|
|
{ |
|
|
|
Children = |
|
|
|
{ |
|
|
|
(border1 = new Border |
|
|
|
{ |
|
|
|
Background = Brushes.Red, |
|
|
|
}), |
|
|
|
(border2 = new Border |
|
|
|
{ |
|
|
|
Background = Brushes.Green, |
|
|
|
}), |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
tree.Measure(Size.Infinity); |
|
|
|
tree.Arrange(new Rect(tree.DesiredSize)); |
|
|
|
|
|
|
|
var scene = new Scene(tree); |
|
|
|
var sceneBuilder = new SceneBuilder(); |
|
|
|
sceneBuilder.UpdateAll(scene); |
|
|
|
|
|
|
|
var decorator = new Decorator(); |
|
|
|
tree.Child = null; |
|
|
|
decorator.Child = panel; |
|
|
|
tree.Child = decorator; |
|
|
|
border1.IsVisible = false; |
|
|
|
|
|
|
|
scene = scene.CloneScene(); |
|
|
|
|
|
|
|
var panelNode = (VisualNode)scene.FindNode(panel); |
|
|
|
sceneBuilder.Update(scene, decorator); |
|
|
|
|
|
|
|
Assert.Equal(2, panelNode.Children.Count); |
|
|
|
Assert.False(panelNode.Children[0].Disposed); |
|
|
|
Assert.False(panelNode.Children[1].Disposed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Update_ClipBounds_For_Negative_Margin() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -101,5 +101,24 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph |
|
|
|
|
|
|
|
node.SortChildren(scene); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TrimChildren_Should_Work_Correctly() |
|
|
|
{ |
|
|
|
var parent = new VisualNode(Mock.Of<IVisual>(), null); |
|
|
|
var child1 = new VisualNode(Mock.Of<IVisual>(), null); |
|
|
|
var child2 = new VisualNode(Mock.Of<IVisual>(), null); |
|
|
|
var child3 = new VisualNode(Mock.Of<IVisual>(), null); |
|
|
|
|
|
|
|
parent.AddChild(child1); |
|
|
|
parent.AddChild(child2); |
|
|
|
parent.AddChild(child3); |
|
|
|
parent.TrimChildren(2); |
|
|
|
|
|
|
|
Assert.Equal(2, parent.Children.Count); |
|
|
|
Assert.False(child1.Disposed); |
|
|
|
Assert.False(child2.Disposed); |
|
|
|
Assert.True(child3.Disposed); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|