/// <summary> /// Changes the node's Parent. This will automatically handle moving the widget /// into the new space and handling references such as `.Parent` and children. /// </summary> public virtual CogaNode SetParent(CogaNode parent) { if (Parent != null) { Parent.Children.Remove(this); Parent.OnChildRemoved?.Invoke(Parent, this); Parent.SetChildrenDirty(); Parent.SetDirty(); OnActiveChange = null; } Parent = parent; Parent.OnActiveChange += (node) => { OnActiveChange?.Invoke(this); }; Parent.SetChildrenDirty(); if (!Parent.Children.Contains(this)) { Parent.Children.Add(this); } if (Parent.Manager != null) { PropagateManager(this, Parent.Manager); } return(this); }
public InternalRowLayout(CogaNode parent) { // Manage relationships. Parent = parent; // Create and set the index at 0. Rows = new List <Row>(); Rows.Add(new Row(Parent.Compute.Width - Parent.ComputedPadding[Edge.Horizontal].Value)); CumulativeHeights = new List <float>(); CumulativeHeights.Add(0f); current_row = 0; HeightFillRows = new List <int>(); }
// Local function to recurse the new manager throughout the tree. // This is necessary for nodes that are put together before being // added to the root. void PropagateManager(CogaNode node, ICogaManager manager) { if (node.Manager == null) { node.Manager = manager; node.OnReceiveManager(); } foreach (var c in node.Children) { PropagateManager(c, manager); } }
/// <summary> /// Adds a child to this node's hierarchy. Handles everything including removing /// the child reference from the previous parent if one existed. /// </summary> public virtual CogaNode AddChild(CogaNode child) { child.SetParent(this); Children.Add(child); OnChildAdded?.Invoke(this, child); SetDirty(); SetChildrenDirty(); if (IsRoot) { PropagateManager(this, Manager); } else if (Manager != null) { PropagateManager(this, Manager); } return(this); }
// Adds a child to the current row if it can fit, if not start a new one. public void AddChild(CogaNode node) { switch (Parent.NodeConfiguration.Direction) { case CogaDirection.Horizontal: if (node.Compute.Width > Rows[current_row].RemainingWidth) { current_row++; Rows.Add(new Row(Parent.Compute.Width - Parent.ComputedPadding[Edge.Horizontal].Value)); CumulativeHeights.Add(0f); } Rows[current_row].Add(node, Parent.NodeConfiguration.Spacing); break; case CogaDirection.Vertical: Rows[current_row].Add(node, Parent.NodeConfiguration.Spacing); current_row++; Rows.Add(new Row(Parent.Compute.Width - Parent.ComputedPadding[Edge.Horizontal].Value)); CumulativeHeights.Add(0f); break; } }
public void Add(CogaNode child, float spacing = 0f) { if (Children.Count > 0) { RemainingWidth -= spacing; } Children.Add(child); if (child.Compute.HeightResolved && child.Compute.Height > Height) { Height = child.Compute.Height; } if (child.NodeConfiguration.Width.ValueType == CogaValueMode.Fill) { DynamicWidthChildren.Add(child); } if (child.NodeConfiguration.Height.ValueType == CogaValueMode.Fill) { DynamicHeightChildren.Add(child); } RemainingWidth -= (child.Compute.Width); }
public Interactivity(CogaNode parent) { Parent = parent; }
public void RemoveChild(CogaNode child) { Children.Remove(child); OnChildRemoved?.Invoke(this, child); }