private void ArrangeNodes(HorizontalStraightLayoutNode parent, IReadOnlyCollection <Node> children, float factor, NodeSide anchor, bool isCollapsed)
        {
            if (children.Count > 0)
            {
                float x = 0, y = 0;

                if (!isCollapsed)
                {
                    x = parent.Position.X
                        + (factor * parent.RenderWidth)
                        + (factor * Layout.HorizontalMargin);
                    y = parent.Position.Y - (parent.TreeHeight * 0.5f) + Layout.ElementMargin;
                }

                foreach (var child in children)
                {
                    var childLayout = (HorizontalStraightLayoutNode)child.LayoutData;

                    if (!isCollapsed)
                    {
                        var childX = x;
                        var childY = y + (0.5f * childLayout.TreeHeight);

                        childLayout.MoveTo(new Vector2(childX, childY), anchor);

                        y += childLayout.TreeSize.Y;
                    }

                    ArrangeNodes(childLayout, child.Children, factor, anchor, isCollapsed || child.IsCollapsed);
                }
            }
        }
Exemple #2
0
        private HorizontalStraightLayoutNode(IRenderNode renderNode, HorizontalStraightLayoutNode parent)
        {
            this.parent     = parent;
            this.renderSize = renderNode.RenderSize;
            this.renderNode = renderNode;

            TreeSize = renderNode.RenderSize;
        }
Exemple #3
0
        public static HorizontalStraightLayoutNode AttachTo(NodeBase node, IRenderNode renderNode, HorizontalStraightLayoutNode parent)
        {
            var layoutNode = new HorizontalStraightLayoutNode(renderNode, parent);

            node.LayoutData = layoutNode;

            return(layoutNode);
        }
        private void ArrangeRoot()
        {
            var rootLayoutNode = HorizontalStraightLayoutNode.AttachTo(Document.Root, Scene.FindRenderNode(Document.Root), null);

            rootLayoutNode.MoveTo(MindmapCenter, NodeSide.Auto);

            Arrange(rootLayoutNode, Document.Root.LeftChildren, -1.0f, NodeSide.Right);
            Arrange(rootLayoutNode, Document.Root.RightChildren, 1.0f, NodeSide.Left);
        }
        private void Arrange(HorizontalStraightLayoutNode root, IReadOnlyCollection <Node> children, float factor, NodeSide anchor)
        {
            UpdateSizeWithChildren(root, children, Document.Root.IsCollapsed);

            var x = MindmapCenter.X - (factor * 0.5f * root.RenderWidth);
            var y = MindmapCenter.Y;

            root.Position = new Vector2(x, y);

            ArrangeNodes(root, children, factor, anchor, Document.Root.IsCollapsed);
        }
        private void UpdateSizeWithChildren(HorizontalStraightLayoutNode parent, IReadOnlyCollection <Node> children, bool isCollapsed)
        {
            var treeW = parent.RenderSize.X;
            var treeH = parent.RenderSize.Y;

            if (children.Count > 0)
            {
                if (isCollapsed)
                {
                    foreach (var child in children)
                    {
                        var childData = HorizontalStraightLayoutNode.AttachTo(child, Scene.FindRenderNode(child), parent);

                        UpdateSizeWithChildren(childData, child.Children, child.IsCollapsed);
                    }
                }
                else
                {
                    float childsW = 0;
                    float childsH = 0;

                    foreach (var child in children)
                    {
                        var childData = HorizontalStraightLayoutNode.AttachTo(child, Scene.FindRenderNode(child), parent);

                        UpdateSizeWithChildren(childData, child.Children, child.IsCollapsed);

                        childsH += childData.TreeHeight;
                        childsW  = Math.Max(childData.TreeWidth, childsW);
                    }

                    treeW += Layout.HorizontalMargin;
                    treeW += childsW;
                    treeH  = childsH;
                }
            }

            treeH += 2 * Layout.ElementMargin;

            parent.TreeSize = new Vector2(treeW, treeH);
        }