/// clean up this view & propagate down
public void Cleanup()
{
// if I'm a one-view splitview, I can propagate my child up and kill myself
SplitView sp = parent as SplitView;
if (children.Length == 1 && sp != null)
{
View c = children[0];
c.position = position;
if (parent != null)
{
parent.AddChild(c, parent.IndexOfChild(this));
parent.RemoveChild(this);
if (sp)
{
sp.Cleanup();
}
c.position = position;
if (!Unsupported.IsDestroyScriptableObject(this))
{
DestroyImmediate(this);
}
return;
}
else if (c is SplitView)
{
RemoveChild(c);
window.rootView = c;
c.position = new Rect(0, 0, c.window.position.width, window.position.height);
c.Reflow();
if (!Unsupported.IsDestroyScriptableObject(this))
{
DestroyImmediate(this);
}
return;
}
}
if (sp)
{
sp.Cleanup();
// the parent might have moved US up and gotten rid of itself
sp = parent as SplitView;
if (sp)
{
// If the parent has the same orientation as us, we can move our views up and kill ourselves
if (sp.vertical == vertical)
{
int idx = new List <View>(parent.children).IndexOf(this);
foreach (View child in children)
{
sp.AddChild(child, idx++);
child.position = new Rect(position.x + child.position.x, position.y + child.position.y, child.position.width, child.position.height);
}
}
}
}
if (children.Length == 0)
{
if (parent == null && window != null)
{
// if we're root in the window, we'll remove ourselves
window.Close();
}
else
{
ICleanuppable ic = parent as ICleanuppable;
if (parent is SplitView)
{
((SplitView)parent).RemoveChildNice(this);
if (!Unsupported.IsDestroyScriptableObject(this))
{
DestroyImmediate(this, true);
}
}
else
{
// This is we're root in the main window.
// We want to stay, but tell the parent (MainWindow) to Cleanup, so he can reduce us to zero-size
/* parent.RemoveChild (this);*/
}
ic.Cleanup();
}
return;
}
else
{
splitState = null;
Reflow();
}
}