Skip to content

ColoredString Class

Represents a string that has foreground and background colors for each character in the string.

C#
[DataContract]
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class ColoredString : IEnumerable<ColoredGlyphAndEffect>, IEnumerable

Inheritance object

Implements IEnumerable<ColoredGlyphAndEffect>, IEnumerable

Default constructor.

C#
public ColoredString()

Creates a new instance of the ColoredString class with the specified blank characters.

C#
public ColoredString(int capacity)

capacity int
The number of blank characters.

Creates a new instance of this class with the specified string value.

C#
public ColoredString(string value, bool treatAsString = false)

value string
The backing string.

treatAsString bool
When true, sets all of the Ignore properties to false, treating this instance as a normal string.

ColoredString(string, Color, Color, Mirror, CellDecorator[]?)

Section titled “ColoredString(string, Color, Color, Mirror, CellDecorator[]?)”

Creates a new instance of the ColoredString class with the specified string value, foreground and background colors, and a cell effect.

C#
public ColoredString(string value, Color foreground, Color background, Mirror mirror = Mirror.None, CellDecorator[]? decorators = null)

value string
The backing string.

foreground SadRogue.Primitives.Color
The foreground color for each character.

background SadRogue.Primitives.Color
The background color for each character.

mirror Mirror
The mirror for each character.

decorators CellDecorator[]
The decorators to apply to each character.

ColoredString(string, ColoredGlyphAndEffect)

Section titled “ColoredString(string, ColoredGlyphAndEffect)”

Creates a new instance of the ColoredString class with the specified string value, foreground and background colors, and a cell effect.

C#
public ColoredString(string value, ColoredGlyphAndEffect appearance)

value string
The backing string.

appearance ColoredGlyphAndEffect
The appearance to use for each character.

ColoredString(params ColoredGlyphAndEffect[])

Section titled “ColoredString(params ColoredGlyphAndEffect[])”

Combines a ColoredGlyphAndEffect array into a ColoredString.

C#
public ColoredString(params ColoredGlyphAndEffect[] glyphs)

glyphs ColoredGlyphAndEffect[]
The glyphs to combine.

Combines a ColoredGlyphBase array into a ColoredString.

C#
public ColoredString(params ColoredGlyphBase[] glyphs)

glyphs ColoredGlyphBase[]
The glyphs to combine.

Gets a ColoredGlyphAndEffect from the string.

C#
public ColoredGlyphAndEffect this[int index] { get; set; }

Gets or sets the characters representing this string. When set, first processes the string through Parse(ReadOnlySpan<char>, int, ICellSurface, ParseCommandStacks) method from Parser.

C#
public string String { get; set; }

The total number of ColoredGlyphAndEffect characters in the string.

C#
public int Length { get; }

When true, instructs a caller to not render the glyphs of the string.

C#
[DataMember]
public bool IgnoreGlyph { get; set; }

When true, instructs a caller to not render the foreground color.

C#
[DataMember]
public bool IgnoreForeground { get; set; }

When true, instructs a caller to not render the background color.

C#
[DataMember]
public bool IgnoreBackground { get; set; }

When true, instructs a caller to not render the effect.

C#
[DataMember]
public bool IgnoreEffect { get; set; }

When true, instructs a caller to not render the mirror state.

C#
[DataMember]
public bool IgnoreMirror { get; set; }

When true, instructs a caller to not render the mirror state.

C#
[DataMember]
public bool IgnoreDecorators { get; set; }

The string parser to use for transforming strings into ColoredString.

C#
public static IParser Parser { get; set; }

Returns a new ColoredString object by cloning this instance.

C#
public ColoredString Clone()

ColoredString
A new ColoredString object.

Returns a new ColoredString object using a substring of this instance from the index to the end.

C#
public ColoredString SubString(int index)

index int
The index to copy the contents from.

ColoredString
A new ColoredString object.

Returns a new ColoredString object using a substring of this instance.

C#
public ColoredString SubString(int index, int count)

index int
The index to copy the contents from.

count int
The count of ColoredGlyphAndEffect objects to copy.

ColoredString
A new ColoredString object.

Applies the referenced cell effect to every character in the colored string.

C#
public void SetEffect(ICellEffect? effect)

effect ICellEffect
The effect to apply.

Applies the referenced color to every character foreground in the colored string.

C#
public void SetForeground(Color color)

color SadRogue.Primitives.Color
The color to apply.

Applies the referenced color to every character background in the colored string.

C#
public void SetBackground(Color color)

color SadRogue.Primitives.Color
The color to apply.

Applies the referenced glyph to every character in the colored string.

C#
public void SetGlyph(int glyph)

glyph int
The glyph to apply.

Applies the mirror value to each character in the colored string.

C#
public void SetMirror(Mirror mirror)

mirror Mirror
The mirror mode.

Applies the decorators to each character in the colored string.

C#
public void SetDecorators(IEnumerable<CellDecorator> decorators)

decorators IEnumerable<CellDecorator>
The decorators.

Applies the decorators to each character in the colored string.

C#
public void SetDecorators(params CellDecorator[] decorators)

decorators CellDecorator[]
The decorators.

Returns a string representing the glyphs in this object.

C#
public override string ToString()

string
A string composed of each glyph in this object.

Gets an enumerator for the ColoredGlyphAndEffect objects in this string.

C#
public IEnumerator<ColoredGlyphAndEffect> GetEnumerator()

IEnumerator<ColoredGlyphAndEffect>
The enumerator in the string.

Creates a new colored string from the specified gradient and text.

C#
public static ColoredString FromGradient(Gradient colors, string text)

colors SadRogue.Primitives.Gradient
The gradient of colors to apply to the text.

text string
The text the colored string contains.

ColoredString
A colored string.