{
// Check next focused view is inside of visible area.
// If it is not, move scroll position to make it visible.
- Vector2 scrollPosition = ContentContainer.ScreenPosition;
- float targetPosition = -(ScrollingDirection == Direction.Horizontal ? scrollPosition.X : scrollPosition.Y);
-
float left = nextFocusedView.ScreenPosition.X;
float right = nextFocusedView.ScreenPosition.X + nextFocusedView.Size.Width;
float top = nextFocusedView.ScreenPosition.Y;
float bottom = nextFocusedView.ScreenPosition.Y + nextFocusedView.Size.Height;
- float visibleRectangleLeft = scrollPosition.X;
- float visibleRectangleRight = scrollPosition.X + Size.Width;
- float visibleRectangleTop = scrollPosition.Y;
- float visibleRectangleBottom = scrollPosition.Y + Size.Height;
+ float visibleRectangleLeft = ScreenPosition.X;
+ float visibleRectangleRight = ScreenPosition.X + Size.Width;
+ float visibleRectangleTop = ScreenPosition.Y;
+ float visibleRectangleBottom = ScreenPosition.Y + Size.Height;
if (ScrollingDirection == Direction.Horizontal)
{
if (left < visibleRectangleLeft)
{
- targetPosition = left - scrollPosition.X;
+ ScrollTo(left- ContentContainer.ScreenPosition.X, true);
}
else if (right > visibleRectangleRight)
{
- targetPosition = right - Size.Width - scrollPosition.X;
+ ScrollTo(right - Size.Width - ContentContainer.ScreenPosition.Y, true);
}
}
else
{
if (top < visibleRectangleTop)
{
- targetPosition = top - scrollPosition.Y;
+ ScrollTo(top - ContentContainer.ScreenPosition.Y, true);
}
else if (bottom > visibleRectangleBottom)
{
- targetPosition = bottom - Size.Height - scrollPosition.Y;
+ ScrollTo(bottom - Size.Height - ContentContainer.ScreenPosition.Y, true);
}
}
- ScrollTo(targetPosition, true);
}
}
return nextFocusedView;