Table of Contents

Class TokenizedString

Namespace
MLEM.Formatting
Assembly
MLEM.dll

A tokenized string that was created using a TextFormatter

public class TokenizedString : GenericDataHolder, IGenericDataHolder
Inheritance
TokenizedString
Implements
Inherited Members

Fields

AllCodes

All of the formatting codes that are applied over this tokenized string. Note that, to get a formatting code for a certain token, use AppliedCodes

public readonly Code[] AllCodes

Field Value

Code[]

RawString

The raw string that was used to create this tokenized string.

public readonly string RawString

Field Value

string

String

The RawString, but with formatting codes stripped out.

public readonly string String

Field Value

string

Tokens

The tokens that this tokenized string contains.

public readonly Token[] Tokens

Field Value

Token[]

Properties

DisplayString

The string that is actually displayed by this tokenized string. If this string has been Split(GenericFont, float, float, TextAlignment) or Truncate(GenericFont, float, float, string, TextAlignment) has been used, this string will contain the newline characters.

public string DisplayString { get; }

Property Value

string

Methods

Draw(GameTime, SpriteBatch, Vector2, GenericFont, Color, Vector2, float, float, Vector2, SpriteEffects, int?, int?)

Submit a text string of sprites for drawing in the current batch.

public void Draw(GameTime time, SpriteBatch batch, Vector2 pos, GenericFont font, Color color, Vector2 scale, float depth, float rotation = 0, Vector2 origin = default, SpriteEffects effects = SpriteEffects.None, int? startIndex = null, int? endIndex = null)

Parameters

time GameTime
batch SpriteBatch
pos Vector2
font GenericFont
color Color

A color mask.

scale Vector2

A scaling of this string.

depth float
rotation float

A rotation of this string.

origin Vector2

Center of the rotation. 0,0 by default.

effects SpriteEffects

Modificators for drawing. Can be combined.

startIndex int?
endIndex int?

Draw(GameTime, SpriteBatch, Vector2, GenericFont, Color, float, float, float, Vector2, SpriteEffects, int?, int?)

Submit a text string of sprites for drawing in the current batch.

public void Draw(GameTime time, SpriteBatch batch, Vector2 pos, GenericFont font, Color color, float scale, float depth, float rotation = 0, Vector2 origin = default, SpriteEffects effects = SpriteEffects.None, int? startIndex = null, int? endIndex = null)

Parameters

time GameTime
batch SpriteBatch
pos Vector2
font GenericFont
color Color

A color mask.

scale float

A scaling of this string.

depth float
rotation float

A rotation of this string.

origin Vector2

Center of the rotation. 0,0 by default.

effects SpriteEffects

Modificators for drawing. Can be combined.

startIndex int?
endIndex int?

GetArea(Vector2, float)

Measures the area that this entire tokenized string and all of its Tokens take up and returns it as a RectangleF.

public RectangleF GetArea(Vector2 stringPos = default, float scale = 1)

Parameters

stringPos Vector2

The position that this string is being rendered at, which will offset the resulting RectangleF.

scale float

The scale that this string is being rendered with, which will scale the resulting RectangleF.

Returns

RectangleF

The area that this tokenized string takes up.

GetTokenUnderPos(Vector2, Vector2, Vector2, GenericFont, float, Vector2, SpriteEffects)

Returns the token under the given position. This can be used for hovering effects when the mouse is over a token, etc.

public Token GetTokenUnderPos(Vector2 stringPos, Vector2 target, Vector2 scale, GenericFont font = null, float rotation = 0, Vector2 origin = default, SpriteEffects effects = SpriteEffects.None)

Parameters

stringPos Vector2

The position that the string is drawn at.

target Vector2

The position to use for checking the token.

scale Vector2

The scale that the string is drawn at.

font GenericFont

The font that the string is being drawn with. If this is null, all following parameters are ignored.

rotation float

The rotation that the string is being drawn with. If font is null, this this is ignored.

origin Vector2

The origin that the string is being drawn with. If font is null, this this is ignored.

effects SpriteEffects

The sprite effects that the string is being drawn with. If font is null, this is ignored.

Returns

Token

The token under the target position

GetTokenUnderPos(Vector2, Vector2, float, GenericFont, float, Vector2, SpriteEffects)

Returns the token under the given position. This can be used for hovering effects when the mouse is over a token, etc.

public Token GetTokenUnderPos(Vector2 stringPos, Vector2 target, float scale, GenericFont font = null, float rotation = 0, Vector2 origin = default, SpriteEffects effects = SpriteEffects.None)

Parameters

stringPos Vector2

The position that the string is drawn at.

target Vector2

The position to use for checking the token.

scale float

The scale that the string is drawn at.

font GenericFont

The font that the string is being drawn with. If this is null, all following parameters are ignored.

rotation float

The rotation that the string is being drawn with. If font is null, this this is ignored.

origin Vector2

The origin that the string is being drawn with. If font is null, this this is ignored.

effects SpriteEffects

The sprite effects that the string is being drawn with. If font is null, this is ignored.

Returns

Token

The token under the target position

Realign(GenericFont, TextAlignment)

Realigns this tokenized string using the given TextAlignment. If the alignment is Right, trailing space characters (but not Nbsp) will be removed.

public void Realign(GenericFont font, TextAlignment alignment)

Parameters

font GenericFont

The font to use for width calculations.

alignment TextAlignment

The text alignment that should be used for width calculations.

Split(GenericFont, float, float, TextAlignment)

Splits this tokenized string, inserting newline characters if the width of the string is bigger than the maximum width. Note that a tokenized string can be re-split without losing any of its actual data, as this operation merely modifies the DisplayString.

public void Split(GenericFont font, float width, float scale, TextAlignment alignment = TextAlignment.Left)

Parameters

font GenericFont

The font to use for width calculations

width float

The maximum width, in display pixels based on the font and scale

scale float

The scale to use for width measurements

alignment TextAlignment

The text alignment that should be used for width calculations

Truncate(GenericFont, float, float, string, TextAlignment)

Truncates this tokenized string, removing any additional characters that exceed the length from the displayed string. Note that a tokenized string can be re-truncated without losing any of its actual data, as this operation merely modifies the DisplayString. TruncateString(string, float, float, bool, string)

public void Truncate(GenericFont font, float width, float scale, string ellipsis = "", TextAlignment alignment = TextAlignment.Left)

Parameters

font GenericFont

The font to use for width calculations

width float

The maximum width, in display pixels based on the font and scale

scale float

The scale to use for width measurements

ellipsis string

The characters to add to the end of the string if it is too long

alignment TextAlignment

The text alignment that should be used for width calculations

Update(GameTime)

Updates the formatting codes in this formatted string, causing animations to animate etc.

public void Update(GameTime time)

Parameters

time GameTime

The game's time