Esempio n. 1
0
        // We have to reset the reduce order to it's initial value, clear all caches we keep here and invalidate measure/arrange
#pragma warning disable CA1801 // Review unused parameters
        internal void GroupBoxCacheClearedAndStateAndScaleResetted(RibbonGroupBox ribbonGroupBox)
#pragma warning restore CA1801 // Review unused parameters
        {
            var ribbonPanel = this;

            var newReduceOrderIndex = ribbonPanel.reduceOrder.Length - 1;

            ribbonPanel.reduceOrderIndex = newReduceOrderIndex;

            this.measureCache = default;

            foreach (var item in this.InternalChildren)
            {
                var groupBox = item as RibbonGroupBox;
                if (groupBox is null)
                {
                    continue;
                }

                groupBox.TryClearCacheAndResetStateAndScale();
            }

            ribbonPanel.InvalidateMeasure();
            ribbonPanel.InvalidateArrange();
        }
        /// <inheritdoc />
        protected override Size MeasureOverride(Size availableSize)
        {
            var desiredSize = this.GetChildrenDesiredSizeIntermediate();

            if (this.reduceOrder.Length == 0
                // Check cached measure to prevent "flicker"
                || (this.measureCache.AvailableSize == availableSize && this.measureCache.DesiredSize == desiredSize))
            {
                this.VerifyScrollData(availableSize.Width, desiredSize.Width);
                return(desiredSize);
            }

            // If we have more available space - try to expand groups
            while (desiredSize.Width <= availableSize.Width)
            {
                var hasMoreVariants = this.reduceOrderIndex < this.reduceOrder.Length - 1;
                if (hasMoreVariants == false)
                {
                    break;
                }

                // Increase size of another item
                this.reduceOrderIndex++;
                this.IncreaseGroupBoxSize(this.reduceOrder[this.reduceOrderIndex]);

                desiredSize = this.GetChildrenDesiredSizeIntermediate();
            }

            // If not enough space - go to next variant
            while (desiredSize.Width > availableSize.Width)
            {
                var hasMoreVariants = this.reduceOrderIndex >= 0;
                if (hasMoreVariants == false)
                {
                    break;
                }

                // Decrease size of another item
                this.DecreaseGroupBoxSize(this.reduceOrder[this.reduceOrderIndex]);
                this.reduceOrderIndex--;

                desiredSize = this.GetChildrenDesiredSizeIntermediate();
            }

            // Set find values
            foreach (var item in this.InternalChildren)
            {
                var groupBox = item as RibbonGroupBox;
                if (groupBox == null)
                {
                    continue;
                }

                if (groupBox.State != groupBox.StateIntermediate ||
                    groupBox.Scale != groupBox.ScaleIntermediate)
                {
                    groupBox.SuppressCacheReseting = true;
                    groupBox.State = groupBox.StateIntermediate;
                    groupBox.Scale = groupBox.ScaleIntermediate;
                    groupBox.InvalidateLayout();
                    groupBox.Measure(new Size(double.PositiveInfinity, availableSize.Height));
                    groupBox.SuppressCacheReseting = false;
                }

                // Something wrong with cache?
                if (groupBox.DesiredSizeIntermediate != groupBox.DesiredSize)
                {
                    // Reset cache and reinvoke masure
                    groupBox.ClearCache();
                    return(this.MeasureOverride(availableSize));
                }
            }

            this.measureCache = new MeasureCache(availableSize, desiredSize);

            this.VerifyScrollData(availableSize.Width, desiredSize.Width);
            return(desiredSize);
        }