예제 #1
0
        /// <summary>
        /// Applies layout changes to a given box and its children.
        /// </summary>
        public override void ApplyVerticalLayout([NotNull] LayoutState state, [NotNull] LayoutState.LayoutLevel level)
        {
            var node = level.BranchRoot;

            if (node.Level == 0)
            {
                node.State.SiblingsRowV = new Dimensions(
                    node.State.Top,
                    node.State.Bottom);
            }

            if (node.AssistantsRoot != null)
            {
                // assistants root has to be initialized with main node's exterior
                node.AssistantsRoot.State.CopyExteriorFrom(node.State);
                LayoutAlgorithm.VerticalLayout(state, node.AssistantsRoot);
            }

            if (node.State.NumberOfSiblings == 0)
            {
                return;
            }

            var siblingsRowExterior = Dimensions.MinMax();

            var top = node.AssistantsRoot == null
                ? node.State.SiblingsRowV.To + ParentChildSpacing
                : node.State.BranchExterior.Bottom + ParentChildSpacing;

            for (var i = 0; i < node.State.NumberOfSiblings; i++)
            {
                var child = node.Children[i];
                var rect  = child.State;

                child.State.MoveTo(0, top);
                child.State.BranchExterior = new Rect(child.State.TopLeft, child.State.Size);

                siblingsRowExterior += new Dimensions(top, top + rect.Size.Height);
            }

            siblingsRowExterior = new Dimensions(siblingsRowExterior.From, siblingsRowExterior.To);

            for (var i = 0; i < node.State.NumberOfSiblings; i++)
            {
                var child = node.Children[i];
                child.State.SiblingsRowV = siblingsRowExterior;

                // re-enter layout algorithm for child branch
                LayoutAlgorithm.VerticalLayout(state, child);
            }
        }
        /// <summary>
        /// Applies layout changes to a given box and its children.
        /// </summary>
        public override void ApplyVerticalLayout([NotNull] LayoutState state, [NotNull] LayoutState.LayoutLevel level)
        {
            var node = level.BranchRoot;

            if (node.State.NumberOfSiblings <= MaxSiblingsPerRow)
            {
                // fall back to linear layout, only have one row of boxes
                base.ApplyVerticalLayout(state, level);
                return;
            }

            if (node.Level == 0)
            {
                node.State.SiblingsRowV = new Dimensions(node.State.Top, node.State.Bottom);
            }

            if (node.AssistantsRoot != null)
            {
                // assistants root has to be initialized with main node's exterior
                node.AssistantsRoot.State.CopyExteriorFrom(node.State);
                LayoutAlgorithm.VerticalLayout(state, node.AssistantsRoot);
            }

            var prevRowExterior = new Dimensions(
                node.State.SiblingsRowV.From,
                node.AssistantsRoot == null
                ? node.State.SiblingsRowV.To
                : node.State.BranchExterior.Bottom);

            for (var row = 0; row < node.State.NumberOfSiblingRows; row++)
            {
                var siblingsRowExterior = Dimensions.MinMax();

                var spacing = row == 0 ? ParentChildSpacing : SiblingSpacing;

                // first, compute
                var from = row * node.State.NumberOfSiblingColumns;
                var to   = Math.Min(from + node.State.NumberOfSiblingColumns, node.State.NumberOfSiblings);
                for (var i = from; i < to; i++)
                {
                    var child = node.Children[i];
                    if (child.Element.IsSpecial)
                    {
                        // skip vertical spacers for now
                        continue;
                    }

                    var rect = child.State;

                    var top = prevRowExterior.To + spacing;
                    child.State.MoveTo(rect.Left, top);
                    child.State.BranchExterior = new Rect(child.State.TopLeft, child.State.Size);

                    siblingsRowExterior += new Dimensions(top, top + rect.Size.Height);
                }

                siblingsRowExterior = new Dimensions(siblingsRowExterior.From, siblingsRowExterior.To);

                var siblingsBottom = double.MinValue;
                for (var i = from; i < to; i++)
                {
                    var child = node.Children[i];
                    child.State.SiblingsRowV = siblingsRowExterior;

                    // re-enter layout algorithm for child branch
                    LayoutAlgorithm.VerticalLayout(state, child);

                    siblingsBottom = Math.Max(siblingsBottom, child.State.BranchExterior.Bottom);
                }

                prevRowExterior = new Dimensions(siblingsRowExterior.From, Math.Max(siblingsBottom, siblingsRowExterior.To));

                // now assign size to the vertical spacer, if any
                var spacerIndex = from + node.State.NumberOfSiblingColumns / 2;
                if (spacerIndex < node.State.NumberOfSiblings)
                {
                    // in the last row, spacer should only extend to the siblings row bottom,
                    // because main vertical carrier does not go below last row
                    // and thus cannot conflict with branches of children of the last row
                    var spacerBottom = row == node.State.NumberOfSiblingRows - 1
                        ? node.Children[spacerIndex - 1].State.SiblingsRowV.To
                        : prevRowExterior.To;

                    var spacer = node.Children[spacerIndex].State;
                    spacer.AdjustSpacer(
                        0, prevRowExterior.From,
                        ParentConnectorShield, spacerBottom - prevRowExterior.From);
                }
            }
        }
        /// <summary>
        /// Applies layout changes to a given box and its children.
        /// </summary>
        public override void ApplyVerticalLayout([NotNull] LayoutState state, [NotNull] LayoutState.LayoutLevel level)
        {
            var node = level.BranchRoot;

            if (node.Level == 0)
            {
                node.State.SiblingsRowV = new Dimensions(
                    node.State.Top,
                    node.State.Bottom);
            }

            if (node.State.NumberOfSiblings == 0)
            {
                return;
            }

            var siblingsRowExterior = Dimensions.MinMax();

            if (Orientation == StackOrientation.SingleRowHorizontal)
            {
                var top = node.AssistantsRoot == null
                    ? node.State.SiblingsRowV.To + ParentChildSpacing
                    : node.State.BranchExterior.Bottom + ParentChildSpacing;

                for (var i = 0; i < node.State.NumberOfSiblings; i++)
                {
                    var child = node.Children[i];
                    var rect  = child.State;

                    child.State.MoveTo(0, top);
                    child.State.BranchExterior = new Rect(child.State.TopLeft, child.State.Size);

                    siblingsRowExterior += new Dimensions(top, top + rect.Size.Height);
                }

                siblingsRowExterior = new Dimensions(siblingsRowExterior.From, siblingsRowExterior.To);

                for (var i = 0; i < node.State.NumberOfSiblings; i++)
                {
                    var child = node.Children[i];
                    child.State.SiblingsRowV = siblingsRowExterior;

                    // re-enter layout algorithm for child branch
                    LayoutAlgorithm.VerticalLayout(state, child);
                }
            }
            else if (Orientation == StackOrientation.SingleColumnVertical)
            {
                var prevRowExterior = new Dimensions(
                    node.State.SiblingsRowV.From,
                    node.State.SiblingsRowV.To);

                for (var row = 0; row < node.State.NumberOfSiblings; row++)
                {
                    // first, compute
                    var child = node.Children[row];
                    var rect  = child.State;

                    var top = prevRowExterior.To + (row == 0 ? ParentChildSpacing : SiblingSpacing);
                    child.State.MoveTo(rect.Left, top);
                    child.State.BranchExterior = new Rect(child.State.TopLeft, child.State.Size);

                    var rowExterior = new Dimensions(top, top + rect.Size.Height);

                    child = node.Children[row];
                    child.State.SiblingsRowV = rowExterior;

                    // re-enter layout algorithm for child branch
                    LayoutAlgorithm.VerticalLayout(state, child);

                    var childBranchBottom = child.State.BranchExterior.Bottom;

                    prevRowExterior = new Dimensions(rowExterior.From, Math.Max(childBranchBottom, rowExterior.To));
                }
            }
        }