SimpleCxxLib
packageclass GLabel : public GObject
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:
Constructor | |
GLabel(str, x, y) | Creates a GLabel object containing the specified string. |
Methods | |
Returns the current font for the GLabel . | |
Returns the maximum distance strings in this font extend above the baseline. | |
Returns the maximum distance strings in this font descend below the baseline. | |
Returns the string displayed by this object. | |
Changes the font used to display the GLabel as specified by the string font , which has the following format: family-style-sizewhere both style and size are optional. | |
Changes the string stored within the GLabel object, so that a new text string appears on the display. |
GLabel(string str); GLabel(string str, double x, double y);
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);
void setFont(string font);
GLabel
as specified by
the string font
, which has the following format:
family-style-sizewhere 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;
GLabel
.
Usage:
string font = label->getFont();
void setLabel(string str);
GLabel
object, so that
a new text string appears on the display.
Usage:
label->setLabel(str);
string getLabel() const;
Usage:
string str = label->getLabel();
double getFontAscent() const;
Usage:
double ascent = label->getFontAscent();
double getFontDescent() const;
Usage:
double descent = label->getFontDescent();