nudsfml.graphics.text

$(U Text) is a drawable class that allows one to easily display some text with a custom style and color on a render target.

It inherits all the functions from $(TRANSFORMABLE_LINK): position, rotation, scale, origin. It also adds text-specific properties such as the font to use, the character size, the font style (bold, italic, underlined), the global color and the text to display of course. It also provides convenience functions to calculate the graphical size of the text, or to get the global position of a given character.

$(U Text) works in combination with the $(FONT_LINK) class, which loads and provides the glyphs (visual characters) of a given font.

The separation of $(FONT_LINK) and $(U Text) allows more flexibility and better performances: indeed a $(FONT_LINK) is a heavy resource, and any operation on it is slow (often too slow for real-time applications). On the other side, a $(U Text) is a lightweight object which can combine the glyphs data and metrics of a $(FONT_LINK) to display any text on a render target.

It is important to note that the $(U Text) instance doesn't copy the font that it uses, it only keeps a reference to it. Thus, a $(FONT_LINK) must not be destructed while it is used by a $(U Text).

See also the note on coordinates and undistorted rendering in $(TRANSFORMABLE_LINK).

Members

Classes

Text
class Text

Graphical text that can be drawn to a render target.

Examples

// Declare and load a font
auto font = new Font();
font.loadFromFile("arial.ttf");

// Create a text
auto text = new Text("hello", font);
text.setCharacterSize(30);
text.setStyle(Text.Style.Bold);
text.setColor(Color.Red);

// Draw it
window.draw(text);

See Also

$(FONT_LINK), $(TRANSFORMABLE_LINK)

Meta