2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIPAGEVIEW_H__
|
|
|
|
#define __UIPAGEVIEW_H__
|
|
|
|
|
2015-09-16 17:13:58 +08:00
|
|
|
#include "ui/UIListView.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_BEGIN
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2015-09-21 15:50:18 +08:00
|
|
|
class PageViewIndicator;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-08-01 18:18:46 +08:00
|
|
|
*@brief Layout manager that allows the user to flip left & right and up & down through pages of data.
|
2015-03-25 18:17:58 +08:00
|
|
|
*
|
|
|
|
*/
|
2015-09-16 17:13:58 +08:00
|
|
|
class CC_GUI_DLL PageView : public ListView
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-12-21 07:21:45 +08:00
|
|
|
* Page turn event type.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-05-12 10:31:52 +08:00
|
|
|
enum class EventType
|
|
|
|
{
|
|
|
|
TURNING
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Touch direction type.
|
|
|
|
*/
|
2014-05-12 10:31:52 +08:00
|
|
|
enum class TouchDirection
|
|
|
|
{
|
|
|
|
LEFT,
|
2015-08-01 18:18:46 +08:00
|
|
|
RIGHT,
|
|
|
|
UP,
|
|
|
|
DOWN
|
|
|
|
};
|
2015-09-16 17:13:58 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-09-16 17:13:58 +08:00
|
|
|
* PageView page turn event callback.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2015-09-16 17:59:56 +08:00
|
|
|
typedef std::function<void(Ref*, EventType)> ccPageViewCallback;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
|
|
|
* Default constructor
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
PageView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
2015-03-28 16:02:47 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual ~PageView();
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create an empty PageView.
|
|
|
|
*@return A PageView instance.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static PageView* create();
|
2015-09-21 21:12:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes direction
|
|
|
|
* Direction Direction::VERTICAL means vertical scroll, Direction::HORIZONTAL means horizontal scroll.
|
|
|
|
* @param direction Set the page view's scroll direction.
|
|
|
|
*/
|
|
|
|
virtual void setDirection(Direction direction) override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Insert a page into the end of PageView.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param page Page to be inserted.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-11-10 20:30:43 +08:00
|
|
|
void addPage(Widget* page);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Insert a page into PageView at a given index.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param page Page to be inserted.
|
|
|
|
* @param idx A given index.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-11-10 20:30:43 +08:00
|
|
|
void insertPage(Widget* page, int idx);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Remove a page of PageView.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param page Page to be removed.
|
2015-11-10 20:03:51 +08:00
|
|
|
*/
|
2015-11-10 20:30:43 +08:00
|
|
|
void removePage(Widget* page);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Remove a page at a given index of PageView.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param index A given index.
|
2015-11-10 20:03:51 +08:00
|
|
|
*/
|
2015-11-10 20:30:43 +08:00
|
|
|
void removePageAtIndex(ssize_t index);
|
2015-08-01 18:18:46 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Remove all pages of the PageView.
|
2015-11-10 20:03:51 +08:00
|
|
|
*/
|
2015-11-10 20:30:43 +08:00
|
|
|
void removeAllPages();
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Scroll to a page with a given index.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-07-15 17:02:02 +08:00
|
|
|
* @param idx A given index in the PageView. Index start from 0 to pageCount -1.
|
2015-11-10 20:03:51 +08:00
|
|
|
*/
|
2015-11-10 20:30:43 +08:00
|
|
|
void scrollToPage(ssize_t idx);
|
2016-08-25 15:48:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll to a page with a given index and with a given scroll time.
|
|
|
|
*
|
|
|
|
* @param idx A given index in the PageView. Index start from 0 to pageCount -1.
|
2016-09-06 10:14:14 +08:00
|
|
|
* @param time Scroll time must be >= 0. Otherwise last set scroll time will be used.
|
2016-08-25 15:48:01 +08:00
|
|
|
*/
|
|
|
|
void scrollToPage(ssize_t idx, float time);
|
2015-07-15 17:02:02 +08:00
|
|
|
|
2015-10-28 15:54:39 +08:00
|
|
|
/**
|
|
|
|
* Scroll to a page with a given index.
|
|
|
|
*
|
2016-07-03 23:42:10 +08:00
|
|
|
* @param itemIndex A given index in the PageView. Index start from 0 to pageCount -1.
|
2015-10-28 15:54:39 +08:00
|
|
|
*/
|
|
|
|
void scrollToItem(ssize_t itemIndex);
|
2016-08-25 15:48:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll to a item with a given index and with a given scroll time.
|
|
|
|
*
|
|
|
|
* @param idx A given index in the PageView. Index start from 0 to pageCount -1.
|
2016-09-06 10:14:14 +08:00
|
|
|
* @param time Scroll time must be >= 0. Otherwise last set scrolltime will be used.
|
2016-08-25 15:48:01 +08:00
|
|
|
*/
|
|
|
|
void scrollToItem(ssize_t idx, float time);
|
2015-10-28 15:54:39 +08:00
|
|
|
|
2015-09-21 20:46:10 +08:00
|
|
|
/**
|
|
|
|
* Gets current displayed page index.
|
|
|
|
* @return current page index.
|
|
|
|
*/
|
2017-02-14 10:24:55 +08:00
|
|
|
ssize_t getCurrentPageIndex();
|
2015-07-15 17:02:02 +08:00
|
|
|
|
2015-09-21 20:46:10 +08:00
|
|
|
/**
|
|
|
|
* Jump to a page with a given index without scrolling.
|
|
|
|
* This is the different between scrollToPage.
|
|
|
|
*
|
|
|
|
* @param index A given index in PageView. Index start from 0 to pageCount -1.
|
|
|
|
*/
|
|
|
|
void setCurrentPageIndex(ssize_t index);
|
2015-09-16 17:59:56 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Add a page turn callback to PageView, then when one page is turning, the callback will be called.
|
|
|
|
*
|
|
|
|
* @param callback A page turning callback.
|
|
|
|
*/
|
2016-01-25 14:48:17 +08:00
|
|
|
void addEventListener(const ccPageViewCallback& callback);
|
2016-01-25 11:53:40 +08:00
|
|
|
using ScrollView::addEventListener;
|
2015-03-25 18:17:58 +08:00
|
|
|
//override methods
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2015-10-28 15:06:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Toggle page indicator enabled.
|
|
|
|
*
|
|
|
|
* @param enabled True if enable page indicator, false otherwise.
|
|
|
|
*/
|
2015-09-21 21:12:25 +08:00
|
|
|
void setIndicatorEnabled(bool enabled);
|
|
|
|
|
2015-10-28 15:06:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Query page indicator state.
|
|
|
|
*
|
|
|
|
* @return True if page indicator is enabled, false otherwise.
|
|
|
|
*/
|
2015-10-28 15:34:30 +08:00
|
|
|
bool getIndicatorEnabled() const { return _indicator != nullptr; }
|
2015-09-21 21:03:05 +08:00
|
|
|
|
2015-10-28 15:06:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the page indicator's position using anchor point.
|
|
|
|
*
|
|
|
|
* @param positionAsAnchorPoint The position as anchor point.
|
|
|
|
*/
|
2015-09-21 21:03:05 +08:00
|
|
|
void setIndicatorPositionAsAnchorPoint(const Vec2& positionAsAnchorPoint);
|
2015-10-28 15:06:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the page indicator's position as anchor point.
|
|
|
|
*
|
|
|
|
* @return positionAsAnchorPoint
|
|
|
|
*/
|
2015-09-21 21:03:05 +08:00
|
|
|
const Vec2& getIndicatorPositionAsAnchorPoint() const;
|
|
|
|
|
2015-10-28 15:06:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the page indicator's position in page view.
|
|
|
|
*
|
|
|
|
* @param position The position in page view
|
|
|
|
*/
|
2015-09-21 21:03:05 +08:00
|
|
|
void setIndicatorPosition(const Vec2& position);
|
2015-10-28 15:06:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the page indicator's position.
|
|
|
|
*
|
|
|
|
* @return positionAsAnchorPoint
|
|
|
|
*/
|
2015-09-21 21:03:05 +08:00
|
|
|
const Vec2& getIndicatorPosition() const;
|
|
|
|
|
2015-10-28 15:06:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Set space between page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @param spaceBetweenIndexNodes Space between nodes in pixel.
|
|
|
|
*/
|
2015-09-22 10:06:18 +08:00
|
|
|
void setIndicatorSpaceBetweenIndexNodes(float spaceBetweenIndexNodes);
|
2015-10-28 15:06:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the space between page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @return spaceBetweenIndexNodes
|
|
|
|
*/
|
2015-09-22 10:06:18 +08:00
|
|
|
float getIndicatorSpaceBetweenIndexNodes() const;
|
2015-09-21 21:03:05 +08:00
|
|
|
|
2015-10-28 15:06:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Set color of page indicator's selected index.
|
|
|
|
*
|
2017-07-17 15:55:43 +08:00
|
|
|
* @param color New color for selected (current) index.
|
2015-10-28 15:06:53 +08:00
|
|
|
*/
|
2015-09-22 10:06:18 +08:00
|
|
|
void setIndicatorSelectedIndexColor(const Color3B& color);
|
2015-10-28 15:06:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the color of page indicator's selected index.
|
|
|
|
*
|
|
|
|
* @return color
|
|
|
|
*/
|
2015-09-22 10:06:18 +08:00
|
|
|
const Color3B& getIndicatorSelectedIndexColor() const;
|
|
|
|
|
2016-04-11 17:28:47 +08:00
|
|
|
/**
|
|
|
|
* @brief Set color of page indicator's index nodes.
|
|
|
|
*
|
2017-07-17 15:55:43 +08:00
|
|
|
* @param color New indicator node color.
|
2016-04-11 17:28:47 +08:00
|
|
|
*/
|
|
|
|
void setIndicatorIndexNodesColor(const Color3B& color);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the color of page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @return color
|
|
|
|
*/
|
|
|
|
const Color3B& getIndicatorIndexNodesColor() const;
|
|
|
|
|
2017-07-17 15:55:43 +08:00
|
|
|
/**
|
|
|
|
* @brief Set opacity of page indicator's selected index.
|
|
|
|
*
|
|
|
|
* @param color New opacity for selected (current) index.
|
|
|
|
*/
|
|
|
|
void setIndicatorSelectedIndexOpacity(GLubyte opacity);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the opacity of page indicator's selected index.
|
|
|
|
*
|
|
|
|
* @return opacity
|
|
|
|
*/
|
|
|
|
GLubyte getIndicatorSelectedIndexOpacity() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set opacity of page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @param opacity New indicator node opacity.
|
|
|
|
*/
|
|
|
|
void setIndicatorIndexNodesOpacity(GLubyte opacity);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the opacity of page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @return opacity
|
|
|
|
*/
|
|
|
|
GLubyte getIndicatorIndexNodesOpacity() const;
|
|
|
|
|
2016-04-11 17:28:47 +08:00
|
|
|
/**
|
|
|
|
* @brief Set scale of page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @param indexNodesScale Scale of index nodes.
|
|
|
|
*/
|
|
|
|
void setIndicatorIndexNodesScale(float indexNodesScale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets texture for index nodes.
|
|
|
|
*
|
|
|
|
* @param fileName File name of texture.
|
|
|
|
* @param resType @see TextureResType .
|
|
|
|
*/
|
|
|
|
void setIndicatorIndexNodesTexture(const std::string& texName,Widget::TextureResType texType = Widget::TextureResType::LOCAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get scale of page indicator's index nodes.
|
|
|
|
*
|
|
|
|
* @return indexNodesScale
|
|
|
|
*/
|
|
|
|
float getIndicatorIndexNodesScale() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2016-04-08 03:08:02 +08:00
|
|
|
void setAutoScrollStopEpsilon(float epsilon);
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
virtual bool init() override;
|
|
|
|
|
2015-11-15 21:48:42 +08:00
|
|
|
//override methods
|
|
|
|
virtual void doLayout() override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
void pageTurningEvent();
|
2016-03-09 19:08:18 +08:00
|
|
|
virtual float getAutoScrollStopEpsilon() const override;
|
2014-05-21 15:44:08 +08:00
|
|
|
|
2015-12-14 15:29:02 +08:00
|
|
|
virtual void remedyLayoutParameter(Widget* item)override;
|
2015-09-21 20:46:10 +08:00
|
|
|
virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override;
|
2015-09-21 18:40:30 +08:00
|
|
|
virtual void onItemListChanged() override;
|
2015-09-21 15:50:18 +08:00
|
|
|
virtual void onSizeChanged() override;
|
2015-09-16 17:59:56 +08:00
|
|
|
virtual void handleReleaseLogic(Touch *touch) override;
|
2016-08-04 09:51:54 +08:00
|
|
|
virtual void handlePressLogic(Touch *touch) override;
|
2015-09-16 17:59:56 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2014-05-21 15:44:08 +08:00
|
|
|
|
2015-09-21 21:03:05 +08:00
|
|
|
void refreshIndicatorPosition();
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2015-09-21 15:50:18 +08:00
|
|
|
PageViewIndicator* _indicator;
|
2015-09-21 21:03:05 +08:00
|
|
|
Vec2 _indicatorPositionAsAnchorPoint;
|
2015-09-21 15:50:18 +08:00
|
|
|
|
2015-09-21 20:46:10 +08:00
|
|
|
ssize_t _currentPageIndex;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
float _childFocusCancelOffset;
|
2014-05-12 10:31:52 +08:00
|
|
|
|
|
|
|
ccPageViewCallback _eventCallback;
|
2016-04-08 03:08:02 +08:00
|
|
|
float _autoScrollStopEpsilon;
|
2016-08-04 09:51:54 +08:00
|
|
|
ssize_t _previousPageIndex;
|
2016-08-05 09:43:15 +08:00
|
|
|
bool _isTouchBegin;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_END
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
#endif /* defined(__PageView__) */
|