Example #1
0
        private RadSize MeasureHorizontally(RadSize availableSize, double offset, double bufferScale)
        {
            //TODO: add buffer here
            var context = new MeasureContext()
            {
                Offset      = offset,
                BufferScale = bufferScale
            };

            context.InitializeForHorizontalMeasure(this.Layout, availableSize);

            this.AvailableLength = context.AvailableLength;


            if (this.IsBufferNeeded)
            {
                context.FirstVisibleIndex = this.GenerateTopBufferItems(context.FirstVisibleIndex, context.AvailableLength, context.Offset, context);
                context.LastVisibleIndex  = context.FirstVisibleIndex;
            }

            this.MeasureForward(ref context);

            //TODO: Investigate the case with maximizing and incorrect scroll offset.
            if (context.AvailableLength - context.ForwardGeneratedLength > ListViewModel.DoubleArithmetics.Ceiling(1d / IndexStorage.PrecisionMultiplier))
            {
                if (this.viewportItemsCount < this.Layout.VisibleLineCount)
                {
                    // perform the measure logic again, since this difference will most probably occur when the Index tree is cleared before the measure pass
                    this.RecycleLocally();
                    context.InitializeForHorizontalMeasure(this.Layout, availableSize);

                    if (this.IsBufferNeeded)
                    {
                        context.FirstVisibleIndex = this.GenerateTopBufferItems(context.FirstVisibleIndex, context.AvailableLength, context.Offset, context);
                        context.LastVisibleIndex  = context.FirstVisibleIndex;
                    }

                    this.MeasureForward(ref context);
                }
            }

            this.MeasureBackwards(ref context);

            if (this.IsBufferNeeded)
            {
                this.GenerateBottomBufferItems(context.LastVisibleIndex, context.AvailableLength, context);
            }

            var desiredSize = this.ComputeDesiredSize(context);

            this.Layout.UpdateAverageLength(context.FirstVisibleIndex, context.LastVisibleIndex);

            return(desiredSize);
        }
Example #2
0
        private RadSize MeasureHorizontally(RadSize availableSize, double offset, int frozenElementsCount)
        {
            var context = new MeasureContext()
            {
                Offset = offset
            };

            if (frozenElementsCount > 0)
            {
                var frozenGeneratedContext = this.MeasureHorizontalFrozenElements(availableSize, frozenElementsCount);
                context.InitializeForHorizontalMeasure(this, availableSize, frozenGeneratedContext);
            }
            else
            {
                context.InitializeForHorizontalMeasure(this, availableSize);
            }

            this.AvailableLength = context.AvailableLength;
            this.MeasureForward(ref context);

            if (context.AvailableLength - context.ForwardGeneratedLength > GridModel.DoubleArithmetics.Ceiling(1d / IndexStorage.PrecisionMultiplier))
            {
                if (context.FirstVisibleIndex + this.ViewportItemCount < this.layout.VisibleLineCount)
                {
                    // perform the measure logic again, since this difference will most probably occur when the Index tree is cleared before the measure pass
                    this.RecycleLocally();
                    context.InitializeForHorizontalMeasure(this, availableSize);
                    this.MeasureForward(ref context);
                }
            }

            context.FirstVisibleIndex -= this.owner.FrozenColumnCount;
            this.MeasureBackwards(ref context);

            var desiredSize = new RadSize(context.GeneratedLength, context.MaxLength);

            desiredSize.Width  = Math.Min(desiredSize.Width, context.AvailableLength);
            desiredSize.Height = Math.Min(desiredSize.Height, GridModel.DoubleArithmetics.Ceiling(availableSize.Height));

            this.Layout.UpdateAverageLength(context.FirstVisibleIndex, context.LastVisibleIndex);

            return(desiredSize);
        }
Example #3
0
        private MeasureContext MeasureHorizontalFrozenElements(RadSize availableSize, int frozenContainersCount)
        {
            var context = new MeasureContext();

            context.InitializeForHorizontalMeasure(this, availableSize);

            if (frozenContainersCount == 0)
            {
                return(context);
            }

            var firstContainerDesiredSize = new RadSize();
            var lastContainerDesiredSize  = new RadSize();

            using (var itemInfos = this.layout.GetLines(context.FirstVisibleIndex, true).GetEnumerator())
            {
                if (itemInfos.MoveNext())
                {
                    firstContainerDesiredSize      = this.GenerateContainer(itemInfos.Current);
                    context.ForwardGeneratedLength = context.GetLength(firstContainerDesiredSize);
                    context.MaxLength = Math.Max(context.MaxLength, context.GetOppositeLength(firstContainerDesiredSize));

                    // Take the length portion of the indexed element that is not currently in viewport.
                    this.HiddenPixels = GridModel.DoubleArithmetics.Floor(context.ForwardGeneratedLength * (context.Index % 1));
                    context.ForwardGeneratedLength -= this.HiddenPixels;

                    context.ForwardGeneratedLength = GridModel.DoubleArithmetics.Ceiling(context.ForwardGeneratedLength);
                    lastContainerDesiredSize       = firstContainerDesiredSize;

                    this.ViewportItemCount++;
                }

                while (frozenContainersCount - 1 > context.LastVisibleIndex && GridModel.DoubleArithmetics.IsLessThan(context.ForwardGeneratedLength, context.AvailableLength) && itemInfos.MoveNext())
                {
                    context.LastVisibleIndex++;
                    lastContainerDesiredSize        = this.GenerateContainer(itemInfos.Current);
                    context.ForwardGeneratedLength += context.GetLength(lastContainerDesiredSize);
                    context.MaxLength = Math.Max(context.MaxLength, context.GetOppositeLength(lastContainerDesiredSize));

                    this.ViewportItemCount++;
                }
            }

            return(context);
        }