/// <summary>
        /// Group elements.
        /// </summary>
        protected override void Group()
        {
            ElementsGroup.Clear();

            var row = new List <LayoutElementInfo>();

            ElementsGroup.Add(row);

            if (!Layout.FlexSettings.Wrap)
            {
                row.AddRange(Elements);
                return;
            }

            var base_size = Layout.MainAxisSize;
            var size      = base_size;
            var spacing   = Layout.IsHorizontal ? Layout.Spacing.x : Layout.Spacing.y;

            for (int i = 0; i < Elements.Count; i++)
            {
                if (row.Count == 0)
                {
                    size -= Elements[i].AxisSize;
                    row.Add(Elements[i]);
                    continue;
                }

                var element_size = Elements[i].AxisSize + spacing;
                if (size >= element_size)
                {
                    size -= element_size;
                    row.Add(Elements[i]);
                }
                else
                {
                    size = base_size - Elements[i].AxisSize;

                    row = new List <LayoutElementInfo>();
                    ElementsGroup.Add(row);

                    row.Add(Elements[i]);
                }
            }

            if (!Layout.TopToBottom)
            {
                ElementsGroup.Reverse();
            }

            if (Layout.RightToLeft)
            {
                ElementsGroup.ForEach(ReverseList);
            }
        }
Beispiel #2
0
        void InsertToBlock(int block_index, LayoutElementInfo element)
        {
            for (int i = ElementsGroup.Count; i <= block_index; i++)
            {
                ElementsGroup.Add(new List <LayoutElementInfo>());
            }

            var row = ElementsGroup[block_index];

            row.Add(element);

            BlocksSizes[block_index] += element.AxisSize;
            if (row.Count > 1)
            {
                var spacing = Layout.IsHorizontal ? Layout.Spacing.x : Layout.Spacing.y;
                BlocksSizes[block_index] += spacing;
            }
        }