ZFFramework
 
Loading...
Searching...
No Matches
ZFUIAutoLayout.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFUIAutoLayout_h_
7#define _ZFI_ZFUIAutoLayout_h_
8
9#include "ZFUIWidgetDef.h"
11
12// ============================================================
32
36
37public:
42
43public:
45 inline zfbool valid(void) const {
46 return this->target() || this->_ZFP_AL_targetId;
47 }
48
49 void removeAll(void) {
50 this->target(zfnull);
52 this->_ZFP_AL_targetId.removeAll();
53 }
54
55public:
60 zfstring ret;
61 this->objectInfoT(ret);
62 return ret;
63 }
64
65public:
67 zfbool operator == (ZF_IN const ZFUIAutoLayoutRule &ref) const {
68 return (zftrue
69 && this->target() == ref.target()
70 && this->targetPos() == ref.targetPos()
71 );
72 }
73 inline zfbool operator != (ZF_IN const ZFUIAutoLayoutRule &ref) const {
74 return !this->operator == (ref);
75 }
77
78public:
79 zfstring _ZFP_AL_targetId;
80};
83ZFOUTPUT_TYPE(ZFUIAutoLayoutRule, {v.objectInfoT(s);})
84
85// ============================================================
86// ZFUIAutoLayoutParam
89zfclass ZFLIB_ZFUIWidget ZFUIAutoLayoutParam : zfextend ZFUILayoutParam {
90 ZFOBJECT_DECLARE(ZFUIAutoLayoutParam, ZFUILayoutParam)
91
92
96
98
99 // ============================================================
100 // rule state
101public:
112
113 // ============================================================
114 // util methods to setup rule
115public:
128
131
134 , ZFMP_IN(const zfstring &, viewId)
138 , ZFMP_IN(const zfstring &, viewId)
142 , ZFMP_IN(const zfstring &, viewId)
146 , ZFMP_IN(const zfstring &, viewId)
150 , ZFMP_IN(const zfstring &, viewId)
154 , ZFMP_IN(const zfstring &, viewId)
156
159 , ZFMP_IN(ZFUIView *, target)
163 , ZFMP_IN(ZFUIView *, target)
167 , ZFMP_IN(ZFUIView *, target)
171 , ZFMP_IN(ZFUIView *, target)
175 , ZFMP_IN(ZFUIView *, target)
179 , ZFMP_IN(ZFUIView *, target)
181
194
197 , ZFMP_IN(const zfstring &, viewId)
201 , ZFMP_IN(ZFUIView *, target)
205
206protected:
211 ZF_IN const ZFSerializableData &serializableData
212 , ZF_OUT_OPT zfstring *outErrorHint = zfnull
213 , ZF_OUT_OPT ZFSerializableData *outErrorPos = zfnull
214 );
217 ZF_IN_OUT ZFSerializableData &serializableData
218 , ZF_OUT_OPT zfstring *outErrorHint = zfnull
219 , ZF_IN_OPT ZFSerializable *refOwner = zfnull
220 );
221
223 virtual void styleableOnCopyFrom(ZF_IN ZFObject *anotherStyleable);
225 virtual ZFCompareResult objectCompareValueImpl(ZF_IN ZFObject *anotherObj);
226
227public:
228 zfclassLikePOD _ZFP_Data {
229 public:
232 zfbool posReset;
233 public:
234 _ZFP_Data(void) : ruleList(), posAttached(), posReset(zffalse) {}
235 };
236public:
237 _ZFP_Data _ZFP_AL_d;
238public:
240 /* ZFTAG_TRICKS: util for chained call to build view tree */
241 inline zfanyT<ZFUIAutoLayoutParam> child(
242 ZF_IN const zfany &view
243 , ZF_IN_OPT zfindex atIndex = zfindexMax()
244 ) {
245 return zfsuper::child(view, atIndex);
246 }
248};
249
251#define ZFSerializableKeyword_ZFUIAutoLayoutParam_rule "rule"
253#define ZFSerializableKeyword_ZFUIAutoLayoutParam_target_parent "@parent"
255#define ZFSerializableKeyword_ZFUIAutoLayoutParam_target_self "@self"
256
257// ============================================================
258// ZFUIAutoLayout
259zfclassFwd _ZFP_ZFUIAutoLayoutPrivate;
326zfclass ZFLIB_ZFUIWidget ZFUIAutoLayout : zfextend ZFUIView {
327 ZFOBJECT_DECLARE(ZFUIAutoLayout, ZFUIView)
329
330 // ============================================================
331 // override ZFUIView
332public:
334 /* ZFTAG_TRICKS: util for chained call to build view tree */
336 ZF_IN const zfany &view
337 , ZF_IN_OPT zfindex atIndex = zfindexMax()
338 ) {
339 return zfsuper::child(view, atIndex);
340 }
342protected:
344 virtual void viewChildOnRemove(
345 ZF_IN ZFUIView *child
347 );
348
350 virtual const ZFClass *layoutParamClass(void) {
352 }
353
355 virtual void layoutOnMeasure(
356 ZF_OUT ZFUISize &ret
357 , ZF_IN const ZFUISize &sizeHint
358 , ZF_IN const ZFUISizeParam &sizeParam
359 );
361 virtual void layoutOnLayout(ZF_IN const ZFUIRect &bounds);
362
363protected:
365 virtual void styleableOnCopyFrom(ZF_IN ZFObject *anotherStyleable);
368 ZF_IN const ZFSerializableData &serializableData
369 , ZF_OUT_OPT zfstring *outErrorHint = zfnull
370 , ZF_OUT_OPT ZFSerializableData *outErrorPos = zfnull
371 );
372
373protected:
375 virtual void objectOnInit(void);
377 virtual void objectOnDealloc(void);
378
379private:
380 _ZFP_ZFUIAutoLayoutPrivate *d;
381};
382
383extern ZFLIB_ZFUIWidget zfbool _ZFP_ZFUIAutoLayout_targetUpdate(
385 , ZF_IN ZFUIAutoLayout *parent
386 , ZF_IN ZFUIView *child
387 );
388extern ZFLIB_ZFUIWidget zfbool _ZFP_ZFUIAutoLayout_targetIdUpdate(
389 ZF_OUT zfstring &targetId
391 , ZF_IN ZFUIAutoLayout *parent
392 , ZF_IN ZFUIView *child
393 );
394
396#endif // #ifndef _ZFI_ZFUIAutoLayout_h_
397
#define ZF_OUT_OPT
dummy macro that shows the param used as optional output
Definition ZFCoreTypeDef_ClassType.h:192
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#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_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
#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
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
_zft_zffloat zffloat
same as float, see zfindex
Definition ZFCoreTypeDef_CoreType.h:183
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFOUTPUT_TYPE(T_Type, outputAction)
declare your custom type conversion to string, convenient for debug
Definition ZFCoreTypeDef_OtherType.h:221
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFCORE_PARAM_DECLARE_SELF(T_self)
see ZFCORE_PARAM
Definition ZFCoreUtilMacro.h:495
#define ZFCORE_PARAM(T_ParamType, paramName,...)
a util macro to generate setter and getter for POD like object
Definition ZFCoreUtilMacro.h:523
#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(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_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 ZFCORE_PARAM_WEAK(T_ParamType, paramName,...)
ZFObject weak version of ZFCORE_PARAM.
Definition ZFObjectClassTypeFwd.h:48
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#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
ZFSerializablePropertyType
serializable property type, see ZFSerializable::serializableOnCheckPropertyType
Definition ZFSerializable.h:40
#define ZFSTYLE_DEFAULT_DECLARE(YourStyle)
used to declare a default style, see ZFStyleable
Definition ZFStyleable.h:262
#define ZFTYPEID_ACCESS_ONLY_REG(ZFLIB_, TypeName, Type,...)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:205
#define ZFTYPEID_ACCESS_ONLY_DECLARE(ZFLIB_, TypeName, Type)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:195
v_ZFUIAutoLayoutPos::ZFEnumType ZFUIAutoLayoutPos
see v_ZFUIAutoLayoutPos
Definition ZFUIAutoLayout.h:30
v_ZFUIViewChildLayer::ZFEnumType ZFUIViewChildLayer
see v_ZFUIViewChildLayer
Definition ZFUIViewType.h:511
global header for ZFUIWidget module
#define ZFLIB_ZFUIWidget
used to export symbols
Definition ZFUIWidgetDef.h:17
info for a property for ZFObject, see ZFPROPERTY_RETAIN for more info
Definition ZFProperty.h:28
ZFSerializable's data container, see ZFSerializable.
Definition ZFSerializableData.h:74
see v_ZFUIAlign, ZFUIAlignFlagsToString, ZFUIAlignFlagsFromString
Definition ZFUITypeDef.h:1075
auto layout with constraint rule
Definition ZFUIAutoLayout.h:326
virtual void objectOnDealloc(void)
override this to destroy your object
virtual zfbool serializableOnSerializeFromData(const ZFSerializableData &serializableData, zfstring *outErrorHint=zft_zfnull, ZFSerializableData *outErrorPos=zft_zfnull)
for serializable data that has "category" attribute, ZFSerializable would ignore it and leave it to s...
virtual void layoutOnMeasure(ZFUISize &ret, const ZFUISize &sizeHint, const ZFUISizeParam &sizeParam)
called by layoutMeasure to decide the view's size
virtual void styleableOnCopyFrom(ZFObject *anotherStyleable)
for a view, copy style would also copy all of it's children
virtual void viewChildOnRemove(ZFUIView *child, ZFUIViewChildLayer layer)
see E_ViewChildOnRemove
virtual const ZFClass * layoutParamClass(void)
see layoutParamCreate
Definition ZFUIAutoLayout.h:350
virtual void objectOnInit(void)
override this to init your object
virtual void layoutOnLayout(const ZFUIRect &bounds)
called by viewFrame to layout the view and children
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:89
virtual zffloat & biasY()
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:95
virtual void toParentTop()
see ZFUIAutoLayout
virtual zfbool serializableOnSerializeToData(ZFSerializableData &serializableData, zfstring *outErrorHint=zft_zfnull, ZFSerializable *refOwner=zft_zfnull)
corresponding to serializableOnSerializeFromData, return whether the task is success,...
virtual void top()
see ZFUIAutoLayout
static const ZFClass * ClassData(void)
get class info
Definition ZFUIAutoLayout.h:90
virtual void toParentRight()
see ZFUIAutoLayout
virtual void left()
see ZFUIAutoLayout
virtual ZFSerializablePropertyType serializableOnCheckPropertyType(const ZFProperty *property)
check the property type that serializable should do what while serializing
virtual void toParent()
see ZFUIAutoLayout
virtual void toTop(const zfstring &viewId)
see ZFUIAutoLayout
virtual void ruleRemove(ZFUIAutoLayoutPos pos)
see ZFUIAutoLayout
virtual void toParentLeft()
see ZFUIAutoLayout
virtual void ruleRemoveAll()
see ZFUIAutoLayout
virtual void toLeft(const zfstring &viewId)
see ZFUIAutoLayout
virtual void toParentHeight()
see ZFUIAutoLayout
virtual void width()
see ZFUIAutoLayout
virtual zfbool serializableOnSerializeFromData(const ZFSerializableData &serializableData, zfstring *outErrorHint=zft_zfnull, ZFSerializableData *outErrorPos=zft_zfnull)
for serializable data that has "category" attribute, ZFSerializable would ignore it and leave it to s...
virtual void toParentWidth()
see ZFUIAutoLayout
virtual void styleableOnCopyFrom(ZFObject *anotherStyleable)
for subclass to achieve custom style copy step, called by styleableCopyFrom, see ZFStyleable
virtual ZFCompareResult objectCompareValueImpl(ZFObject *anotherObj)
see objectCompareValue
virtual void bottom()
see ZFUIAutoLayout
virtual const ZFUIAutoLayoutRule & rule(ZFUIAutoLayoutPos pos)
see ZFUIAutoLayout
virtual void toParentBottom()
see ZFUIAutoLayout
virtual void toBottom(const zfstring &viewId)
see ZFUIAutoLayout
virtual zffloat & biasX()
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:93
virtual void toWidth(const zfstring &viewId)
see ZFUIAutoLayout
virtual void toRight(const zfstring &viewId)
see ZFUIAutoLayout
virtual void right()
see ZFUIAutoLayout
virtual void toHeight(const zfstring &viewId)
see ZFUIAutoLayout
virtual void edges()
util to setup left + top + right + bottom
virtual void height()
see ZFUIAutoLayout
virtual void to(const zfstring &viewId)
see ZFUIAutoLayout
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:34
ZFUIAutoLayoutPos & targetPos(void)
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:41
void objectInfoT(zfstring &ret) const
see objectInfo
void removeAll(void)
remove all contents
Definition ZFUIAutoLayout.h:49
zfstring objectInfo(void) const
return object info
Definition ZFUIAutoLayout.h:59
zfanyT< ZFUIView > const & target(void) const
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:39
zfbool valid(void) const
true if contains valid rule
Definition ZFUIAutoLayout.h:45
virtual ZFUIAlignFlags & align()
see ZFUILayoutParam, default is (v_ZFUIAlign::e_Left | v_ZFUIAlign::e_Top)
Definition ZFUIViewType.h:153
2D rectangle
Definition ZFUITypeDef.h:636
2D size
Definition ZFUITypeDef.h:397
2D size
Definition ZFUIViewType.h:41
base class of all UI views
Definition ZFUIView.h:93
zfanyT< ZFUILayoutParam > child(const zfany &view, zfindex atIndex=((zfindex) -1))
add child and return child's layoutParam, see childWithParam
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:14
@ e_None
Definition ZFUIAutoLayout.h:15
@ ZFEnumCount
max enum value
Definition ZFUIAutoLayout.h:22
util method to cast ZFObject types freely
Definition zfany.h:35
see zfany
Definition zfany.h:106