Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        private LayoutBoxInformation calculateRelativeLayoutBoxes(ILayoutBox layoutComponent, AbsoluteSize clientSize)
        {
            RelativeLength width  = layoutComponent.Width;
            RelativeLength height = layoutComponent.Height;

            var component = (IComponent)layoutComponent;

            var siblings            = component.Parent.Children.Where(x => x != component);
            var totalSiblingsWidth  = siblings.Where(x => x is ILayoutBox).Select(x => ((ILayoutBox)x).Width).Aggregate((total, sibling) => { return(total + sibling); });
            var totalSiblingsHeight = siblings.Where(x => x is ILayoutBox).Select(x => ((ILayoutBox)x).Height).Aggregate((total, sibling) => { return(total + sibling); });

            var totalWidth  = totalSiblingsWidth + width;
            var totalHeight = totalSiblingsHeight + height;

            // Does it have related length (Like 1x or 5x)?
            var hasRelatedWidth  = width[UnitType.Ratio] != 0;
            var hasRelatedHeight = height[UnitType.Ratio] != 0;

            // Assume siblings related lengths to '0' if this component is 'Fill'
            if (width == RelativeLength.Infinity)
            {
                totalSiblingsWidth -= totalSiblingsWidth[UnitType.Ratio];
            }
            if (height == RelativeLength.Infinity)
            {
                totalSiblingsHeight -= totalSiblingsHeight[UnitType.Ratio];
            }

            // Assume the length as 'Fill' if this component have related length but siblings don't.
            if (hasRelatedWidth && totalSiblingsWidth[UnitType.Ratio] == 0)
            {
                width = RelativeLength.Infinity;
            }
            if (hasRelatedHeight && totalSiblingsHeight[UnitType.Ratio] == 0)
            {
                height = RelativeLength.Infinity;
            }

            // Assume the length as 'content length' if this component is 'Shrink' and at least one of the siblings has related or fill length.
            if (width == RelativeLength.NaN && (totalSiblingsWidth[UnitType.Ratio] != 0 || totalSiblingsWidth == RelativeLength.Infinity))
            {
                width = calculateContentWidth(layoutComponent);
            }
            if (height == RelativeLength.NaN && (totalSiblingsHeight[UnitType.Ratio] != 0 || totalSiblingsHeight == RelativeLength.Infinity))
            {
                height = calculateContentHeight(layoutComponent);
            }


            // Calculate size
            var absoluteWidth  = calculateLength(width, totalWidth, clientSize.Width);
            var absoluteHeight = calculateLength(height, totalHeight, clientSize.Height);

            // Calculate margins (based on parent client area)
            var marginTop    = calculateLength(layoutComponent.Margin.Top, clientSize.Height);
            var marginRight  = calculateLength(layoutComponent.Margin.Right, clientSize.Width);
            var marginBottom = calculateLength(layoutComponent.Margin.Bottom, clientSize.Height);
            var marginLeft   = calculateLength(layoutComponent.Margin.Left, clientSize.Width);

            // Calculate paddings (based on self client area)
            var paddingTop    = calculateLength(layoutComponent.Padding.Top, absoluteHeight);
            var paddingRight  = calculateLength(layoutComponent.Padding.Right, absoluteWidth);
            var paddingBottom = calculateLength(layoutComponent.Padding.Bottom, absoluteHeight);
            var paddingLeft   = calculateLength(layoutComponent.Padding.Left, absoluteWidth);

            return(new LayoutBoxInformation()
            {
                AbsoluteMarginBox = new AbsoluteRectangle(
                    0,
                    0,
                    absoluteWidth + marginLeft + marginRight,
                    absoluteHeight + marginTop + marginBottom
                    ),
                AbsoluteBox = new AbsoluteRectangle(
                    marginLeft,
                    marginTop,
                    absoluteWidth,
                    absoluteHeight
                    ),
                AbsolutePaddingBox = new AbsoluteRectangle(
                    marginLeft + paddingLeft,
                    marginTop + paddingTop,
                    absoluteWidth - paddingLeft - paddingRight,
                    absoluteHeight - paddingTop - paddingBottom
                    ),
                LayoutDirection = layoutComponent.LayoutDirection
            });
        }
 public FrameRenderer(AbsoluteSize clientSize, SKSurface surface)
 {
     this.clientSize = clientSize;
     this.surface    = surface;
     canvas          = surface.Canvas;
 }