Table of Contents

Class Paragraph

Namespace
MLEM.Ui.Elements
Assembly
MLEM.Ui.dll

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, IDisposable
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 Anchor

The paragraph's anchor

width float

The paragraph's width. Note that its height is automatically calculated.

textCallback Paragraph.TextCallback

The paragraph's text

alignment TextAlignment

The paragraph's text alignment.

autoAdjustWidth bool

Whether 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 Anchor

The paragraph's anchor

width float

The paragraph's width. Note that its height is automatically calculated.

textCallback Paragraph.TextCallback

The paragraph's text

autoAdjustWidth bool

Whether 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 Anchor

The paragraph's anchor

width float

The paragraph's width. Note that its height is automatically calculated.

text string

The paragraph's text

alignment TextAlignment

The paragraph's text alignment.

autoAdjustWidth bool

Whether 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 Anchor

The paragraph's anchor

width float

The paragraph's width. Note that its height is automatically calculated.

text string

The paragraph's text

autoAdjustWidth bool

Whether 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, float, float, 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, float, float, 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

Paragraph.TextCallback

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

Action<Paragraph.Link, LinkCode>

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

StyleProp<TextAlignment>

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

bool

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

string

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

bool

RegularFont

The font that this paragraph draws text with. To set its bold and italic font, use Bold and Italic.

public StyleProp<GenericFont> RegularFont { get; set; }

Property Value

StyleProp<GenericFont>

Text

The text to render inside of this paragraph. Use GetTextCallback if the text changes frequently.

public string Text { get; set; }

Property Value

string

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

StyleProp<float>

TextScaleMultiplier

A multiplier that will be applied to TextScale. To change the text scale itself, use TextScale.

public float TextScaleMultiplier { get; set; }

Property Value

float

TokenizedText

The tokenized version of the Text

public TokenizedString TokenizedText { get; }

Property Value

TokenizedString

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

bool

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 RectangleF

This 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 GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

alpha float

The alpha to draw this element and its children with

context SpriteBatchContext

The 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 UiStyle

The 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 GameTime

The game's time