Exemple #1
0
        /// <summary>
        /// Updates the bounds of child elements when flow is to Left.
        /// </summary>
        private void UpdateRegionsFlowsToLeft(Graphics g, RibbonElementSizeMode mode)
        {
            int curRight   = ContentBounds.Left + Owner.ItemPadding.Horizontal + 0;
            int curBottom  = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
            int lastRight  = curRight;
            int lastBottom = 0;
            List <RibbonItem> lastColumn = new List <RibbonItem>();

            ///Iterate thru items on panel
            for (int i = Items.Count - 1; i >= 0; i--)
            {
                RibbonItem item = Items[i];

                ///Gets the last measured size (to avoid re-measuring calculations)
                Size itemSize;
                if (item.Visible)
                {
                    itemSize = item.LastMeasuredSize;
                }
                else
                {
                    itemSize = new Size(0, 0);
                }

                ///If not enough space available, reset curBottom and advance curRight
                if (curBottom + itemSize.Height > ContentBounds.Bottom)
                {
                    curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                    curRight  = lastRight + Owner.ItemPadding.Horizontal + 0;
                    Items.CenterItemsVerticallyInto(lastColumn, ContentBounds);
                    lastColumn.Clear();
                }

                ///Set the item's bounds
                item.SetBounds(new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height));

                ///save last right and bottom
                lastRight  = Math.Max(item.Bounds.Right, lastRight);
                lastBottom = item.Bounds.Bottom;

                ///update current bottom
                curBottom = item.Bounds.Bottom + Owner.ItemPadding.Vertical + 1;

                ///Add to the collection of items of the last column
                lastColumn.Add(item);
            }

            ///Center the items vertically on the last column
            Items.CenterItemsVerticallyInto(lastColumn, Items.GetItemsBounds());
        }
Exemple #2
0
        /// <summary>
        /// Updates the bounds of child elements when flow is to bottom
        /// </summary>
        private void UpdateRegionsFlowsToRight(Graphics g, RibbonElementSizeMode mode)
        {
            int curLeft   = ContentBounds.Left;
            int curTop    = ContentBounds.Top;
            int padding   = mode == RibbonElementSizeMode.Medium ? 7 : 0;
            int maxBottom = 0;

            #region Sorts from larger to smaller

            RibbonItem[] array = Items.ToArray();

            for (int i = (array.Length - 1); i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (array[j - 1].LastMeasuredSize.Width < array[j].LastMeasuredSize.Width)
                    {
                        RibbonItem temp = array[j - 1];
                        array[j - 1] = array[j];
                        array[j]     = temp;
                    }
                }
            }

            #endregion

            List <RibbonItem> list = new List <RibbonItem>(array);

            ///Attend elements, deleting every attended element from the list
            while (list.Count > 0)
            {
                ///Extract item and delete it
                RibbonItem item = list[0];
                list.Remove(item);

                ///If not enough space left, reset left and advance top
                if (curLeft + item.LastMeasuredSize.Width > ContentBounds.Right)
                {
                    curLeft = ContentBounds.Left;
                    curTop  = maxBottom + Owner.ItemPadding.Vertical + 1 + padding;
                }

                ///Set item's bounds
                item.SetBounds(new Rectangle(new Point(curLeft, curTop), item.LastMeasuredSize));

                ///Increment reminders
                curLeft  += item.Bounds.Width + Owner.ItemPadding.Horizontal;
                maxBottom = Math.Max(maxBottom, item.Bounds.Bottom);

                ///Check available space after placing item
                int spaceAvailable = ContentBounds.Right - curLeft;

                ///Check for elements that fit on available space
                for (int i = 0; i < list.Count; i++)
                {
                    ///If item fits on the available space
                    if (list[i].LastMeasuredSize.Width < spaceAvailable)
                    {
                        ///Place the item there and reset the counter to check for further items
                        list[i].SetBounds(new Rectangle(new Point(curLeft, curTop), list[i].LastMeasuredSize));
                        curLeft       += list[i].Bounds.Width + Owner.ItemPadding.Horizontal;
                        maxBottom      = Math.Max(maxBottom, list[i].Bounds.Bottom);
                        spaceAvailable = ContentBounds.Right - curLeft;
                        list.RemoveAt(i);
                        i = 0;
                    }
                }
            }
        }