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
The RawString, but with formatting codes stripped out.
public readonly string String
Field Value
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
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
timeGameTimebatchSpriteBatchposVector2fontGenericFontcolorColorA color mask.
scaleVector2A scaling of this string.
depthfloatrotationfloatA rotation of this string.
originVector2Center of the rotation. 0,0 by default.
effectsSpriteEffectsModificators for drawing. Can be combined.
startIndexint?endIndexint?
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
timeGameTimebatchSpriteBatchposVector2fontGenericFontcolorColorA color mask.
scalefloatA scaling of this string.
depthfloatrotationfloatA rotation of this string.
originVector2Center of the rotation. 0,0 by default.
effectsSpriteEffectsModificators for drawing. Can be combined.
startIndexint?endIndexint?
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
stringPosVector2The position that this string is being rendered at, which will offset the resulting RectangleF.
scalefloatThe 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
stringPosVector2The position that the string is drawn at.
targetVector2The position to use for checking the token.
scaleVector2The scale that the string is drawn at.
fontGenericFontThe font that the string is being drawn with. If this is null, all following parameters are ignored.
rotationfloatThe rotation that the string is being drawn with. If
fontis null, this this is ignored.originVector2The origin that the string is being drawn with. If
fontis null, this this is ignored.effectsSpriteEffectsThe sprite effects that the string is being drawn with. If
fontis 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
stringPosVector2The position that the string is drawn at.
targetVector2The position to use for checking the token.
scalefloatThe scale that the string is drawn at.
fontGenericFontThe font that the string is being drawn with. If this is null, all following parameters are ignored.
rotationfloatThe rotation that the string is being drawn with. If
fontis null, this this is ignored.originVector2The origin that the string is being drawn with. If
fontis null, this this is ignored.effectsSpriteEffectsThe sprite effects that the string is being drawn with. If
fontis 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
fontGenericFontThe font to use for width calculations.
alignmentTextAlignmentThe 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
fontGenericFontThe font to use for width calculations
widthfloatThe maximum width, in display pixels based on the font and scale
scalefloatThe scale to use for width measurements
alignmentTextAlignmentThe 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
fontGenericFontThe font to use for width calculations
widthfloatThe maximum width, in display pixels based on the font and scale
scalefloatThe scale to use for width measurements
ellipsisstringThe characters to add to the end of the string if it is too long
alignmentTextAlignmentThe 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
timeGameTimeThe game's time