Пример #1
0
        /// <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);
        }
Пример #2
0
        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>();
        }
Пример #3
0
        // 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);
            }
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        // 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;
            }
        }
Пример #6
0
            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);
            }
Пример #7
0
 public Interactivity(CogaNode parent)
 {
     Parent = parent;
 }
Пример #8
0
 public void RemoveChild(CogaNode child)
 {
     Children.Remove(child);
     OnChildRemoved?.Invoke(this, child);
 }