ZFFramework
 
Loading...
Searching...
No Matches
ZFUIScrollView.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFUIScrollView_h_
7#define _ZFI_ZFUIScrollView_h_
8
9#include "ZFUIView.h"
11
17 ZFENUM_VALUE(Dragging)
18 ZFENUM_VALUE(Scrolling)
21 ZFENUM_VALUE_REGISTER(Dragging)
22 ZFENUM_VALUE_REGISTER(Scrolling)
25
26zfclassFwd _ZFP_ZFUIScrollViewPrivate;
27// ============================================================
28// ZFUIScrollView
35zfclass ZFLIB_ZFUIKit ZFUIScrollView : zfextend ZFUIView {
36 ZFOBJECT_DECLARE(ZFUIScrollView, ZFUIView)
38
39public:
40 // ============================================================
41 // event
47 ZFEVENT(ScrollOnDragBegin)
53 ZFEVENT(ScrollOnDrag)
59 ZFEVENT(ScrollOnDragEnd)
65 ZFEVENT(ScrollOnScrollBegin)
71 ZFEVENT(ScrollOnScroll)
77 ZFEVENT(ScrollOnScrollEnd)
83 ZFEVENT(ScrollAreaOnUpdate)
89 ZFEVENT(ScrollContentFrameOnUpdate)
95 ZFEVENT(ScrollAutoScrollOnStart)
101 ZFEVENT(ScrollAutoScrollOnStop)
114 ZFEVENT(ScrollOnScrolledByUser)
115
116public:
117 // ============================================================
118 // properties
124
145
168
182 zffinal void _ZFP_ZFUIScrollView_scrollContentFrameByImpl(ZF_IN const ZFUIRect &rect);
183
184protected:
186 virtual void objectOnInit(void);
188 virtual void objectOnDealloc(void);
190 virtual void objectOnDeallocPrepare(void);
191
192protected:
195
196 // ============================================================
197 // override ZFUIView
198protected:
200 virtual void implChildOnAdd(
201 ZF_IN ZFUIView *child
202 , ZF_IN zfindex virtualIndex
203 , ZF_IN ZFUIViewChildLayer childLayer
204 , ZF_IN zfindex childLayerIndex
205 );
207 virtual void implChildOnRemove(
208 ZF_IN ZFUIView *child
209 , ZF_IN zfindex virtualIndex
210 , ZF_IN ZFUIViewChildLayer childLayer
211 , ZF_IN zfindex childLayerIndex
212 );
215
216protected:
218 virtual void layoutOnLayoutPrepare(ZF_IN const ZFUIRect &bounds);
226 virtual void layoutOnLayout(ZF_IN const ZFUIRect &bounds);
228 virtual void layoutOnLayoutFinish(ZF_IN const ZFUIRect &bounds);
231 ret.x += this->scrollContentFrame().x;
232 ret.y += this->scrollContentFrame().y;
233 }
234
239 virtual void viewEventOnMouseEvent(ZF_IN ZFUIMouseEvent *mouseEvent);
241 virtual void viewEventOnWheelEvent(ZF_IN ZFUIWheelEvent *wheelEvent);
242
245
246 // ============================================================
247 // util methods
248public:
259 , ZFMP_IN(ZFUIView *, child)
260 , ZFMP_IN_OPT(const ZFUIMargin &, margin, ZFUIMarginCreate(ZFUIGlobalStyle::DefaultStyle()->itemMargin()))
261 , ZFMP_IN_OPT(zfbool, scrollWithAni, zftrue)
263
264 // ============================================================
265 // scroll area
266public:
271 , ZFMP_IN(const ZFUIMargin &, margin)
277 , ZFMP_IN(const ZFUIMargin &, margin)
288
289 // ============================================================
290 // scroll thumb
291public:
299 , ZFMP_IN(const ZFClass *, cls)
309 , ZFMP_IN(const ZFClass *, cls)
315protected:
319 virtual void scrollThumbHorizontalOnInit(void);
323 virtual void scrollThumbVerticalOnInit(void);
324
325 // ============================================================
326 // scroll control
327public:
336
337public:
350
351public:
371 , ZFMP_IN(zffloat, xPos)
372 , ZFMP_IN(zffloat, yPos)
382 , ZFMP_IN(zffloat, xSpeedInPixelsPerSecond)
383 , ZFMP_IN(zffloat, ySpeedInPixelsPerSecond)
398
403
404public:
415 , ZFMP_IN(zffloat, speedInPixelsPerSecond)
421 , ZFMP_IN(zffloat, speedInPixelsPerSecond)
439
440public:
445 , ZFMP_IN(const ZFUIPoint &, mousePos)
446 , ZFMP_IN(zftimet, mouseTime)
452 , ZFMP_IN(const ZFUIPoint &, mousePos)
453 , ZFMP_IN(zftimet, mouseTime)
459 , ZFMP_IN(zftimet, mouseTime)
460 , ZFMP_IN_OPT(zfbool, needScrollAni, zftrue)
462
463protected:
476
477 // ============================================================
478 // scroll status
479public:
484
485 // ============================================================
486 // scroll callbacks
487public:
488 zffinal void _ZFP_ZFUIScrollView_notifyDragBegin(
489 ZF_IN const ZFUIPoint &mousePos
490 , ZF_IN zftimet mouseTime
491 );
492 zffinal void _ZFP_ZFUIScrollView_notifyDrag(
493 ZF_IN const ZFUIPoint &mousePos
494 , ZF_IN zftimet mouseTime
495 );
496 zffinal void _ZFP_ZFUIScrollView_notifyDragEnd(
497 ZF_IN zftimet mouseTime
498 , ZF_IN zfbool needScrollAni
499 );
500 zffinal void _ZFP_ZFUIScrollView_notifyScrollAnimation(ZF_IN zftimet relativeTimeInMiliseconds);
501protected:
503 virtual inline void scrollOnDragBegin(void) {
505 }
506
507 virtual inline void scrollOnDrag(void) {
509 }
510
511 virtual inline void scrollOnDragEnd(void) {
513 }
514
515 virtual inline void scrollOnScrollBegin(void) {
517 }
518
519 virtual inline void scrollOnScroll(void) {
521 }
522
523 virtual inline void scrollOnScrollEnd(void) {
525 }
526
527 virtual inline void scrollAreaOnUpdate(void) {
529 }
530
534
538
542
546
547private:
548 _ZFP_ZFUIScrollViewPrivate *d;
549 friend zfclassFwd _ZFP_ZFUIScrollViewPrivate;
550};
551
553#endif // #ifndef _ZFI_ZFUIScrollView_h_
554
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
_zft_zftimet zftimet
time unit, ensured at least 64 bit, ensured signed
Definition ZFCoreTypeDef_CoreType.h:203
_zft_zffloat zffloat
same as float, see zfindex
Definition ZFCoreTypeDef_CoreType.h:183
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFENUM_SEPARATOR()
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:158
#define ZFENUM_VALUE_REGISTER(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:168
#define ZFENUM_REG(ZFLIB_, EnumName,...)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:186
#define ZFENUM_VALUE(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:151
#define ZFENUM_BEGIN(ZFLIB_, EnumName)
macros to define reflectable enum type
Definition ZFEnumDeclare.h:147
#define ZFENUM_END(ZFLIB_, EnumName)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:172
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_DECLARE_0(ReturnType, MethodName)
see ZFMethod
Definition ZFMethodDeclare.h:693
#define ZFMETHOD_DECLARE_2(ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMethod
Definition ZFMethodDeclare.h:1025
#define ZFMETHOD_DECLARE_3(ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2)
see ZFMethod
Definition ZFMethodDeclare.h:1206
#define ZFMETHOD_DECLARE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:854
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#define ZFEVENT(YourEvent)
see ZFObject::observerNotify
Definition ZFObjectObserver.h:328
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:128
#define ZFPROPERTY_ON_ATTACH_DECLARE(Type, Name)
see ZFPROPERTY_ON_INIT_DECLARE
Definition ZFPropertyDeclare.h:248
#define ZFSTYLE_DEFAULT_DECLARE(YourStyle)
used to declare a default style, see ZFStyleable
Definition ZFStyleable.h:262
#define ZFLIB_ZFUIKit
used to export symbols
Definition ZFUIKitDef.h:16
v_ZFUIScrollViewState::ZFEnumType ZFUIScrollViewState
see v_ZFUIScrollViewState
Definition ZFUIScrollView.h:23
ZFUIMargin ZFUIMarginCreate(zffloat const &left, zffloat const &top, zffloat const &right, zffloat const &bottom)
make a margin
Definition ZFUITypeDef.h:183
base class of all UI views
v_ZFUIViewChildLayer::ZFEnumType ZFUIViewChildLayer
see v_ZFUIViewChildLayer
Definition ZFUIViewType.h:511
void observerNotify(zfidentity eventId, ZFObject *param0=zft_zfnull, ZFObject *param1=zft_zfnull)
notify the observer with eventId
static zfanyT< ZFUIGlobalStyle > DefaultStyle(void)
margin
Definition ZFUITypeDef.h:147
mouse event for ui elements
Definition ZFUIMouseEvent.h:52
2D point
Definition ZFUITypeDef.h:62
2D rectangle
Definition ZFUITypeDef.h:636
virtual ZFUIScrollViewState scrollViewState()
current state for the scroll view
virtual void scrollBySpeed(zffloat xSpeedInPixelsPerSecond, zffloat ySpeedInPixelsPerSecond)
scroll by desired initial speed, in pixels per second
virtual void scrollAreaMarginAdd(const ZFUIMargin &margin)
margin for impl to modify scrollable area, ZFUIMarginZero by default
virtual void autoScrollStopX()
see autoScrollStartX
void scrollOverride(zfbool scrollOverride)
for subclass to supply advanced scroll controll
static zfidentity E_ScrollContentFrameOnUpdate(void)
see ZFObject::observerNotify
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
virtual ZFUIPoint scrollByPointEndPoint()
return end point of scrollByPoint, or current content offset if not scrolling
virtual void scrollOnScrollEnd(void)
see E_ScrollOnScrollEnd
Definition ZFUIScrollView.h:523
virtual zfbool & scrollAlignToAxis()
whether limit scroll horizontal or vertical only, false by default
Definition ZFUIScrollView.h:149
virtual void scrollChildToVisible(ZFUIView *child, const ZFUIMargin &margin=(ZFUIMarginCreate(ZFUIGlobalStyle::DefaultStyle() ->itemMargin())), zfbool scrollWithAni=(_ZFT_t_zftrue))
scroll child to proper position so that it's visible to user
virtual void nativeImplViewMarginOnUpdate(void)
see E_NativeImplViewMarginOnUpdate
virtual zfbool & scrollBounceHorizontalAlways()
scrollable even if content is not larger than scrollview, false by default
Definition ZFUIScrollView.h:138
virtual void scrollThumbHorizontalOnInit(void)
called to init scroll thumb
virtual zfbool & scrollBounceVerticalAlways()
scrollable even if content is not larger than scrollview, false by default
Definition ZFUIScrollView.h:143
virtual void layoutOnLayoutFinish(const ZFUIRect &bounds)
see E_ViewLayoutOnLayoutFinish
static zfidentity E_ScrollOnScrolledByUser(void)
see ZFObject::observerNotify
virtual void scrollSimulateDragBegin(const ZFUIPoint &mousePos, zftimet mouseTime)
simulate drag
virtual void scrollThumbVerticalOnInit(void)
called to init scroll thumb
virtual zfbool & scrollBounceHorizontal()
if content is larger than scroll view, make it scrollable even if reaches edge, true by default
Definition ZFUIScrollView.h:128
virtual void implChildOnRemove(ZFUIView *child, zfindex virtualIndex, ZFUIViewChildLayer childLayer, zfindex childLayerIndex)
see implChildOnAdd, implChildOnRemoveAllForDealloc
virtual void objectOnDealloc(void)
override this to destroy your object
static zfidentity E_ScrollOnDragBegin(void)
see ZFObject::observerNotify
static zfidentity E_ScrollOnScrollBegin(void)
see ZFObject::observerNotify
virtual void scrollSimulateDrag(const ZFUIPoint &mousePos, zftimet mouseTime)
simulate drag
virtual void implChildOnRemoveAllForDealloc(void)
called to remove all children during parent dealloc for performance
virtual void autoScrollStartY(zffloat speedInPixelsPerSecond)
see autoScrollStartX
virtual void autoScrollStopY()
see autoScrollStartX
virtual zffloat scrollContentOffsetBottom()
see scrollContentOffsetLeft
virtual void scrollToFitRange()
cancel over scroll and ensure content offset in range
static zfidentity E_ScrollAutoScrollOnStop(void)
see ZFObject::observerNotify
virtual zffloat scrollContentOffsetLeft()
util method to get offset of the scroll content
virtual void viewEventOnMouseEvent(ZFUIMouseEvent *mouseEvent)
(ZFTAG_LIMITATION) due to implementations limitation, ZFUIScrollView may or may not have mouse event ...
static zfidentity E_ScrollOnScroll(void)
see ZFObject::observerNotify
virtual void scrollOnScrollBegin(void)
see E_ScrollOnScrollBegin
Definition ZFUIScrollView.h:515
virtual void scrollAreaOnUpdate(void)
see E_ScrollAreaOnUpdate
Definition ZFUIScrollView.h:527
virtual void layoutChildOffsetOnUpdate(ZFUIPoint &ret)
see layoutChildOffset
Definition ZFUIScrollView.h:230
virtual ZFUIPoint scrollEndPointPredicted()
scrollByPointEndPoint or scrollBySpeedEndPointPredicted depending on scroll type
virtual void scrollThumbHorizontalClass(const ZFClass *cls)
change current scroll thumb, null to disable
virtual zffloat scrollBySpeedCurrentSpeedX()
return current speed of scrollBySpeed
virtual void objectOnInit(void)
override this to init your object
virtual zffloat scrollContentOffsetTop()
see scrollContentOffsetLeft
static zfidentity E_ScrollAutoScrollOnStart(void)
see ZFObject::observerNotify
virtual void scrollAutoScrollOnStart(void)
see E_ScrollAutoScrollOnStart
Definition ZFUIScrollView.h:535
virtual void scrollByPoint(zffloat xPos, zffloat yPos)
animated scroll to desired position
virtual void scrollContentFrameAnimated(const ZFUIRect &scrollContentFrame)
animated change scroll content frame
virtual zffloat autoScrollSpeedY()
current auto scroll speed, 0 means not auto scrolling, see autoScrollStartX
virtual void scrollOnScroll(void)
see E_ScrollOnScroll
Definition ZFUIScrollView.h:519
virtual zfbool & scrollBounceVertical()
if content is larger than scroll view, make it scrollable even if reaches edge, true by default
Definition ZFUIScrollView.h:133
virtual void scrollThumbVerticalClass(const ZFClass *cls)
see scrollThumbHorizontalClass
virtual void scrollOnDragEnd(void)
see E_ScrollOnDragEnd
Definition ZFUIScrollView.h:511
virtual void viewEventOnWheelEvent(ZFUIWheelEvent *wheelEvent)
called when wheel event occurred
virtual void scrollAreaMarginRemove(const ZFUIMargin &margin)
see scrollAreaMarginAdd
virtual zffloat autoScrollSpeedX()
current auto scroll speed, 0 means not auto scrolling, see autoScrollStartX
virtual zfbool & scrollAlignToPageVertical()
whether align to page when scroll, false by default
Definition ZFUIScrollView.h:166
virtual zffloat scrollContentOffsetRight()
see scrollContentOffsetLeft
virtual zfbool & scrollEnable()
whether the scroll view is scrollable, zftrue by default
Definition ZFUIScrollView.h:122
virtual zfbool & scrollAlignToPageHorizontal()
whether align to page when scroll, false by default
Definition ZFUIScrollView.h:157
virtual ZFUIRect & scrollContentFrame()
scroll view's content frame
Definition ZFUIScrollView.h:180
virtual void scrollOnDrag(void)
see E_ScrollOnDrag
Definition ZFUIScrollView.h:507
static zfidentity E_ScrollAreaOnUpdate(void)
see ZFObject::observerNotify
static zfidentity E_ScrollOnDrag(void)
see ZFObject::observerNotify
virtual void scrollOnDragBegin(void)
see E_ScrollOnDragBegin
Definition ZFUIScrollView.h:503
virtual void autoScrollStartX(zffloat speedInPixelsPerSecond)
start an auto scroll with specified speed
virtual const ZFUIRect & scrollArea()
scrollable frame excluding scrollAreaMargin, valid only if layouted
virtual void scrollContentFrameUpdate(const ZFUIRect &scrollContentFrame)
change scroll content frame without interrupt current scroll animation
virtual void scrollSimulateDragEnd(zftimet mouseTime, zfbool needScrollAni=(_ZFT_t_zftrue))
simulate drag
virtual void scrollContentFrameOnUpdate(void)
see E_ScrollContentFrameOnUpdate
Definition ZFUIScrollView.h:531
virtual const ZFUIMargin & scrollAreaMargin()
see scrollAreaMarginAdd
virtual zffloat scrollBySpeedCurrentSpeedY()
return current speed of scrollBySpeed
virtual const ZFClass * scrollerClass()
class for internal scroller, must be type of ZFUIScroller, ZFUIScrollerClass by default
virtual void layoutOnLayoutPrepare(const ZFUIRect &bounds)
see E_ViewLayoutOnLayoutPrepare
virtual void scrollAutoScrollOnStop(void)
see E_ScrollAutoScrollOnStop
Definition ZFUIScrollView.h:539
virtual void layoutOnLayout(const ZFUIRect &bounds)
override ZFUIView to layout scroll view's internal view and content view
virtual void implChildOnAdd(ZFUIView *child, zfindex virtualIndex, ZFUIViewChildLayer childLayer, zfindex childLayerIndex)
called to add or remove view to impl
static zfidentity E_ScrollOnDragEnd(void)
see ZFObject::observerNotify
static zfidentity E_ScrollOnScrollEnd(void)
see ZFObject::observerNotify
virtual ZFUIPoint scrollBySpeedEndPointPredicted()
return predicted end point of scrollBySpeed, or current content offset if not scrolling,...
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
virtual void scrollOnScrolledByUser(void)
see E_ScrollOnScrolledByUser
Definition ZFUIScrollView.h:543
zfanyT< ZFUILayoutParam > child(const zfany &view, zfindex atIndex=((zfindex) -1))
add child and return child's layoutParam, see childWithParam
wheel event for ui elements
Definition ZFUIWheelEvent.h:16