Exemplo n.º 1
0
            private void ApplyAlignment(Size mySize, IRenderElementStyle myStyle, IList <IRenderElement> children)
            {
                foreach (var item in children)
                {
                    Point itemPos    = item.Display.Region.MarginRect.Location;
                    Size  marginSize = item.Display.Region.MarginSize;

                    switch (myStyle.Flex?.AlignItems ?? AlignItems.Default)
                    {
                    case AlignItems.End:
                        itemPos = IncCross(itemPos, CrossAxis(mySize) - CrossAxis(marginSize));
                        break;

                    case AlignItems.Center:
                        itemPos = IncCross(itemPos, (CrossAxis(mySize) - CrossAxis(marginSize)) / 2);
                        break;

                    case AlignItems.Stretch:
                        marginSize = SetCrossSize(marginSize, CrossAxis(mySize));
                        break;
                    }

                    item.Display.Region.SetMarginPosition(itemPos);
                    item.Display.Region.SetMarginSize(marginSize);
                }
            }
Exemplo n.º 2
0
            private void PositionChildren(Size mySize,
                                          IRenderElementStyle myStyle,
                                          IList <IRenderElement> children)
            {
                Point dest = new Point(0, 0);

                foreach (var item in children)
                {
                    item.Display.Region.SetMarginPosition(dest);

                    dest = IncMain(dest, MainAxis(item.Display.Region.MarginSize));
                }
            }
Exemplo n.º 3
0
            public void PerformLayout(
                IUserInterfaceRenderContext renderContext,
                Size mySize,
                IRenderElementStyle myStyle,
                IList <IRenderElement> children)
            {
                int idealSizeOfAllChildren = CalcChildrenIdealSizes(renderContext, mySize, children);

                int extraSpace = MainAxis(mySize) - idealSizeOfAllChildren;

                GrowFlexItems(children, ref extraSpace);
                ContractItems(children, mySize, ref extraSpace);

                PositionChildren(mySize, myStyle, children);
                ApplyAlignment(mySize, myStyle, children);

                DistributeExtraSpace(myStyle, children, ref extraSpace);
            }
Exemplo n.º 4
0
            private void DistributeExtraSpace(IRenderElementStyle myStyle,
                                              IList <IRenderElement> children,
                                              ref int extraSpace)
            {
                if (extraSpace <= 0)
                {
                    return;
                }

                switch (myStyle.Flex?.JustifyContent ?? JustifyContent.Default)
                {
                case JustifyContent.Center:
                    foreach (var item in children)
                    {
                        item.Display.MarginRect = IncMain(item.Display.MarginRect, extraSpace / 2);
                    }
                    break;

                case JustifyContent.End:
                    foreach (var item in children)
                    {
                        item.Display.MarginRect = IncMain(item.Display.MarginRect, extraSpace);
                    }
                    break;

                case JustifyContent.SpaceBetween:
                    DistributeSpaceBetween(children, extraSpace);
                    break;

                case JustifyContent.SpaceAround:
                    DistributeSpaceAround(children, extraSpace);
                    break;

                case JustifyContent.SpaceEvenly:
                    DistributeSpaceEvenly(children, extraSpace);
                    break;
                }

                extraSpace = 0;
            }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a WidgetLayout structure.
 /// </summary>
 /// <param name="activeStyle"></param>
 public RenderElementRegion(IRenderElementStyle activeStyle)
 {
     this.Style = activeStyle;
 }