Skip to content

Commit

Permalink
Revert "Handle reparenting controls in SceneBuilder."
Browse files Browse the repository at this point in the history
This reverts commit db8751d.

The change was incorrect, it causes #3019.
  • Loading branch information
grokys committed Sep 23, 2019
1 parent a600244 commit 25e0ed5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ private void UpdateScene()
foreach (var visual in _recalculateChildren)
{
var node = scene.FindNode(visual);
((VisualNode)node)?.UpdateChildren(scene);
((VisualNode)node)?.SortChildren(scene);
}

_recalculateChildren.Clear();
Expand Down
15 changes: 3 additions & 12 deletions src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ public void ReplaceDrawOperation(int index, IRef<IDrawOperation> operation)

/// <summary>
/// Sorts the <see cref="Children"/> collection according to the order of the visual's
/// children and their z-index and removes controls that are no longer children.
/// children and their z-index.
/// </summary>
/// <param name="scene">The scene that the node is a part of.</param>
public void UpdateChildren(Scene scene)
public void SortChildren(Scene scene)
{
if (_children == null || _children.Count == 0)
if (_children == null || _children.Count <= 1)
{
return;
}
Expand All @@ -193,12 +193,9 @@ public void UpdateChildren(Scene scene)
keys.Add(((long)zIndex << 32) + i);
}

var toRemove = _children.ToList();

keys.Sort();
_children.Clear();


foreach (var i in keys)
{
var child = Visual.VisualChildren[(int)(i & 0xffffffff)];
Expand All @@ -207,14 +204,8 @@ public void UpdateChildren(Scene scene)
if (node != null)
{
_children.Add(node);
toRemove.Remove(node);
}
}

foreach (var node in toRemove)
{
scene.Remove(node);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ public void Should_Update_When_Control_Moved()
moveFromNode = (VisualNode)scene.FindNode(moveFrom);
moveToNode = (VisualNode)scene.FindNode(moveTo);

moveFromNode.UpdateChildren(scene);
moveToNode.UpdateChildren(scene);
moveFromNode.SortChildren(scene);
moveToNode.SortChildren(scene);
sceneBuilder.Update(scene, moveFrom);
sceneBuilder.Update(scene, moveTo);
sceneBuilder.Update(scene, moveMe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void SortChildren_Does_Not_Throw_On_Null_Children()
var node = new VisualNode(Mock.Of<IVisual>(), null);
var scene = new Scene(Mock.Of<IVisual>());

node.UpdateChildren(scene);
node.SortChildren(scene);
}
}
}

0 comments on commit 25e0ed5

Please sign in to comment.