public void AddChildAtIndex(FNode node, int newIndex)
{
int nodeIndex = _childNodes.IndexOf(node);
if(newIndex > _childNodes.Count) //if it's past the end, make it at the end
{
newIndex = _childNodes.Count;
}
if(nodeIndex == newIndex) return; //if it's already at the right index, just leave it there
if(nodeIndex == -1) //add it if it's not a child
{
node.HandleAddedToContainer(this);
_childNodes.Insert(newIndex, node);
if(_isOnStage)
{
node.stage = _stage;
node.HandleAddedToStage();
}
}
else //if node is already a child, move it to the desired index
{
_childNodes.RemoveAt(nodeIndex);
if(nodeIndex < newIndex)
{
_childNodes.Insert(newIndex-1, node); //gotta subtract 1 to account for it moving in the order
}
else
{
_childNodes.Insert(newIndex, node);
}
if(_isOnStage) _stage.HandleFacetsChanged();
}
}