#include <uprop.hpp>
Inheritance diagram for ubit::UProp:
Public Member Functions | |
UProp (UMask b_modes=0) | |
virtual class UProp * | propCast () |
dynamic cast ( | |
virtual unsigned short | getNodeType () const |
returns the XML node type. | |
virtual const UStr * | getNodeName () const |
returns the XML node name. | |
virtual const UStr * | getNodeValue () const |
returns the XML node value. | |
virtual const UStr * | getName () const |
returns the name of this attribute. | |
virtual const UStr * | getValue () const |
returns the value of this attribute. | |
virtual void | setValue (const UStr &) |
virtual void | initNode (UDoc *, UGroup *parent) |
initialises this node. | |
virtual UProp & | onChange (UCall &) |
adds a callback that is fired when the value of the property is modified. | |
virtual void | changed (bool update=true) |
[impl] called when object's content is changed. | |
virtual void | update () |
updates parents graphics. | |
virtual void | putProp (UContext *, UControl *) |
[impl] changes corresponding value in the UContext | |
Protected Attributes | |
uptr< UStr > | pvalue |
Friends | |
class | UBox |
Property bricks specify the layout, the geometry, the color, the font... of container objects that derive from UBox (certain properties also apply on UGroup containers, as explained in the doc of these properties).
They can be added to the attribute list of one or several containers by using UGroup::addAttr(). They can also be inserted in the *beginning* of their child list, before any viewable child (that is to say a child that derive from UGroup or UData). Certains properties (mainly UFont and UColor) can be inserted anywhere in the child list and take effect of the following children.
Properties update their parents automatically when they are modified. All parents that share the same property are thus automatically synchronized.
Properties can have callback functions that are fired when their value is changed (see an example below). Property parents can also be notified when property values are modified by using the UOn::propChange condition (see below).
Example:
class Demo { public: void colorCB(UColor* c); void boxCB(UEvent& e); .... };
Demo* d = new Demo();
UColor& color = ucolor(255, 0, 0); // shorcut for: *new UColor(...)
// d->colorCB(&color) will be called when the color is changed color.onChange(ucall(d, &color, &Demo::colorCB));
UBox& btn = ubutton("Click Me"); // shorcut for: *new UButton(...)
btn.addAttr(color); // adds color to the attribute list
// the content of UColor::blue (which is a predefined value) is copied // into the content of the color object (note that color is not a pointer // but a reference)
color = UColor::blue; // fires colorCB
Alternatively, we could insert color at the beginning of the child list:
UBox& btn = ubutton(color + "Click Me"); // btn.addAttr(color); useless: color is in the child list!
Finally,
UBox& btn = ubutton(color + "Click Me" + UOn::propChange / ucall(d, &Demo::boxCB));
will call d->boxCB(event) when the value of any property of btn is changed. In this case, color is the only property, and boxCB is fired when color is modified. The UEvent& argument of boxCB() makes it possible to retrieve the color property as follows:
void Demo::boxCB(UEvent& e) { UColor* c = null; if (e.getTarget()) c = dynamic_cast<UColor*>(e.getTarget()); .... }Note that we could have use the same technique to retrieve the color property in colorCB(), instead of giving color as an argument to this function
void ubit::UProp::changed | ( | bool | update = true |
) | [virtual] |
[impl] called when object's content is changed.
This function updates graphics (if 'update' is true) then fires parents' UOn::propChange callbacks
adds a callback that is fired when the value of the property is modified.
virtual class UProp* ubit::UProp::propCast | ( | ) | [virtual] |