Example #1
0
 public void AddChild(FlexItem item)
 {
     this.flexItems.Add(item);
 }
Example #2
0
        public void Arrange()
        {
            int   j          = flexItems.Count;
            float curX       = 0;
            float curY       = 0;
            float availableW = AvaliableParentWidth;

            for (int i = 0; i < j; ++i)
            {
                FlexItem flexItem = flexItems[i];
                CssBox   box      = flexItem.Box;
                box.SetLocation(curX, curY);
                curX += flexItem.PlanWidth;
            }
            //-----------------------------------------------
            if (curX < availableW)
            {
                //find box that can expand
                List <FlexItem> widthResizableItems = new List <FlexItem>();
                for (int i = 0; i < j; ++i)
                {
                    FlexItem flexItem = flexItems[i];
                    if (!flexItem.ReachMaxHeight)
                    {
                        widthResizableItems.Add(flexItem);
                    }
                }

                //remain some space
                //so expand it
                if ((j = widthResizableItems.Count) > 0)
                {
                    //how to expand it
                    //1. check grow feature
                    int totalExpandCount = 0;
                    for (int i = j - 1; i >= 0; --i)
                    {
                        totalExpandCount += widthResizableItems[i].FlexGrow;
                    }

                    if (totalExpandCount > 0)
                    {
                        float remainingW = availableW - curX;
                        float onePart    = remainingW / totalExpandCount;
                        //add to plan width
                        for (int i = j - 1; i >= 0; --i)
                        {
                            widthResizableItems[i].PlanWidth += (onePart * widthResizableItems[i].FlexGrow);
                        }

                        //then rearrange the line again
                        curX = 0;//reset
                        for (int i = 0; i < j; ++i)
                        {
                            FlexItem flexItem = flexItems[i];
                            CssBox   box      = flexItem.Box;
                            box.SetLocation(curX, curY);
                            box.SetVisualSize(flexItem.PlanWidth, flexItem.PlanHeight);
                            curX += flexItem.PlanWidth;
                        }
                    }
                }
            }
            else if (curX > availableW)
            {
                //use more than available width
                //find if it can shrink?
            }

            this.LineWidthAfterArrange = curX;

            //-----------------------------------------------
            //check for height
            float maxHeight = 0;

            for (int i = flexItems.Count - 1; i >= 0; --i)
            {
                FlexItem flexItem = flexItems[i];
                CssBox   box      = flexItem.Box;
                if (maxHeight < box.VisualHeight)
                {
                    maxHeight = box.VisualHeight;
                }
            }
            if (maxHeight < this.AvaliableParentHeight)
            {
                //expand item or shrink
                if (this.flexCssBox.Height.IsEmptyOrAuto)
                {
                    //autoheight
                    //then set new height for parent
                    this.LineHeightAfterArrange = maxHeight;
                }
                else
                {
                    //try expand flex item
                    for (int i = flexItems.Count - 1; i >= 0; --i)
                    {
                        FlexItem flexItem = flexItems[i];
                        if (!flexItem.ReachMaxHeight)
                        {
                            flexItem.Box.SetVisualHeight(this.AvaliableParentHeight);
                        }
                    }
                    this.LineHeightAfterArrange = this.AvaliableParentHeight;
                }
            }
        }
Example #3
0
 public void AddChild(FlexItem item)
 {
     this.flexItems.Add(item);
 }