Prev: point-drawer.html Up Next: legendbox.html

Practical Guide:
label::pdraw("Some text",2*MM,3*CM).xalign(sym::center);    // draw a label into the current pad

label::direction(sym::up);           // set direction for subsequent labels
label::pdraw("Above previous text"); // draw another label above previous one

A label is a text object. This inherits from box, so it provides the left(), width(), right(), bottom() etc. functions to access its dimensions.

A label provides the following member functions to modify its properties:

text(const var &)
Set the value (text) of this label
Set the angle of the label (in degrees)
textcolor(const color &)
Set the color of the text
x(const length &)
y(const length &)
x(const length &, int xalign)
y(const length &, int yalign)
Specify the coordinates (first two functions), or the coordinates and alignment (3rd and 4th version) in the x or y direction
align(int xal, int yal)
Specify the alignment of the label
All of these functions return a reference to the object itself, so they can be chained:
label l;
l.text("text").textcolor(blue).x(2*CM, sym::center).angle(45);

It provides the static functions cdraw(...),pdraw(...),fdraw(...) (see the design concepts). All of these 3 functions accept 3 argument: the first argument is the text to be drawn, the 2nd and 3rd argument is a length, specifying the coordinates of the text. These are those values, which are absolutely necessary for any text label to be drawn. These functions create a new object, place it into the current canvas (cdraw), pad (pdraw) or frame (fdraw), and return a reference to the newly created object. Any other attributes can be set using member functions on the returned reference:

// draw a label centered within a pad
Or, if you want to access this object later, remember a reference:
// draw a label centered within a pad
label &l = label::pdraw("text",0.5,0.5).align(sym::center,sym::center).textcolor(blue);
.... do something else
l.angle(45);  // rotate by 45 degrees

The pdraw, fdraw and cdraw functions have also a version without positions. In this case the label is positioned with respect to the last previously placed label, depending on a direction flag, which one can set via the static function label::direction(...) function, see below. (The label is left-aligned with the last label, but this might change in the future to allow right-alignment)

label::fdraw("First label",0.2,0.2);  // place first label
label::direction(sym::up);            // change the default placement direction to 'upwards'
                                      // the default is 'down'
label::fdraw("Second label above the first");
label::fdraw("third label above the 2nd");
label::fdraw(".... etc");

Souce files:

Prev: point-drawer.html Up Next: legendbox.html