123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- #ifndef __UIPAGEVIEW_H__
- #define __UIPAGEVIEW_H__
- #include "ui/UIListView.h"
- #include "ui/GUIExport.h"
- NS_CC_BEGIN
- namespace ui {
- class PageViewIndicator;
- typedef enum
- {
- PAGEVIEW_EVENT_TURNING,
- }PageViewEventType;
- typedef void (Ref::*SEL_PageViewEvent)(Ref*, PageViewEventType);
- #define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR)
- class CC_GUI_DLL PageView : public ListView
- {
-
- DECLARE_CLASS_GUI_INFO
-
- public:
-
- enum class EventType
- {
- TURNING
- };
-
-
- enum class TouchDirection
- {
- LEFT,
- RIGHT,
- UP,
- DOWN
- };
-
- typedef std::function<void(Ref*, EventType)> ccPageViewCallback;
-
- PageView();
-
-
- virtual ~PageView();
-
-
- static PageView* create();
-
- virtual void setDirection(Direction direction) override;
-
- CC_DEPRECATED_ATTRIBUTE void addWidgetToPage(Widget* widget, ssize_t pageIdx, bool forceCreate);
-
-
- void addPage(Widget* page);
-
- void insertPage(Widget* page, int idx);
-
- void removePage(Widget* page);
-
- void removePageAtIndex(ssize_t index);
-
- void removeAllPages();
-
-
- void scrollToPage(ssize_t idx);
-
-
- void scrollToPage(ssize_t idx, float time);
-
- void scrollToItem(ssize_t itemIndex);
-
-
- void scrollToItem(ssize_t idx, float time);
-
- CC_DEPRECATED_ATTRIBUTE ssize_t getCurPageIndex() const;
-
- ssize_t getCurrentPageIndex();
-
- CC_DEPRECATED_ATTRIBUTE void setCurPageIndex(ssize_t index);
-
- void setCurrentPageIndex(ssize_t index);
-
- CC_DEPRECATED_ATTRIBUTE Vector<Layout*>& getPages();
-
- CC_DEPRECATED_ATTRIBUTE Layout* getPage(ssize_t index);
-
-
- CC_DEPRECATED_ATTRIBUTE void addEventListenerPageView(Ref *target, SEL_PageViewEvent selector);
-
- void addEventListener(const ccPageViewCallback& callback);
- using ScrollView::addEventListener;
-
- virtual std::string getDescription() const override;
-
- void setIndicatorEnabled(bool enabled);
-
- bool getIndicatorEnabled() const { return _indicator != nullptr; }
-
- void setIndicatorPositionAsAnchorPoint(const Vec2& positionAsAnchorPoint);
-
- const Vec2& getIndicatorPositionAsAnchorPoint() const;
-
- void setIndicatorPosition(const Vec2& position);
-
-
- const Vec2& getIndicatorPosition() const;
-
- void setIndicatorSpaceBetweenIndexNodes(float spaceBetweenIndexNodes);
-
- float getIndicatorSpaceBetweenIndexNodes() const;
-
- void setIndicatorSelectedIndexColor(const Color3B& color);
-
- const Color3B& getIndicatorSelectedIndexColor() const;
-
- void setIndicatorIndexNodesColor(const Color3B& color);
-
-
- const Color3B& getIndicatorIndexNodesColor() const;
-
-
- void setIndicatorIndexNodesScale(float indexNodesScale);
-
-
- void setIndicatorIndexNodesTexture(const std::string& texName,Widget::TextureResType texType = Widget::TextureResType::LOCAL);
-
-
- float getIndicatorIndexNodesScale() const;
-
-
- CC_DEPRECATED_ATTRIBUTE void setCustomScrollThreshold(float threshold);
-
- CC_DEPRECATED_ATTRIBUTE float getCustomScrollThreshold()const;
-
- CC_DEPRECATED_ATTRIBUTE void setUsingCustomScrollThreshold(bool flag);
-
- CC_DEPRECATED_ATTRIBUTE bool isUsingCustomScrollThreshold()const;
- void setAutoScrollStopEpsilon(float epsilon);
- CC_CONSTRUCTOR_ACCESS:
- virtual bool init() override;
-
- virtual void doLayout() override;
- protected:
- void pageTurningEvent();
- virtual float getAutoScrollStopEpsilon() const override;
- virtual void remedyLayoutParameter(Widget* item)override;
- virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override;
- virtual void onItemListChanged() override;
- virtual void onSizeChanged() override;
- virtual void handleReleaseLogic(Touch *touch) override;
- virtual void handlePressLogic(Touch *touch) override;
- virtual Widget* createCloneInstance() override;
- virtual void copySpecialProperties(Widget* model) override;
- void refreshIndicatorPosition();
- protected:
- PageViewIndicator* _indicator;
- Vec2 _indicatorPositionAsAnchorPoint;
- ssize_t _currentPageIndex;
- float _childFocusCancelOffset;
- Ref* _pageViewEventListener;
- #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- #elif _MSC_VER >= 1400
- #pragma warning (push)
- #pragma warning (disable: 4996)
- #endif
- SEL_PageViewEvent _pageViewEventSelector;
- #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
- #pragma GCC diagnostic warning "-Wdeprecated-declarations"
- #elif _MSC_VER >= 1400
- #pragma warning (pop)
- #endif
- ccPageViewCallback _eventCallback;
- float _autoScrollStopEpsilon;
- ssize_t _previousPageIndex;
- bool _isTouchBegin;
- };
- }
- NS_CC_END
- #endif
|