private double ComputeScrollOffsetWithMinimalScroll(double topView, double bottomView, double topChild, double bottomChild) { bool flag = DoubleUtil.LessThan(topChild, topView) && DoubleUtil.LessThan(bottomChild, bottomView); bool flag2 = DoubleUtil.GreaterThan(bottomChild, bottomView) && DoubleUtil.GreaterThan(topChild, topView); bool flag3 = (bottomChild - topChild) > (bottomView - topView); if (flag && !flag3) { return(topChild); } if (flag2 && flag3) { return(topChild); } if (!flag && !flag2) { return(topView); } return(bottomChild - (bottomView - topView)); }
protected override Size MeasureOverride(Size constraint) { int num; double width; UIElementCollection internalChildren = base.InternalChildren; Size size = new Size(); Size availableSize = constraint; bool flag = this.Orientation == Orientation.Horizontal; int num2 = -1; if (flag) { availableSize.Width = double.PositiveInfinity; if (this.IsScrolling && this.CanVerticallyScroll) { availableSize.Height = double.PositiveInfinity; } num = this.IsScrolling ? CoerceOffsetToInteger(this._scrollData._offset.X, internalChildren.Count) : 0; width = constraint.Width; } else { availableSize.Height = double.PositiveInfinity; if (this.IsScrolling && this.CanHorizontallyScroll) { availableSize.Width = double.PositiveInfinity; } num = this.IsScrolling ? CoerceOffsetToInteger(this._scrollData._offset.Y, internalChildren.Count) : 0; width = constraint.Height; } int num5 = 0; int count = internalChildren.Count; while (num5 < count) { UIElement element = internalChildren[num5]; if (element != null) { double height; element.Measure(availableSize); Size desiredSize = element.DesiredSize; if (flag) { size.Width += desiredSize.Width; size.Height = Math.Max(size.Height, desiredSize.Height); height = desiredSize.Width; } else { size.Width = Math.Max(size.Width, desiredSize.Width); size.Height += desiredSize.Height; height = desiredSize.Height; } if ((this.IsScrolling && (num2 == -1)) && (num5 >= num)) { width -= height; if (DoubleUtil.LessThanOrClose(width, 0.0)) { num2 = num5; } } } num5++; } if (this.IsScrolling) { Size viewport = constraint; Size extent = size; Vector offset = this._scrollData._offset; if (num2 == -1) { num2 = internalChildren.Count - 1; } int num10 = (num > Children.Count - 1) ? Children.Count : num; num10 = num10 < 0 ? num10 + Children.Count : num10; while (num10 > 0) { double num7 = width; if (flag) { num7 -= internalChildren[(num10 - 1) % Children.Count].DesiredSize.Width; } else { num7 -= internalChildren[(num10 - 1) % Children.Count].DesiredSize.Height; } if (DoubleUtil.LessThan(num7, 0.0)) { break; } num10--; width = num7; } int num8 = internalChildren.Count; int num9 = num2 - num10; if ((num9 == 0) || DoubleUtil.GreaterThanOrClose(width, 0.0)) { num9++; } if (flag) { this._scrollData._physicalViewport = viewport.Width; viewport.Width = num9; extent.Width = num8; offset.X = num; offset.Y = Math.Max(0.0, Math.Min(offset.Y, extent.Height - viewport.Height)); } else { this._scrollData._physicalViewport = viewport.Height; viewport.Height = num9; extent.Height = num8; offset.Y = num; offset.X = Math.Max(0.0, Math.Min(offset.X, extent.Width - viewport.Width)); } size.Width = Math.Min(size.Width, constraint.Width); size.Height = Math.Min(size.Height, constraint.Height); this.VerifyScrollingData(viewport, extent, offset); } return(size); }
private void MakeVisibleLogicalHelper(int childIndex, ref Vector newOffset, ref Rect newRect) { int x; int width; bool flag = this.Orientation == Orientation.Horizontal; double num4 = 0.0; if (flag) { x = (int)this._scrollData._computedOffset.X; width = (int)this._scrollData._viewport.Width; } else { x = (int)this._scrollData._computedOffset.Y % Children.Count; width = (int)this._scrollData._viewport.Height; } int num2 = x; bool needsScroll = (childIndex >= x && childIndex < x + width || childIndex + Children.Count < x + width) ? false : true; if (needsScroll) { int abst = (x + width - childIndex + Children.Count) % Children.Count; bool scrollUp = false; if ((childIndex < x) && (x - childIndex < abst)) { abst = x - childIndex; scrollUp = true; } if (abst > (Children.Count - width) / 2) { scrollUp = !scrollUp; } if (scrollUp) { num2 = childIndex; } else { Size desiredSize = base.InternalChildren[childIndex].DesiredSize; double num5 = flag ? desiredSize.Width : desiredSize.Height; double num6 = this._scrollData._physicalViewport - num5; int num7 = childIndex; while (DoubleUtil.GreaterThanOrClose(num6, 0.0)) { num7 = ((num7 - 1) + Children.Count) % Children.Count; desiredSize = base.InternalChildren[num7].DesiredSize; num5 = flag ? desiredSize.Width : desiredSize.Height; num4 += num5; num6 -= num5; } if ((num7 != childIndex) && DoubleUtil.LessThan(num6, 0.0)) { num4 -= num5; num7++; } num2 = num7; } } if (flag) { newOffset.X = num2; newRect.X = num4; newRect.Width = base.InternalChildren[childIndex].DesiredSize.Width; } else { newOffset.Y = num2; newRect.Y = num4; newRect.Height = base.InternalChildren[childIndex].DesiredSize.Height; } }