Can set scroll to item duration in ListView and derived classes (#15964)

* Can set scroll to item duration in ListView and derived classes (e.g. PageView)

* Parameter no more 'const'. Comments
This commit is contained in:
Drakon-Cocos 2016-06-29 03:48:03 +02:00 committed by minggo
parent 3bb9c75d66
commit 7302ad979a
2 changed files with 30 additions and 1 deletions

View File

@ -39,6 +39,7 @@ _gravity(Gravity::CENTER_VERTICAL),
_magneticType(MagneticType::NONE),
_magneticAllowedOutOfBoundary(true),
_itemsMargin(0.0f),
_scrollTime(DEFAULT_TIME_IN_SEC_FOR_SCROLL_TO_ITEM),
_curSelectedIndex(-1),
_innerContainerDoLayoutDirty(true),
_listViewEventListener(nullptr),
@ -440,6 +441,17 @@ float ListView::getItemsMargin()const
return _itemsMargin;
}
void ListView::setScrollDuration(float time)
{
if (time >= 0)
_scrollTime = time;
}
float ListView::getScrollDuration() const
{
return _scrollTime;
}
void ListView::setDirection(Direction dir)
{
switch (dir)
@ -775,7 +787,7 @@ void ListView::jumpToItem(ssize_t itemIndex, const Vec2& positionRatioInView, co
void ListView::scrollToItem(ssize_t itemIndex, const Vec2& positionRatioInView, const Vec2& itemAnchorPoint)
{
scrollToItem(itemIndex, positionRatioInView, itemAnchorPoint, DEFAULT_TIME_IN_SEC_FOR_SCROLL_TO_ITEM);
scrollToItem(itemIndex, positionRatioInView, itemAnchorPoint, _scrollTime);
}
void ListView::scrollToItem(ssize_t itemIndex, const Vec2& positionRatioInView, const Vec2& itemAnchorPoint, float timeInSec)

View File

@ -244,6 +244,21 @@ public:
*/
float getItemsMargin()const;
/**
* Set the time in seconds to scroll between items.
* Subsequent calls of function 'scrollToItem', will take 'time' seconds for scrolling.
* @param time The seconds needed to scroll between two items. 'time' must be >= 0
* @see scrollToItem(ssize_t, const Vec2&, const Vec2&)
*/
void setScrollDuration(float time);
/**
* Get the time in seconds to scroll between items.
* @return The time in seconds to scroll between items
* @see setScrollDuration(float)
*/
float getScrollDuration() const;
//override methods
virtual void doLayout() override;
virtual void requestDoLayout() override;
@ -427,6 +442,8 @@ protected:
float _itemsMargin;
float _scrollTime;
ssize_t _curSelectedIndex;
bool _innerContainerDoLayoutDirty;