mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14940 from mxenabled/stop_auto_scroll
Add ability to stop auto scrolling in ui::ScrollView and extension::ScrollView
This commit is contained in:
commit
ee31d2ad22
|
@ -469,6 +469,14 @@ void ScrollView::startAutoScroll(const Vec2& deltaMove, float timeInSec, bool at
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScrollView::stopAutoScroll()
|
||||||
|
{
|
||||||
|
_autoScrolling = false;
|
||||||
|
_autoScrollAttenuate = true;
|
||||||
|
_autoScrollTotalTime = 0;
|
||||||
|
_autoScrollAccumulatedTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool ScrollView::isNecessaryAutoScrollBrake()
|
bool ScrollView::isNecessaryAutoScrollBrake()
|
||||||
{
|
{
|
||||||
if(_autoScrollBraking)
|
if(_autoScrollBraking)
|
||||||
|
|
|
@ -156,61 +156,66 @@ public:
|
||||||
*/
|
*/
|
||||||
Layout* getInnerContainer()const;
|
Layout* getInnerContainer()const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immediately stops inner container scroll initiated by any of the "scrollTo*" member functions
|
||||||
|
*/
|
||||||
|
virtual void stopAutoScroll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to bottom boundary of scrollview.
|
* Scroll inner container to bottom boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToBottom(float timeInSec, bool attenuated);
|
virtual void scrollToBottom(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to top boundary of scrollview.
|
* Scroll inner container to top boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToTop(float timeInSec, bool attenuated);
|
virtual void scrollToTop(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to left boundary of scrollview.
|
* Scroll inner container to left boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToLeft(float timeInSec, bool attenuated);
|
virtual void scrollToLeft(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to right boundary of scrollview.
|
* Scroll inner container to right boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToRight(float timeInSec, bool attenuated);
|
virtual void scrollToRight(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to top and left boundary of scrollview.
|
* Scroll inner container to top and left boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToTopLeft(float timeInSec, bool attenuated);
|
virtual void scrollToTopLeft(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to top and right boundary of scrollview.
|
* Scroll inner container to top and right boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToTopRight(float timeInSec, bool attenuated);
|
virtual void scrollToTopRight(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to bottom and left boundary of scrollview.
|
* Scroll inner container to bottom and left boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToBottomLeft(float timeInSec, bool attenuated);
|
virtual void scrollToBottomLeft(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to bottom and right boundary of scrollview.
|
* Scroll inner container to bottom and right boundary of scrollview.
|
||||||
* @param timeInSec Time in seconds
|
* @param timeInSec Time in seconds
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToBottomRight(float timeInSec, bool attenuated);
|
virtual void scrollToBottomRight(float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to vertical percent position of scrollview.
|
* Scroll inner container to vertical percent position of scrollview.
|
||||||
|
@ -218,7 +223,7 @@ public:
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToPercentVertical(float percent, float timeInSec, bool attenuated);
|
virtual void scrollToPercentVertical(float percent, float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to horizontal percent position of scrollview.
|
* Scroll inner container to horizontal percent position of scrollview.
|
||||||
|
@ -226,7 +231,7 @@ public:
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToPercentHorizontal(float percent, float timeInSec, bool attenuated);
|
virtual void scrollToPercentHorizontal(float percent, float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll inner container to both direction percent position of scrollview.
|
* Scroll inner container to both direction percent position of scrollview.
|
||||||
|
@ -234,7 +239,7 @@ public:
|
||||||
* @param timeInSec Time in seconds.
|
* @param timeInSec Time in seconds.
|
||||||
* @param attenuated Whether scroll speed attenuate or not.
|
* @param attenuated Whether scroll speed attenuate or not.
|
||||||
*/
|
*/
|
||||||
void scrollToPercentBothDirection(const Vec2& percent, float timeInSec, bool attenuated);
|
virtual void scrollToPercentBothDirection(const Vec2& percent, float timeInSec, bool attenuated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move inner container to bottom boundary of scrollview.
|
* Move inner container to bottom boundary of scrollview.
|
||||||
|
|
|
@ -64,6 +64,7 @@ ScrollView::ScrollView()
|
||||||
, _maxScale(0.0f)
|
, _maxScale(0.0f)
|
||||||
, _scissorRestored(false)
|
, _scissorRestored(false)
|
||||||
, _touchListener(nullptr)
|
, _touchListener(nullptr)
|
||||||
|
, _animatedScrollAction(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -234,12 +235,21 @@ void ScrollView::setContentOffsetInDuration(Vec2 offset, float dt)
|
||||||
{
|
{
|
||||||
FiniteTimeAction *scroll, *expire;
|
FiniteTimeAction *scroll, *expire;
|
||||||
|
|
||||||
|
if (_animatedScrollAction) {
|
||||||
|
stopAnimatedContentOffset();
|
||||||
|
}
|
||||||
scroll = MoveTo::create(dt, offset);
|
scroll = MoveTo::create(dt, offset);
|
||||||
expire = CallFuncN::create(CC_CALLBACK_1(ScrollView::stoppedAnimatedScroll,this));
|
expire = CallFuncN::create(CC_CALLBACK_1(ScrollView::stoppedAnimatedScroll,this));
|
||||||
_container->runAction(Sequence::create(scroll, expire, nullptr));
|
_animatedScrollAction = _container->runAction(Sequence::create(scroll, expire, nullptr));
|
||||||
this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::performedAnimatedScroll));
|
this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::performedAnimatedScroll));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScrollView::stopAnimatedContentOffset() {
|
||||||
|
stopAction(_animatedScrollAction);
|
||||||
|
_animatedScrollAction = nullptr;
|
||||||
|
stoppedAnimatedScroll(this);
|
||||||
|
}
|
||||||
|
|
||||||
Vec2 ScrollView::getContentOffset()
|
Vec2 ScrollView::getContentOffset()
|
||||||
{
|
{
|
||||||
return _container->getPosition();
|
return _container->getPosition();
|
||||||
|
|
|
@ -128,6 +128,10 @@ public:
|
||||||
* @param dt The animation duration.
|
* @param dt The animation duration.
|
||||||
*/
|
*/
|
||||||
void setContentOffsetInDuration(Vec2 offset, float dt);
|
void setContentOffsetInDuration(Vec2 offset, float dt);
|
||||||
|
/**
|
||||||
|
* Halts the movement animation of the inner content started with setContentOffset() or setContentOffsetInDuration()
|
||||||
|
*/
|
||||||
|
void stopAnimatedContentOffset();
|
||||||
|
|
||||||
void setZoomScale(float s);
|
void setZoomScale(float s);
|
||||||
/**
|
/**
|
||||||
|
@ -378,6 +382,11 @@ protected:
|
||||||
|
|
||||||
CustomCommand _beforeDrawCommand;
|
CustomCommand _beforeDrawCommand;
|
||||||
CustomCommand _afterDrawCommand;
|
CustomCommand _afterDrawCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action created with setContentOffsetInDuration(), saved so it can be halted
|
||||||
|
*/
|
||||||
|
Action* _animatedScrollAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue