ColoredString Class
Definition
Section titled “Definition”Represents a string that has foreground and background colors for each character in the string.
[DataContract][JsonObject(MemberSerialization = MemberSerialization.OptIn)]public class ColoredString : IEnumerable<ColoredGlyphAndEffect>, IEnumerableInheritance object
Implements IEnumerable<ColoredGlyphAndEffect>, IEnumerable
Constructors
Section titled “Constructors”ColoredString()
Section titled “ColoredString()”Default constructor.
public ColoredString()ColoredString(int)
Section titled “ColoredString(int)”Creates a new instance of the ColoredString class with the specified blank characters.
public ColoredString(int capacity)Parameters
Section titled “Parameters”capacity int
The number of blank characters.
ColoredString(string, bool)
Section titled “ColoredString(string, bool)”Creates a new instance of this class with the specified string value.
public ColoredString(string value, bool treatAsString = false)Parameters
Section titled “Parameters”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.
public ColoredString(string value, Color foreground, Color background, Mirror mirror = Mirror.None, CellDecorator[]? decorators = null)Parameters
Section titled “Parameters”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.
public ColoredString(string value, ColoredGlyphAndEffect appearance)Parameters
Section titled “Parameters”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.
public ColoredString(params ColoredGlyphAndEffect[] glyphs)Parameters
Section titled “Parameters”glyphs ColoredGlyphAndEffect[]
The glyphs to combine.
ColoredString(params ColoredGlyphBase[])
Section titled “ColoredString(params ColoredGlyphBase[])”Combines a ColoredGlyphBase array into a ColoredString.
public ColoredString(params ColoredGlyphBase[] glyphs)Parameters
Section titled “Parameters”glyphs ColoredGlyphBase[]
The glyphs to combine.
Properties
Section titled “Properties”this[int]
Section titled “this[int]”Gets a ColoredGlyphAndEffect from the string.
public ColoredGlyphAndEffect this[int index] { get; set; }String
Section titled “String”Gets or sets the characters representing this string. When set, first processes the string through Parse(ReadOnlySpan<char>, int, ICellSurface, ParseCommandStacks) method from Parser.
public string String { get; set; }Length
Section titled “Length”The total number of ColoredGlyphAndEffect characters in the string.
public int Length { get; }IgnoreGlyph
Section titled “IgnoreGlyph”When true, instructs a caller to not render the glyphs of the string.
[DataMember]public bool IgnoreGlyph { get; set; }IgnoreForeground
Section titled “IgnoreForeground”When true, instructs a caller to not render the foreground color.
[DataMember]public bool IgnoreForeground { get; set; }IgnoreBackground
Section titled “IgnoreBackground”When true, instructs a caller to not render the background color.
[DataMember]public bool IgnoreBackground { get; set; }IgnoreEffect
Section titled “IgnoreEffect”When true, instructs a caller to not render the effect.
[DataMember]public bool IgnoreEffect { get; set; }IgnoreMirror
Section titled “IgnoreMirror”When true, instructs a caller to not render the mirror state.
[DataMember]public bool IgnoreMirror { get; set; }IgnoreDecorators
Section titled “IgnoreDecorators”When true, instructs a caller to not render the mirror state.
[DataMember]public bool IgnoreDecorators { get; set; }Parser
Section titled “Parser”The string parser to use for transforming strings into ColoredString.
public static IParser Parser { get; set; }Methods
Section titled “Methods”Clone()
Section titled “Clone()”Returns a new ColoredString object by cloning this instance.
public ColoredString Clone()Returns
Section titled “Returns”ColoredString
A new ColoredString object.
SubString(int)
Section titled “SubString(int)”Returns a new ColoredString object using a substring of this instance from the index to the end.
public ColoredString SubString(int index)Parameters
Section titled “Parameters”index int
The index to copy the contents from.
Returns
Section titled “Returns”ColoredString
A new ColoredString object.
SubString(int, int)
Section titled “SubString(int, int)”Returns a new ColoredString object using a substring of this instance.
public ColoredString SubString(int index, int count)Parameters
Section titled “Parameters”index int
The index to copy the contents from.
count int
The count of ColoredGlyphAndEffect objects to copy.
Returns
Section titled “Returns”ColoredString
A new ColoredString object.
SetEffect(ICellEffect?)
Section titled “SetEffect(ICellEffect?)”Applies the referenced cell effect to every character in the colored string.
public void SetEffect(ICellEffect? effect)Parameters
Section titled “Parameters”effect ICellEffect
The effect to apply.
SetForeground(Color)
Section titled “SetForeground(Color)”Applies the referenced color to every character foreground in the colored string.
public void SetForeground(Color color)Parameters
Section titled “Parameters”color SadRogue.Primitives.Color
The color to apply.
SetBackground(Color)
Section titled “SetBackground(Color)”Applies the referenced color to every character background in the colored string.
public void SetBackground(Color color)Parameters
Section titled “Parameters”color SadRogue.Primitives.Color
The color to apply.
SetGlyph(int)
Section titled “SetGlyph(int)”Applies the referenced glyph to every character in the colored string.
public void SetGlyph(int glyph)Parameters
Section titled “Parameters”glyph int
The glyph to apply.
SetMirror(Mirror)
Section titled “SetMirror(Mirror)”Applies the mirror value to each character in the colored string.
public void SetMirror(Mirror mirror)Parameters
Section titled “Parameters”mirror Mirror
The mirror mode.
SetDecorators(IEnumerable<CellDecorator>)
Section titled “SetDecorators(IEnumerable<CellDecorator>)”Applies the decorators to each character in the colored string.
public void SetDecorators(IEnumerable<CellDecorator> decorators)Parameters
Section titled “Parameters”decorators IEnumerable<CellDecorator>
The decorators.
SetDecorators(params CellDecorator[])
Section titled “SetDecorators(params CellDecorator[])”Applies the decorators to each character in the colored string.
public void SetDecorators(params CellDecorator[] decorators)Parameters
Section titled “Parameters”decorators CellDecorator[]
The decorators.
ToString()
Section titled “ToString()”Returns a string representing the glyphs in this object.
public override string ToString()Returns
Section titled “Returns”string
A string composed of each glyph in this object.
GetEnumerator()
Section titled “GetEnumerator()”Gets an enumerator for the ColoredGlyphAndEffect objects in this string.
public IEnumerator<ColoredGlyphAndEffect> GetEnumerator()Returns
Section titled “Returns”IEnumerator<ColoredGlyphAndEffect>
The enumerator in the string.
FromGradient(Gradient, string)
Section titled “FromGradient(Gradient, string)”Creates a new colored string from the specified gradient and text.
public static ColoredString FromGradient(Gradient colors, string text)Parameters
Section titled “Parameters”colors SadRogue.Primitives.Gradient
The gradient of colors to apply to the text.
text string
The text the colored string contains.
Returns
Section titled “Returns”ColoredString
A colored string.