You.i Engine
YiScrollController.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_SCROLL_CONTROLLER_H_
3 #define _YI_SCROLL_CONTROLLER_H_
4 
6 #include "framework/YiPredef.h"
7 
8 class CYIInputInterpreter;
9 
16 {
18 
19  float delta;
20  float speed;
21  float eventPos;
22  int32_t pageBefore;
23  int32_t pageAfter;
25  bool reachedEnd;
26 };
27 
37 {
38 public:
44  {
45  public:
46  virtual ~ScrollListener() {}
50  virtual void OnScrollStarted(CYIScrollController * /*pControl*/){};
54  virtual void OnScrollEnded(CYIScrollController * /*pControl*/){};
60  virtual void OnScrollAuto(CYIScrollController * /*pControl*/){};
64  virtual void OnScrolled(CYIScrollController * /*pControl*/, YI_SCROLLED_INFO /*scrolledInfo*/){};
65  };
66 
75  {
76  public:
77  virtual ~OutOfRangeListener() {}
78 
82  virtual void OnOutOfRangeAtStart(CYIScrollController * /*pControl*/, float /*fOutOfRange*/, float /*fDelta*/){};
86  virtual void OnOutOfRangeAtEnd(CYIScrollController * /*pControl*/, float /*fOutOfRange*/, float /*fDelta*/){};
87 
91  virtual void OnOutOfRangeAtStartDirectionChanged(CYIScrollController * /*pControl*/, float /*fOutOfRange*/, float /*fDelta*/){};
95  virtual void OnOutOfRangeAtEndDirectionChanged(CYIScrollController * /*pControl*/, float /*fOutOfRange*/, float /*fDelta*/){};
99  virtual void OnOutOfRangeAtStartSnapBack(CYIScrollController * /*pControl*/, float /*fOutOfRange*/){};
103  virtual void OnOutOfRangeAtEndSnapBack(CYIScrollController * /*pControl*/, float /*fOutOfRange*/){};
107  virtual void OnOutOfRangeAtStartBegan(CYIScrollController * /*pControl*/, float /*fOutOfRange*/, float /*fDelta*/){};
111  virtual void OnOutOfRangeAtEndBegan(CYIScrollController * /*pControl*/, float /*fOutOfRange*/, float /*fDelta*/){};
115  virtual void OnOutOfRangeAtStartFinished(CYIScrollController * /*pControl*/){};
119  virtual void OnOutOfRangeAtEndFinished(CYIScrollController * /*pControl*/){};
120  };
121 
123  virtual ~CYIScrollController() override;
124 
128  void SetSnapBackDur(uint64_t snapBackDur);
132  uint64_t GetSnapBackDur() const;
133 
137  void SetFrictionCoeff(float frictionCoefficient);
141  void SetMaxVelocityCoeff(float maxVelocityCoefficient);
142 
146  void SetScrollListener(ScrollListener *pListener);
150  void SetOutOfRangeListener(OutOfRangeListener *pListener);
151 
156  void GetDataRange(float *pStart, float *pSize) const;
161  void SetDataRange(float dataStart, float dataSize, bool animate = true);
166  void SetMagnetRules(bool snapBack, float snapBackStart, float snapBackEnd, float maxOutOfRangeStart, float maxOutOfRangeEnd);
167 
173  void SetCarousel(bool carousel);
174 
180  void MoveBy(float delta, float eventPos = 0, bool allowOutOfRange = false, bool notifyListener = true, bool skipIfAnimation = false);
181 
189  void MoveByAnimate(float delta, uint64_t dur, CYITimeInterpolator *pInterpolator = nullptr, bool allowOutOfRange = true);
190 
194  void UpdateMoveByAnimateDelta(float delta);
195 
204  void MoveToPercentage(float percentage, bool notifyListener = true);
214  void MoveToPercentageAnimate(float percentage, uint64_t dur, CYITimeInterpolator *pInterpolator = nullptr);
218  void StopScrolling();
222  bool IsScrolling() const;
226  float GetPctPos() const;
230  int64_t GetCurrentVelocity() const;
236  void GetCurrentWindowPos(float *pStart, float *pEnd) const;
242  float GetDataStart() const;
243 
247  float GetScrollStartPos() const;
253  void Reset();
254 
264  void SetPageSize(float pageSize, bool alwaysCenterOnPage = false, bool swipeToNextPage = false);
270  float GetPageSize() const;
276  bool GetAlwaysCenterOnPage() const;
282  int32_t GetCurPage() const;
289  size_t GetPageCount() const;
295  float CalculatePageOffset(int32_t page) const;
301  float CalculateOffsetToNearestPage(float moveBy) const;
302 
306  float CalculateCenterOffset() const;
307 
317  virtual float CalculateSnapBackOffset() const;
318 
322  void GestureStart(float pos, uint64_t eventTimeMs);
326  void GestureMove(float pos, uint64_t eventTimeMs);
330  void GestureEnd(float pos, uint64_t eventTimeMs);
331 
337  void SetDecelerationDuration(uint32_t durationMs);
338 
344  virtual uint32_t GetDecelerationDuration() const;
345 
349  float GetScrollDelta() const;
350 
354  float GetCompletedScrollDelta() const;
355 
356 protected:
363  virtual bool AdjustMoveBy(float *pMoveBy, const float &dataEnd) const;
367  virtual bool AdjustMoveByNoOutOfRange(float *pMoveBy) const;
373  virtual bool AdjustMoveByNoOutOfRangeDuringDecelerate(float *pMoveBy, int32_t dir);
374 
378  void AnimateMoveBy(float delta, uint64_t dur, bool canCancel, CYITimeInterpolator *pInterpolator = nullptr);
382  void Decelerate();
388  void FinishMoveBy();
394  bool SnapBack(bool animate = true);
395 
399  virtual void OnAnimate(CYIAnimation *pAnim, float dataPosition) override;
403  virtual void OnAnimationBegin(CYIAnimation *pAnim) override;
404 
408  virtual void OnAnimationEnd(CYIAnimation *pAnim) override;
409 
414  void StartScroll(bool alreadyScrolling);
418  void EndScroll();
422  void AutoScroll();
423 
429  float GetDataEnd() const;
430 
436  bool IsOutOfRange(float offset = 0.0f) const;
437 
441  float CalculateSnapBackOffset(float dataStart) const;
442 
443  float m_dataStart;
444  float m_dataSize;
447 
450 
452 
460  float m_pageSize;
462 
463  uint64_t m_snapBackDur;
466 
470 
471  std::unique_ptr<CYIAnimation> m_pMoveByAnim;
476 
479 
480  std::unique_ptr<CYIInputInterpreter> m_pGestureData;
481 
482 private:
484 };
485 
488 #endif // _YI_SCROLL_CONTROLLER_H_
float m_pageSize
Definition: YiScrollController.h:460
float m_anticipatedDataStart
Definition: YiScrollController.h:445
std::unique_ptr< CYIAnimation > m_pMoveByAnim
Definition: YiScrollController.h:471
Container for basic interpolator functions.
Definition: YiTimeInterpolator.h:20
virtual ~OutOfRangeListener()
Definition: YiScrollController.h:77
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:122
virtual void OnOutOfRangeAtStartSnapBack(CYIScrollController *, float)
Definition: YiScrollController.h:99
int32_t pageBefore
Definition: YiScrollController.h:22
virtual void OnOutOfRangeAtStart(CYIScrollController *, float, float)
Definition: YiScrollController.h:82
std::unique_ptr< CYIInputInterpreter > m_pGestureData
Definition: YiScrollController.h:480
uint32_t m_decelerationDuration
Definition: YiScrollController.h:465
virtual void OnOutOfRangeAtEndFinished(CYIScrollController *)
Definition: YiScrollController.h:119
virtual void OnScrollStarted(CYIScrollController *)
Definition: YiScrollController.h:50
bool m_snapBack
Definition: YiScrollController.h:455
bool m_gestureStarted
Definition: YiScrollController.h:467
virtual void OnOutOfRangeAtEndSnapBack(CYIScrollController *, float)
Definition: YiScrollController.h:103
virtual void OnScrolled(CYIScrollController *, YI_SCROLLED_INFO)
Definition: YiScrollController.h:64
virtual void OnOutOfRangeAtStartDirectionChanged(CYIScrollController *, float, float)
Definition: YiScrollController.h:91
virtual void OnOutOfRangeAtEnd(CYIScrollController *, float, float)
Definition: YiScrollController.h:86
virtual void OnOutOfRangeAtEndDirectionChanged(CYIScrollController *, float, float)
Definition: YiScrollController.h:95
OutOfRangeListener * m_pOutOfRangeListener
Definition: YiScrollController.h:478
float m_gestureEndPos
Definition: YiScrollController.h:469
float m_scrollStartPos
Definition: YiScrollController.h:448
int32_t m_outOfRangeDirection
Definition: YiScrollController.h:451
bool m_allowOutOfRangeOnAnimateMoveBy
Definition: YiScrollController.h:475
int32_t pageAfter
Definition: YiScrollController.h:23
bool m_moveByCanCancel
Definition: YiScrollController.h:474
Definition: YiScrollController.h:15
float m_dataStart
Definition: YiScrollController.h:443
CYIScrollController provides scrolling behaviour to views.
Definition: YiScrollController.h:36
float m_frictionCoeff
Definition: YiScrollController.h:464
virtual void OnOutOfRangeAtStartBegan(CYIScrollController *, float, float)
Definition: YiScrollController.h:107
float speed
Definition: YiScrollController.h:20
float m_snapBackStart
Definition: YiScrollController.h:456
int32_t m_pageAtGestureStart
Definition: YiScrollController.h:468
bool m_swipeToNextPage
Definition: YiScrollController.h:454
virtual void OnOutOfRangeAtEndBegan(CYIScrollController *, float, float)
Definition: YiScrollController.h:111
float m_maxOutOfRangeEnd
Definition: YiScrollController.h:459
virtual void OnOutOfRangeAtStartFinished(CYIScrollController *)
Definition: YiScrollController.h:115
float m_anticipatedDataEnd
Definition: YiScrollController.h:446
bool m_alwaysCenterOnPage
Definition: YiScrollController.h:453
Definition: YiScrollController.h:43
virtual void OnScrollEnded(CYIScrollController *)
Definition: YiScrollController.h:54
float delta
Definition: YiScrollController.h:19
virtual ~ScrollListener()
Definition: YiScrollController.h:46
float m_moveByDone
Definition: YiScrollController.h:473
bool m_carousel
Definition: YiScrollController.h:461
float m_moveByTarget
Definition: YiScrollController.h:472
float eventPos
Definition: YiScrollController.h:21
virtual void OnScrollAuto(CYIScrollController *)
Definition: YiScrollController.h:60
float m_dataSize
Definition: YiScrollController.h:444
Used to create animations programatically.
Definition: YiAnimation.h:31
float m_snapBackEnd
Definition: YiScrollController.h:457
uint64_t m_snapBackDur
Definition: YiScrollController.h:463
Provides a means of being notified when a scroll controller is outside of the snap back range...
Definition: YiScrollController.h:74
Base class used to listen to one or more CYIAnimations as they update over time.
Definition: YiAnimation.h:61
float m_maxOutOfRangeStart
Definition: YiScrollController.h:458
bool reachedStart
Definition: YiScrollController.h:24
ScrollListener * m_pScrollListener
Definition: YiScrollController.h:477
bool m_isScrolling
Definition: YiScrollController.h:449
bool reachedEnd
Definition: YiScrollController.h:25