Class Paragraph
A paragraph element for use inside of a UiSystem. A paragraph is an element that contains text. A paragraph's text can be formatted using the ui system's TextFormatter.
public class Paragraph : Element, IGenericDataHolder
- Inheritance
-
Paragraph
- Implements
- Inherited Members
- Extension Methods
Constructors
Paragraph(Anchor, float, TextCallback, TextAlignment, bool)
Creates a new paragraph with the given settings.
public Paragraph(Anchor anchor, float width, Paragraph.TextCallback textCallback, TextAlignment alignment, bool autoAdjustWidth = false)
Parameters
anchor
AnchorThe paragraph's anchor
width
floatThe paragraph's width. Note that its height is automatically calculated.
textCallback
Paragraph.TextCallbackThe paragraph's text
alignment
TextAlignmentThe paragraph's text alignment.
autoAdjustWidth
boolWhether the paragraph's width should automatically be calculated based on the text within it.
Paragraph(Anchor, float, TextCallback, bool)
Creates a new paragraph with the given settings.
public Paragraph(Anchor anchor, float width, Paragraph.TextCallback textCallback, bool autoAdjustWidth = false)
Parameters
anchor
AnchorThe paragraph's anchor
width
floatThe paragraph's width. Note that its height is automatically calculated.
textCallback
Paragraph.TextCallbackThe paragraph's text
autoAdjustWidth
boolWhether the paragraph's width should automatically be calculated based on the text within it.
Paragraph(Anchor, float, string, TextAlignment, bool)
Creates a new paragraph with the given settings.
public Paragraph(Anchor anchor, float width, string text, TextAlignment alignment, bool autoAdjustWidth = false)
Parameters
anchor
AnchorThe paragraph's anchor
width
floatThe paragraph's width. Note that its height is automatically calculated.
text
stringThe paragraph's text
alignment
TextAlignmentThe paragraph's text alignment.
autoAdjustWidth
boolWhether the paragraph's width should automatically be calculated based on the text within it.
Paragraph(Anchor, float, string, bool)
Creates a new paragraph with the given settings.
public Paragraph(Anchor anchor, float width, string text, bool autoAdjustWidth = false)
Parameters
anchor
AnchorThe paragraph's anchor
width
floatThe paragraph's width. Note that its height is automatically calculated.
text
stringThe paragraph's text
autoAdjustWidth
boolWhether the paragraph's width should automatically be calculated based on the text within it.
Fields
DrawEndIndex
The exclusive index in this paragraph's Text to stop drawing at. This value is passed to Draw(GameTime, SpriteBatch, Vector2, GenericFont, Color, Vector2, float, float, Vector2, SpriteEffects, int?, int?).
public int? DrawEndIndex
Field Value
- int?
DrawStartIndex
The inclusive index in this paragraph's Text to start drawing at. This value is passed to Draw(GameTime, SpriteBatch, Vector2, GenericFont, Color, Vector2, float, float, Vector2, SpriteEffects, int?, int?).
public int? DrawStartIndex
Field Value
- int?
GetTextCallback
An event that gets called when this paragraph's Text is queried. Use this event for setting this paragraph's text if it changes frequently.
public Paragraph.TextCallback GetTextCallback
Field Value
LinkAction
The action that is executed if Paragraph.Link objects inside of this paragraph are pressed. By default, OpenLinkOrFile(string) is executed.
public Action<Paragraph.Link, LinkCode> LinkAction
Field Value
TextColor
The color that the text will be rendered with
public StyleProp<Color> TextColor
Field Value
- StyleProp<Color>
Properties
Alignment
The TextAlignment that this paragraph's text should be rendered with
public StyleProp<TextAlignment> Alignment { get; set; }
Property Value
AutoAdjustWidth
If this paragraph should automatically adjust its width based on the width of the text within it
public bool AutoAdjustWidth { get; set; }
Property Value
Ellipsis
The ellipsis characters to use if TruncateIfLong is enabled and the string is truncated. If this is set to an empty string, no ellipsis will be attached to the truncated string.
public string Ellipsis { get; set; }
Property Value
IsHidden
Set this property to true
to cause this element to be hidden.
Hidden elements don't receive input events, aren't rendered and don't factor into auto-anchoring.
public override bool IsHidden { get; }
Property Value
RegularFont
public StyleProp<GenericFont> RegularFont { get; set; }
Property Value
Text
The text to render inside of this paragraph. Use GetTextCallback if the text changes frequently.
public string Text { get; set; }
Property Value
TextScale
The scale that the text will be rendered with. To add a multiplier rather than changing the scale directly, use TextScaleMultiplier.
public StyleProp<float> TextScale { get; set; }
Property Value
TextScaleMultiplier
public float TextScaleMultiplier { get; set; }
Property Value
TokenizedText
The tokenized version of the Text
public TokenizedString TokenizedText { get; }
Property Value
TruncateIfLong
Whether this paragraph should be truncated instead of split if the displayed Text's width exceeds the provided width. When the string is truncated, the Ellipsis is added to its end.
public bool TruncateIfLong { get; set; }
Property Value
Methods
CalcActualSize(RectangleF)
Calculates the actual size that this element should take up, based on the area that its parent encompasses. By default, this is based on the information specified in Size's documentation.
protected override Vector2 CalcActualSize(RectangleF parentArea)
Parameters
parentArea
RectangleFThis parent's area, or the ui system's viewport if it has no parent
Returns
- Vector2
The actual size of this element, taking Scale into account
Draw(GameTime, SpriteBatch, float, SpriteBatchContext)
Draws this element and all of its children. Override this method to draw the content of custom elements.
Note that, when this is called, SpriteBatch.Begin
has already been called with custom Transform etc. applied.
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context)
Parameters
time
GameTimeThe game's time
batch
SpriteBatchThe sprite batch to use for drawing
alpha
floatThe alpha to draw this element and its children with
context
SpriteBatchContextThe sprite batch context to use for drawing
InitStyle(UiStyle)
Initializes this element's StyleProp<T> instances using the ui system's UiStyle.
protected override void InitStyle(UiStyle style)
Parameters
style
UiStyleThe new style
SetAreaAndUpdateChildren(RectangleF)
Sets this element's Area to the given RectangleF and invokes the OnElementAreaUpdated event. This method also updates all of this element's Children's areas. Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all.
public override void SetAreaAndUpdateChildren(RectangleF area)
Parameters
area
RectangleF
- See Also
Update(GameTime)
Updates this element and all of its SortedChildren
public override void Update(GameTime time)
Parameters
time
GameTimeThe game's time