Esempio n. 1
0
        private void processComponent(IElement element, LayoutCalculationContext context, ref AbsolutePoint currentOffset)
        {
            if (element is ILayoutBox layoutComponent)
            {
                validateMeasures(layoutComponent);
                var parentLayoutBox = context.GetLayoutBoxInformation(element.Parent);

                var layoutBox = calculateRelativeLayoutBoxes(layoutComponent, parentLayoutBox.AbsolutePaddingBox.Size);

                // Convert relative location to absolute location
                layoutBox.AbsoluteMarginBox.Offset(parentLayoutBox.AbsolutePaddingBox.Location);
                layoutBox.AbsoluteBox.Offset(parentLayoutBox.AbsolutePaddingBox.Location);
                layoutBox.AbsolutePaddingBox.Offset(parentLayoutBox.AbsolutePaddingBox.Location);

                // Adjust location because of previous siblings
                layoutBox.AbsoluteMarginBox.Offset(currentOffset);
                layoutBox.AbsoluteBox.Offset(currentOffset);
                layoutBox.AbsolutePaddingBox.Offset(currentOffset);

                // Add this component to offset too to adjust next siblings (based on margin box).
                if (parentLayoutBox.LayoutDirection == LayoutDirection.Vertical)
                {
                    currentOffset.Y += layoutBox.AbsoluteMarginBox.Size.Height;
                }
                if (parentLayoutBox.LayoutDirection == LayoutDirection.Horizontal)
                {
                    currentOffset.X += layoutBox.AbsoluteMarginBox.Size.Width;
                }

                context.SetLayoutBoxInformation(element, layoutBox);
            }
            else
            {
                // If this is not an ILayoutBox (layoutable) component, set it's client from it's parent.
                context.SetLayoutBoxInformation(element, context.GetLayoutBoxInformation(element.Parent));
            }

            var childrenOffset = new AbsolutePoint();

            // Continue with the children
            foreach (var child in element.Children)
            {
                processComponent(child, context, ref childrenOffset);
            }
        }
Esempio n. 2
0
        public LayoutCalculationResult ProcessLayout(AbsoluteSize clientSize, IElementTree componentTree)
        {
            //componentTree.Restructure();
            var context = new LayoutCalculationContext();

            var rootComponentBox = context.GetLayoutBoxInformation(componentTree.Owner);

            rootComponentBox.AbsoluteBox        = new AbsoluteRectangle(0, 0, clientSize.Width, clientSize.Height);
            rootComponentBox.AbsoluteMarginBox  = rootComponentBox.AbsoluteBox;
            rootComponentBox.AbsolutePaddingBox = rootComponentBox.AbsoluteBox;
            rootComponentBox.LayoutDirection    = LayoutDirection.Vertical;

            var childrenOffset = new AbsolutePoint();

            foreach (var component in componentTree.Owner.ElementTree.Children)
            {
                processComponent(component, context, ref childrenOffset);
            }

            var filteredBoxes = context.LayoutBoxes.ToDictionary(x => (ILayoutBox)x.Key, x => x.Value);

            return(new LayoutCalculationResult(filteredBoxes));
        }