Struct sfml::graphics::Text

source ·
pub struct Text<'s> { /* private fields */ }
Expand description

Graphical text

Text is a drawable type that allows to easily display some text with custom style and color on a render target.

Note: Currently, it is not feasible to store text long term. A common pattern with rust-sfml is to create a Text right before you start drawing, and draw all the text you want with it. You can change its properties using set_font, set_position, set_string, etc., before drawing it, as many times as you need to.

Implementations§

Create a new text with initialized value

Default value for characterSize on SFML is 30.

Arguments
  • string - The string of the text
  • font - The font to display the Text
  • characterSize - The size of the Text

Set the string of a text

A text’s string is empty by default.

Arguments
  • string - New string

Get the string of a text

Get the size of the characters

Return the size of the characters

Set the font of the text

The font argument refers to a texture that must exist as long as the text uses it. Indeed, the text doesn’t store its own copy of the font, but rather keeps a pointer to the one that you passed to this function. If the font is destroyed and the text tries to use it, the behaviour is undefined.

font - New font

Set the style of a text

You can pass a combination of one or more styles, for example Bold | Italic. The default style is Regular.

Arguments
  • style - New style

Set the size of the characters of a text

The default size is 30.

Arguments
  • size - The new character size, in pixels

Get the style of a text

Return the current string style (see Style enum)

Get the font of a text If the text has no font attached, a None is returned. The returned pointer is const, which means that you can’t modify the font when you retrieve it with this function.

Set the fill color of the text.

By default, the text’s fill color is opaque white. Setting the fill color to a transparent color with an outline will cause the outline to be displayed in the fill area of the text.

Set the outline color of the text.

By default, the text’s outline color is opaque black.

Set the thickness of the text’s outline.

By default, the outline thickness is 0.

Be aware that using a negative value for the outline thickness will cause distorted rendering.

Returns the fill color of the text.

Returns the outline color of the text.

Returns the outline thickness of the text, in pixels.

Return the position of the index-th character in a text

This function computes the visual position of a character from its index in the string. The returned position is in global coordinates (translation, rotation, scale and origin are applied). If index is out of range, the position of the end of the string is returned.

Arguments
  • index - The index of the character

Return the position of the character

Get the local bounding rectangle of a text

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, …) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity’s coordinate system.

Return the local bounding rectangle of the entity

Get the global bounding rectangle of a text

The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, …) that are applied to the entity. In other words, this function returns the bounds of the text in the global 2D world’s coordinate system.

Return the global bounding rectangle of the entity

Get the size of the line spacing factor.

Set the line spacing factor.

The default spacing between lines is defined by the font. This method enables you to set a factor for the spacing between lines. By default the line spacing factor is 1.

Get the size of the letter spacing factor.

Set the letter spacing factor.

The default spacing between letters is defined by the font. This factor doesn’t directly apply to the existing spacing between each character, it rather adds a fixed space between them which is calculated from the font metrics and the character size. Note that factors below 1 (including negative numbers) bring characters closer to each other. By default the letter spacing factor is 1.

Trait Implementations§

Return a new Text or panic! if there is not enough memory

Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Draws into target with RenderStates states.
Executes the destructor for this type. Read more
Sets the position of the object. Read more
Set the orientation of the object. Read more
Sets the scale factors of the object. Read more
Sets the local origin of the object. Read more
Gets the position of the object.
Gets the rotation of the object. Read more
Gets the current scale of the object.
Gets the local origin of the object.
Moves the object by a given offset. Read more
Rotates the object. Read more
Scales the object. Read more
Gets the combined transform of the object.
Gets the inverse combined transform of the object.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.