Class EntityTextRenderData
- Namespace
- Stride.CommunityToolkit.Rendering.Text
- Assembly
- Stride.CommunityToolkit.dll
Per-component state the text renderer keeps between frames.
public class EntityTextRenderData
- Inheritance
-
EntityTextRenderData
Remarks
This exists to hold the measured size of the text, which is needed to anchor it and to size its background, and which is far too expensive to recompute every frame for every label. Holding it here rather than in a dictionary inside the renderer is what gives it a correct lifetime: the processor creates one of these when the component is added and drops it when the component goes away, so the measurement cannot outlive what it describes.
Constructors
EntityTextRenderData(EntityTextComponent)
Per-component state the text renderer keeps between frames.
public EntityTextRenderData(EntityTextComponent component)
Parameters
componentEntityTextComponentThe component being drawn.
Remarks
This exists to hold the measured size of the text, which is needed to anchor it and to size its background, and which is far too expensive to recompute every frame for every label. Holding it here rather than in a dictionary inside the renderer is what gives it a correct lifetime: the processor creates one of these when the component is added and drops it when the component goes away, so the measurement cannot outlive what it describes.
Properties
Component
Gets the component being drawn.
public EntityTextComponent Component { get; }
Property Value
Entity
Gets the entity the component is attached to.
public Entity Entity { get; }
Property Value
Remarks
Read from the component rather than stored alongside it. A component knows its own owner for as long as it is attached, and this data only exists while it is - the processor creates it when the component arrives and drops it when it leaves - so keeping a second copy would add a way for the two to disagree without adding anything.
Methods
GetMeasuredSize(SpriteBatch, SpriteFont)
Returns the size of the component's text in pixels at FontSize, measuring it only when the text, size or font has actually changed since the last measurement.
public Vector2 GetMeasuredSize(SpriteBatch spriteBatch, SpriteFont font)
Parameters
spriteBatchSpriteBatchThe batch used to measure.
fontSpriteFontThe font the text will be drawn with.
Returns
GetMeasuredSize(SpriteBatch, SpriteFont, float)
Returns the size of the component's text in pixels at a given font size - the component's own size times the display's scale, when the renderer is following it - measuring it only when the text, size or font has actually changed since the last measurement.
public Vector2 GetMeasuredSize(SpriteBatch spriteBatch, SpriteFont font, float fontSize)
Parameters
spriteBatchSpriteBatchThe batch used to measure.
fontSpriteFontThe font the text will be drawn with.
fontSizefloatThe size the glyphs are rasterised at, in pixels.