2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
*PageView page turn event type.
|
2015-03-26 15:47:14 +08:00
|
|
|
*@deprecated Use `PageView::EventType` instead.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef enum
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
PAGEVIEW_EVENT_TURNING,
|
|
|
|
}PageViewEventType;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*A callback which would be called when a PageView turning event is happening.
|
2015-03-26 15:47:14 +08:00
|
|
|
*@deprecated Use `PageView::ccPageViewCallback` instead.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef void (Ref::*SEL_PageViewEvent)(Ref*, PageViewEventType);
|
2014-03-11 17:13:54 +08:00
|
|
|
#define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR)
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Page turn event tpye.
|
|
|
|
*/
|
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-03-25 18:17:58 +08:00
|
|
|
* Add a widget as a page of PageView in a given index.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param widget Widget to be added to pageview.
|
|
|
|
* @param pageIdx A given index.
|
|
|
|
* @param forceCreate If `forceCreate` is true and `widget` isn't exists, pageview would create a default page and add it.
|
2015-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::insertCustomItem(Widget* item, ssize_t index)` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-09-16 17:59:56 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addWidgetToPage(Widget* widget, ssize_t pageIdx, bool forceCreate);
|
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.
|
2015-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::pushBackCustomItem(Widget* item)` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-09-16 17:59:56 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addPage(Layout* 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.
|
2015-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::insertCustomItem(Widget* item, ssize_t index)` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-09-16 17:59:56 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void insertPage(Layout* 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-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::removeItem(getIndex(item))` instead.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void removePage(Layout* 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-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::removeItem(ssize_t index)` instead.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE 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-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::removeAllItems()` instead.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE 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-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `ListView::scrollToItem(ssize_t itemIndex, Vec2::ANCHOR_MIDDLE, Vec2::ANCHOR_MIDDLE)` instead.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void scrollToPage(ssize_t idx);
|
2015-07-15 17:02:02 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Gets current displayed page index.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return current page index.
|
2015-09-21 20:46:10 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is deprecated. Use `getCurrentPageIndex()` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-09-21 20:46:10 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE ssize_t getCurPageIndex() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets current displayed page index.
|
|
|
|
* @return current page index.
|
|
|
|
*/
|
|
|
|
ssize_t getCurrentPageIndex() const { return _currentPageIndex; }
|
2015-07-15 17:02:02 +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.
|
2015-09-16 17:59:56 +08:00
|
|
|
*
|
2015-09-21 20:46:10 +08:00
|
|
|
* Since v3.9, this is deprecated. Use `setCurrentPageIndex()` instead.
|
2015-09-16 17:59:56 +08:00
|
|
|
*/
|
2015-09-21 20:46:10 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void setCurPageIndex(ssize_t index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 Get all the pages in the PageView.
|
2015-10-23 15:37:33 +08:00
|
|
|
* @return A vector of Layout pointers.
|
2015-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is obsolete. Use `Vector<Widget*>& ListView::getItems()` instead.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE Vector<Layout*>& getPages();
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Get a page at a given index
|
|
|
|
*
|
|
|
|
* @param index A given index.
|
|
|
|
* @return A layout pointer in PageView container.
|
2015-09-16 17:59:56 +08:00
|
|
|
*
|
|
|
|
* Since v3.9, this is obsolete. Use `Widget* ListView::getItem(index)` instead.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE Layout* getPage(ssize_t index);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Add a page turn callback to PageView, then when one page is turning, the callback will be called.
|
2015-03-26 15:47:14 +08:00
|
|
|
*@deprecated Use `PageView::addEventListener` instead.
|
2015-03-25 18:17:58 +08:00
|
|
|
*@param target A pointer of `Ref*` type.
|
|
|
|
*@param selector A member function pointer with signature of `SEL_PageViewEvent`.
|
|
|
|
*/
|
2014-05-12 10:31:52 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addEventListenerPageView(Ref *target, SEL_PageViewEvent selector);
|
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.
|
|
|
|
*/
|
2014-05-14 16:14:28 +08:00
|
|
|
void addEventListener(const ccPageViewCallback& callback);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
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-09-21 21:03:05 +08:00
|
|
|
|
|
|
|
void setIndicatorPositionAsAnchorPoint(const Vec2& positionAsAnchorPoint);
|
|
|
|
const Vec2& getIndicatorPositionAsAnchorPoint() const;
|
|
|
|
|
|
|
|
void setIndicatorPosition(const Vec2& position);
|
|
|
|
const Vec2& getIndicatorPosition() const;
|
|
|
|
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*@brief If you don't specify the value, the pageView will turn page when scrolling at the half width of a page.
|
|
|
|
*@param threshold A threshold in float.
|
2014-08-14 11:14:24 +08:00
|
|
|
*/
|
|
|
|
void setCustomScrollThreshold(float threshold);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-08-14 11:14:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
*@brief Query the custom scroll threshold of the PageView.
|
|
|
|
*@return Custom scroll threshold in float.
|
2014-08-14 11:14:24 +08:00
|
|
|
*/
|
|
|
|
float getCustomScrollThreshold()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-08-14 11:14:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
*@brief Set using user defined scroll page threshold or not.
|
2014-08-14 11:14:24 +08:00
|
|
|
* If you set it to false, then the default scroll threshold is pageView.width / 2
|
2015-03-25 18:17:58 +08:00
|
|
|
*@param flag True if using custom scroll threshold, false otherwise.
|
2014-08-14 11:14:24 +08:00
|
|
|
*/
|
|
|
|
void setUsingCustomScrollThreshold(bool flag);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-08-14 11:14:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
*@brief Query whether use user defined scroll page threshold or not.
|
|
|
|
*@return True if using custom scroll threshold, false otherwise.
|
2014-08-14 11:14:24 +08:00
|
|
|
*/
|
|
|
|
bool isUsingCustomScrollThreshold()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
virtual bool init() override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
void pageTurningEvent();
|
2014-05-21 15:44:08 +08:00
|
|
|
|
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;
|
|
|
|
|
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-08-14 11:14:24 +08:00
|
|
|
float _customScrollThreshold;
|
2014-08-14 14:36:30 +08:00
|
|
|
bool _usingCustomScrollThreshold;
|
2014-08-14 11:14:24 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
float _childFocusCancelOffset;
|
2014-05-12 10:31:52 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
Ref* _pageViewEventListener;
|
2014-05-12 10:31:52 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
2014-03-11 17:13:54 +08:00
|
|
|
SEL_PageViewEvent _pageViewEventSelector;
|
2014-05-12 10:31:52 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
ccPageViewCallback _eventCallback;
|
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__) */
|