Table of Contents

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

component EntityTextComponent

The 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

EntityTextComponent

Entity

Gets the entity the component is attached to.

public Entity Entity { get; }

Property Value

Entity

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

spriteBatch SpriteBatch

The batch used to measure.

font SpriteFont

The font the text will be drawn with.

Returns

Vector2

The width and height of the text, in pixels, before Scale.

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

spriteBatch SpriteBatch

The batch used to measure.

font SpriteFont

The font the text will be drawn with.

fontSize float

The size the glyphs are rasterised at, in pixels.

Returns

Vector2

The width and height of the text, in pixels, before Scale.