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§
source§impl<'s> Text<'s>
impl<'s> Text<'s>
sourcepub fn new<S: SfStrConv>(
string: S,
font: &'s Font,
character_size: u32
) -> Text<'s>
pub fn new<S: SfStrConv>(
string: S,
font: &'s Font,
character_size: u32
) -> Text<'s>
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
sourcepub fn set_string<S: SfStrConv>(&mut self, string: S)
pub fn set_string<S: SfStrConv>(&mut self, string: S)
sourcepub fn character_size(&self) -> u32
pub fn character_size(&self) -> u32
Get the size of the characters
Return the size of the characters
sourcepub fn set_font(&mut self, font: &'s Font)
pub fn set_font(&mut self, font: &'s Font)
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
sourcepub fn set_style(&mut self, style: TextStyle)
pub fn set_style(&mut self, style: TextStyle)
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
sourcepub fn set_character_size(&mut self, size: u32)
pub fn set_character_size(&mut self, size: u32)
Set the size of the characters of a text
The default size is 30.
Arguments
- size - The new character size, in pixels
sourcepub fn style(&self) -> TextStyle
pub fn style(&self) -> TextStyle
Get the style of a text
Return the current string style (see Style enum)
sourcepub fn font(&self) -> Option<&'s Font>
pub fn font(&self) -> Option<&'s Font>
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.
sourcepub fn set_fill_color(&mut self, color: Color)
pub fn set_fill_color(&mut self, color: Color)
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.
sourcepub fn set_outline_color(&mut self, color: Color)
pub fn set_outline_color(&mut self, color: Color)
Set the outline color of the text.
By default, the text’s outline color is opaque black.
sourcepub fn set_outline_thickness(&mut self, thickness: f32)
pub fn set_outline_thickness(&mut self, thickness: f32)
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.
sourcepub fn fill_color(&self) -> Color
pub fn fill_color(&self) -> Color
Returns the fill color of the text.
sourcepub fn outline_color(&self) -> Color
pub fn outline_color(&self) -> Color
Returns the outline color of the text.
sourcepub fn outline_thickness(&self) -> f32
pub fn outline_thickness(&self) -> f32
Returns the outline thickness of the text, in pixels.
sourcepub fn find_character_pos(&self, index: usize) -> Vector2f
pub fn find_character_pos(&self, index: usize) -> Vector2f
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
sourcepub fn local_bounds(&self) -> FloatRect
pub fn local_bounds(&self) -> FloatRect
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
sourcepub fn global_bounds(&self) -> FloatRect
pub fn global_bounds(&self) -> FloatRect
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
sourcepub fn line_spacing(&self) -> f32
pub fn line_spacing(&self) -> f32
Get the size of the line spacing factor.
sourcepub fn set_line_spacing(&mut self, factor: f32)
pub fn set_line_spacing(&mut self, factor: f32)
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.
sourcepub fn letter_spacing(&self) -> f32
pub fn letter_spacing(&self) -> f32
Get the size of the letter spacing factor.
sourcepub fn set_letter_spacing(&mut self, factor: f32)
pub fn set_letter_spacing(&mut self, factor: f32)
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.