The SimpleCxxLib package


#include "gobjects.h"

class GLabel : public GObject

This graphical object subclass represents a text string. For example, the following code adds a GLabel containing the string "hello, world" to the center of the window:
   int main() {
      GWindow gw;
      cout << "This program draws the 'hello, world' message." << endl;
      GLabel *label = new GLabel("hello, world");
      label->setFont("SansSerif-18");
      double x = (gw.getWidth() - label->getWidth()) / 2;
      double y = (gw.getHeight() + label->getFontAscent()) / 2;
      gw.add(label, x, y);
      return 0;
   }
Controlling the appearance and positioning of a GLabel depends on understanding the following terms:

The following diagram illustrates the interpretation of these terms:

GLabelGeometry
Constructor
GLabel(str)
GLabel(str, x, y) 
Creates a GLabel object containing the specified string.
Methods
getFont() Returns the current font for the GLabel.
getFontAscent() Returns the maximum distance strings in this font extend above the baseline.
getFontDescent() Returns the maximum distance strings in this font descend below the baseline.
getLabel() Returns the string displayed by this object.
setFont(font) Changes the font used to display the GLabel as specified by the string font, which has the following format:
    family-style-size 
where both style and size are optional.
setLabel(str) Changes the string stored within the GLabel object, so that a new text string appears on the display.

Constructor detail


GLabel(string str);
GLabel(string str, double x, double y);
Creates a GLabel object containing the specified string. By default, the baseline of the first character appears at the origin; the second form automatically resets the location of the GLabel to the point (x, y).

Usage:

GLabel *label = new GLabel(str);
GLabel *label = new GLabel(str, x, y);

Method detail


void setFont(string font);
Changes the font used to display the GLabel as specified by the string font, which has the following format:
   family-style-size
where both style and size are optional. If any of these elements are missing or specified as an asterisk, the existing value is retained.

Usage:

label->setFont(font);

string getFont() const;
Returns the current font for the GLabel.

Usage:

string font = label->getFont();

void setLabel(string str);
Changes the string stored within the GLabel object, so that a new text string appears on the display.

Usage:

label->setLabel(str);

string getLabel() const;
Returns the string displayed by this object.

Usage:

string str = label->getLabel();

double getFontAscent() const;
Returns the maximum distance strings in this font extend above the baseline.

Usage:

double ascent = label->getFontAscent();

double getFontDescent() const;
Returns the maximum distance strings in this font descend below the baseline.

Usage:

double descent = label->getFontDescent();