ubit::UProp Class Reference

Base class for Graphical Properties. More...

#include <uprop.hpp>

Inheritance diagram for ubit::UProp:

ubit::UBrick ubit::UObject ubit::UAlpha ubit::UBackground ubit::UBorder ubit::UChoice ubit::UColor ubit::UCursor ubit::UEdit ubit::UFlagdef ubit::UFont ubit::UHalign ubit::UHeight ubit::UHmargin ubit::UHspacing ubit::UOrient ubit::UPos ubit::UPosChooser ubit::UProps ubit::UPropval ubit::URadioSelect ubit::UScale ubit::UValign ubit::UVmargin ubit::UVspacing ubit::UWidth List of all members.

Public Member Functions

 UProp (UMask b_modes=0)
virtual class UProppropCast ()
 dynamic cast (
virtual unsigned short getNodeType () const
 returns the XML node type.
virtual const UStrgetNodeName () const
 returns the XML node name.
virtual const UStrgetNodeValue () const
 returns the XML node value.
virtual const UStrgetName () const
 returns the name of this attribute.
virtual const UStrgetValue () const
 returns the value of this attribute.
virtual void setValue (const UStr &)
virtual void initNode (UDoc *, UGroup *parent)
 initialises this node.
virtual UProponChange (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< UStrpvalue

Friends

class UBox

Detailed Description

Base class for Graphical Properties.

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

See also:
also: the UCall doc, that explains how to use ucall() expressions


Member Function Documentation

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

UProp & ubit::UProp::onChange ( UCall  )  [virtual]

adds a callback that is fired when the value of the property is modified.

See also:
an example in the UProp doc.

virtual class UProp* ubit::UProp::propCast (  )  [virtual]

dynamic cast (

See also:
UObject).

Reimplemented from ubit::UObject.


The documentation for this class was generated from the following files:
Generated on Mon Jan 29 00:20:54 2007 for Ubit by  doxygen 1.4.7