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// ============================================================
13#define _ZFP_ZFUIAutoLayoutPosCount 7
33
37
38public:
43
44public:
46 inline zfbool valid(void) const {
47 return this->target() || this->_ZFP_AL_targetId;
48 }
49
50 void removeAll(void) {
51 this->target(zfnull);
53 this->_ZFP_AL_targetId.removeAll();
54 }
55
56public:
61 zfstring ret;
62 this->objectInfoT(ret);
63 return ret;
64 }
65
66public:
68 zfbool operator == (ZF_IN const ZFUIAutoLayoutRule &ref) const {
69 return (zftrue
70 && this->target() == ref.target()
71 && this->targetPos() == ref.targetPos()
72 );
73 }
74 inline zfbool operator != (ZF_IN const ZFUIAutoLayoutRule &ref) const {
75 return !(this->operator == (ref));
76 }
78
79public:
80 zfstring _ZFP_AL_targetId;
81};
84ZFOUTPUT_TYPE(ZFUIAutoLayoutRule, {v.objectInfoT(s);})
85
86// ============================================================
87// ZFUIAutoLayoutParam
90zfclass ZFLIB_ZFUIWidget ZFUIAutoLayoutParam : zfextend ZFUILayoutParam {
91 ZFOBJECT_DECLARE(ZFUIAutoLayoutParam, ZFUILayoutParam)
92
93
97
99
100 // ============================================================
101 // rule state
102public:
113
114 // ============================================================
115 // util methods to setup rule
116public:
129
132
135 , ZFMP_IN(const zfstring &, viewId)
139 , ZFMP_IN(const zfstring &, viewId)
143 , ZFMP_IN(const zfstring &, viewId)
147 , ZFMP_IN(const zfstring &, viewId)
151 , ZFMP_IN(const zfstring &, viewId)
155 , ZFMP_IN(const zfstring &, viewId)
157
160 , ZFMP_IN(ZFUIView *, target)
164 , ZFMP_IN(ZFUIView *, target)
168 , ZFMP_IN(ZFUIView *, target)
172 , ZFMP_IN(ZFUIView *, target)
176 , ZFMP_IN(ZFUIView *, target)
180 , ZFMP_IN(ZFUIView *, target)
182
195
198 , ZFMP_IN(const zfstring &, viewId)
202 , ZFMP_IN(ZFUIView *, target)
206
207protected:
212 ZF_IN const ZFSerializableData &serializableData
213 , ZF_OUT_OPT zfstring *errorHint = zfnull
215 );
218 ZF_IN_OUT ZFSerializableData &serializableData
219 , ZF_OUT_OPT zfstring *errorHint = zfnull
220 , ZF_IN_OPT ZFSerializable *refOwner = zfnull
221 );
222
224 virtual void styleableOnCopyFrom(ZF_IN ZFObject *anotherStyleable);
226 virtual ZFCompareResult objectCompareValueImpl(ZF_IN ZFObject *anotherObj);
227
228public:
229 zfclassLikePOD _ZFP_Data {
230 public:
231 ZFUIAutoLayoutRule ruleList[_ZFP_ZFUIAutoLayoutPosCount];
232 zfbool posAttached[_ZFP_ZFUIAutoLayoutPosCount];
233 zfbool posReset;
234 public:
235 _ZFP_Data(void) : ruleList(), posAttached(), posReset(zffalse) {}
236 };
237public:
238 _ZFP_Data _ZFP_AL_d;
239public:
241 /* ZFTAG_TRICKS: util for chained call to build view tree */
242 inline zfanyT<ZFUIAutoLayoutParam> child(
243 ZF_IN const zfany &view
244 , ZF_IN_OPT zfindex atIndex = zfindexMax()
245 ) {
246 return zfsuper::child(view, atIndex);
247 }
249};
250
252#define ZFSerializableKeyword_ZFUIAutoLayoutParam_rule "rule"
254#define ZFSerializableKeyword_ZFUIAutoLayoutParam_target_parent "@parent"
256#define ZFSerializableKeyword_ZFUIAutoLayoutParam_target_self "@self"
257
258// ============================================================
259// ZFUIAutoLayout
260zfclassFwd _ZFP_ZFUIAutoLayoutPrivate;
327zfclass ZFLIB_ZFUIWidget ZFUIAutoLayout : zfextend ZFUIView {
328 ZFOBJECT_DECLARE(ZFUIAutoLayout, ZFUIView)
330
331 // ============================================================
332 // override ZFUIView
333public:
335 /* ZFTAG_TRICKS: util for chained call to build view tree */
337 ZF_IN const zfany &view
338 , ZF_IN_OPT zfindex atIndex = zfindexMax()
339 ) {
340 return zfsuper::child(view, atIndex);
341 }
343protected:
345 virtual void viewChildOnRemove(
346 ZF_IN ZFUIView *child
348 );
349
351 virtual const ZFClass *layoutParamClass(void) {
353 }
354
356 virtual void layoutOnMeasure(
357 ZF_OUT ZFUISize &ret
358 , ZF_IN const ZFUISize &sizeHint
359 , ZF_IN const ZFUISizeParam &sizeParam
360 );
362 virtual void layoutOnLayout(ZF_IN const ZFUIRect &bounds);
363
364protected:
366 virtual void styleableOnCopyFrom(ZF_IN ZFObject *anotherStyleable);
369 ZF_IN const ZFSerializableData &serializableData
370 , ZF_OUT_OPT zfstring *errorHint = zfnull
372 );
373
374protected:
376 virtual void objectOnInit(void);
378 virtual void objectOnDealloc(void);
379
380private:
381 _ZFP_ZFUIAutoLayoutPrivate *d;
382};
383
384extern ZFLIB_ZFUIWidget zfbool _ZFP_ZFUIAutoLayout_targetUpdate(
386 , ZF_IN ZFUIAutoLayout *parent
387 , ZF_IN ZFUIView *child
388 );
389extern ZFLIB_ZFUIWidget zfbool _ZFP_ZFUIAutoLayout_targetIdUpdate(
390 ZF_OUT zfstring &targetId
392 , ZF_IN ZFUIAutoLayout *parent
393 , ZF_IN ZFUIView *child
394 );
395
397#endif // #ifndef _ZFI_ZFUIAutoLayout_h_
398
#define ZF_OUT_OPT
dummy macro that shows the param used as optional output
Definition ZFCoreTypeDef_ClassType.h:210
#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:198
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:202
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:206
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:214
#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:467
#define ZFCORE_PARAM(T_ParamType, paramName,...)
a util macro to generate setter and getter for POD like object
Definition ZFCoreUtilMacro.h:495
#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:692
#define ZFMETHOD_DECLARE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:853
#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:122
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:120
#define ZFPROPERTY_ON_ATTACH_DECLARE(Type, Name)
see ZFPROPERTY_ON_INIT_DECLARE
Definition ZFPropertyDeclare.h:239
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:268
#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:31
v_ZFUIViewChildLayer::ZFEnumType ZFUIViewChildLayer
see v_ZFUIViewChildLayer
Definition ZFUIViewType.h:522
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:27
ZFSerializable's data container, see ZFSerializable.
Definition ZFSerializableData.h:74
see v_ZFUIAlign, ZFUIAlignFlagsToString, ZFUIAlignFlagsFromString
Definition ZFUITypeDef.h:1104
auto layout with constraint rule
Definition ZFUIAutoLayout.h:327
virtual void objectOnDealloc(void)
override this to destroy your object
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:351
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
virtual zfbool serializableOnSerializeFromData(const ZFSerializableData &serializableData, zfstring *errorHint=zft_zfnull, ZFSerializableData *errorPos=zft_zfnull)
for serializable data that has "category" attribute, ZFSerializable would ignore it and leave it to s...
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:90
virtual zffloat & biasY()
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:96
virtual void toParentTop()
see ZFUIAutoLayout
virtual void top()
see ZFUIAutoLayout
static const ZFClass * ClassData(void)
get class info
Definition ZFUIAutoLayout.h:91
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 serializableOnSerializeToData(ZFSerializableData &serializableData, zfstring *errorHint=zft_zfnull, ZFSerializable *refOwner=zft_zfnull)
corresponding to serializableOnSerializeFromData, return whether the task is success,...
virtual void toParentWidth()
see ZFUIAutoLayout
virtual void styleableOnCopyFrom(ZFObject *anotherStyleable)
for subclass to achieve custom style copy step, called by copyFrom, 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:94
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 zfbool serializableOnSerializeFromData(const ZFSerializableData &serializableData, zfstring *errorHint=zft_zfnull, ZFSerializableData *errorPos=zft_zfnull)
for serializable data that has "category" attribute, ZFSerializable would ignore it and leave it to s...
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:35
ZFUIAutoLayoutPos & targetPos(void)
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:42
void objectInfoT(zfstring &ret) const
see objectInfo
void removeAll(void)
remove all contents
Definition ZFUIAutoLayout.h:50
zfstring objectInfo(void) const
return object info
Definition ZFUIAutoLayout.h:60
zfanyT< ZFUIView > const & target(void) const
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:40
zfbool valid(void) const
true if contains valid rule
Definition ZFUIAutoLayout.h:46
virtual ZFUIAlignFlags & align()
see ZFUILayoutParam, default is (v_ZFUIAlign::e_Left | v_ZFUIAlign::e_Top)
Definition ZFUIViewType.h:153
2D rectangle
Definition ZFUITypeDef.h:667
2D size
Definition ZFUITypeDef.h:418
2D size
Definition ZFUIViewType.h:41
base class of all UI views
Definition ZFUIView.h:88
zfanyT< ZFUILayoutParam > child(const zfany &view, zfindex atIndex=((zfindex) -1))
add child and return child's layoutParam
see ZFUIAutoLayout
Definition ZFUIAutoLayout.h:15
@ e_None
Definition ZFUIAutoLayout.h:16
util method to cast ZFObject types freely
Definition zfany.h:35
see zfany
Definition zfany.h:113