ZFFramework
Loading...
Searching...
No Matches
Styleable

with styleable logic, you may copy contents from another object easily
to declare a styleable, it's recommended to declare like this:

// in header files:
zfclass YourStyleableObject : zfextend ParentStyleableObject {
ZFOBJECT_DECLARE(YourStyleableObject, ParentStyleableObject)
ZFSTYLE_DEFAULT_DECLARE(YourStyleableObject)
};
// in cpp files
ZFSTYLE_DEFAULT_DEFINE(YourStyleableObject)
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#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 ZFSTYLE_DEFAULT_DECLARE(YourStyle)
used to declare a default style, see ZFStyleable
Definition ZFStyleable.h:318
#define ZFSTYLE_DEFAULT_DEFINE(YourStyle)
see ZFSTYLE_DEFAULT_DECLARE
Definition ZFStyleable.h:321

once declared, object's style can be copied as styleable easily:

obj->styleableCopyFrom(anotherStyleableObject);

and you can access default style by the macro generated method:

YourStyle::DefaultStyle();

then, it's convenient to chain different styleable object to achieve simple style logic:

zfclass SomeStyle : zfextend Parent {
ZFOBJECT_DECLARE(SomeStyle, Parent)
ZFPROPERTY_RETAIN(SomeType, someName, OtherStyle::DefaultStyle()->sth())
};
#define ZFPROPERTY_RETAIN(Type, Name,...)
declare a retain property
Definition ZFPropertyDeclare.h:103

Advanced styleable

styleable is useful to achieve advance skin logic, use ZFStyleable::styleKey to supply your style:

yourObj->styleKey("your_skin_key");

this code register yourObj to ZFStyleSet, once the skin value associated with "your_skin_key" has changed by ZFStyleChangeEnd, yourObj would be notified and copy style from it automatically

for non-ZFStyleable property, you may also attach to style if it's registered by ZFTYPEID_DECLARE

yourObj->styleKeyForProperty(ZFPropertyAccess(YourObject, yourProperty), "your_skin_key");
#define ZFPropertyAccess(OwnerClass, Name)
access the property directly, compile error if not declared
Definition ZFPropertyDeclare.h:19


also, thanks to ZFClass's instance observer, you may achieve more complex style logic:

ZFLISTENER(myObjCreated) {
MyStyleableObject *obj = zfargs.sender();
// change default setting for all instance of MyStyleableObject
obj->myProperty(xxx);
// or apply style copy (consume more CPU)
obj->styleableCopyFrom(yyy);
MyStyleableObject::ClassData()->instanceObserverAdd(myObjCreated);
#define ZFLISTENER(name)
util to declare a ZFListener locally
Definition ZFListenerDeclare.h:53
#define ZFLISTENER_END()
see ZFLISTENER
Definition ZFListenerDeclare.h:17