void ScrollView::moveChildrenToPosition(const Vec2& position) { setInnerContainerPosition(position); Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO); updateScrollBar(outOfBoundary); }
void ScrollView::copySpecialProperties(Widget *widget) { ScrollView* scrollView = dynamic_cast<ScrollView*>(widget); if (scrollView) { Layout::copySpecialProperties(widget); setDirection(scrollView->_direction); setInnerContainerPosition(scrollView->getInnerContainerPosition()); setInnerContainerSize(scrollView->getInnerContainerSize()); _topBoundary = scrollView->_topBoundary; _bottomBoundary = scrollView->_bottomBoundary; _leftBoundary = scrollView->_leftBoundary; _rightBoundary = scrollView->_rightBoundary; _bePressed = scrollView->_bePressed; _childFocusCancelOffsetInInch = scrollView->_childFocusCancelOffsetInInch; setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled); _inertiaScrolling = scrollView->_inertiaScrolling; _inertiaInitiVelocity = scrollView->_inertiaInitiVelocity; _inertiaTouchDisplacements = scrollView->_inertiaTouchDisplacements; _inertiaTouchTimeDeltas = scrollView->_inertiaTouchTimeDeltas; _inertiaPrevTouchTimestamp = scrollView->_inertiaPrevTouchTimestamp; _inertiaScrollExpectedTime = scrollView->_inertiaScrollExpectedTime; _inertiaScrollElapsedTime = scrollView->_inertiaScrollElapsedTime; _autoScrolling = scrollView->_autoScrolling; _autoScrollAttenuate = scrollView->_autoScrollAttenuate; _autoScrollStartPosition = scrollView->_autoScrollStartPosition; _autoScrollTargetDelta = scrollView->_autoScrollTargetDelta; _autoScrollDuration = scrollView->_autoScrollDuration; _autoScrollAccumulatedTime = scrollView->_autoScrollAccumulatedTime; setBounceEnabled(scrollView->_bounceEnabled); _bouncingBack = scrollView->_bouncingBack; _scrollViewEventListener = scrollView->_scrollViewEventListener; _scrollViewEventSelector = scrollView->_scrollViewEventSelector; _eventCallback = scrollView->_eventCallback; _ccEventCallback = scrollView->_ccEventCallback; setScrollBarEnabled(scrollView->isScrollBarEnabled()); if(isScrollBarEnabled()) { if(_direction != Direction::HORIZONTAL) { setScrollBarPositionFromCornerForVertical(scrollView->getScrollBarPositionFromCornerForVertical()); } if(_direction != Direction::VERTICAL) { setScrollBarPositionFromCornerForHorizontal(scrollView->getScrollBarPositionFromCornerForHorizontal()); } setScrollBarWidth(scrollView->getScrollBarWidth()); setScrollBarColor(scrollView->getScrollBarColor()); setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled()); setScrollBarAutoHideTime(scrollView->getScrollBarAutoHideTime()); } } }
void ScrollView::onSizeChanged() { Layout::onSizeChanged(); _topBoundary = _contentSize.height; _rightBoundary = _contentSize.width; Size innerSize = _innerContainer->getContentSize(); float orginInnerSizeWidth = innerSize.width; float orginInnerSizeHeight = innerSize.height; float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); setInnerContainerPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); }
void ScrollView::moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) { Vec2 adjustedMove = flattenVectorByDirection(deltaMove); setInnerContainerPosition(getInnerContainerPosition() + adjustedMove); Vec2 outOfBoundary = getHowMuchOutOfBoundary(); updateScrollBar(outOfBoundary); if(_bounceEnabled && canStartBounceBack) { startBounceBackIfNeeded(); } }
void ScrollView::setInnerContainerSize(const Size &size) { float innerSizeWidth = _contentSize.width; float innerSizeHeight = _contentSize.height; Size originalInnerSize = _innerContainer->getContentSize(); if (size.width < _contentSize.width) { CCLOG("Inner width <= scrollview width, it will be force sized!"); } else { innerSizeWidth = size.width; } if (size.height < _contentSize.height) { CCLOG("Inner height <= scrollview height, it will be force sized!"); } else { innerSizeHeight = size.height; } _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); // Calculate and set the position of the inner container. Vec2 pos = _innerContainer->getPosition(); if (_innerContainer->getLeftBoundary() > 0.0f) { pos.x = _innerContainer->getAnchorPoint().x * _innerContainer->getContentSize().width; } if (_innerContainer->getRightBoundary() < _contentSize.width) { pos.x = _contentSize.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getContentSize().width); } if (_innerContainer->getPosition().y > 0.0f) { pos.y = _innerContainer->getAnchorPoint().y * _innerContainer->getContentSize().height; } if (_innerContainer->getTopBoundary() < _contentSize.height) { pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height; } setInnerContainerPosition(pos); updateScrollBar(Vec2::ZERO); }
void ScrollView::onSizeChanged() { Layout::onSizeChanged(); _topBoundary = _contentSize.height; _rightBoundary = _contentSize.width; Size innerSize = _innerContainer->getContentSize(); float orginInnerSizeWidth = innerSize.width; float orginInnerSizeHeight = innerSize.height; float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); setInnerContainerPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); if (_verticalScrollBar != nullptr) _verticalScrollBar->onScrolled(getHowMuchOutOfBoundary()); if (_horizontalScrollBar != nullptr) _horizontalScrollBar->onScrolled(getHowMuchOutOfBoundary()); }