C# Class NGUIText, swip3

Show file Open project: unit9/swip3 Class Usage Examples

Public Properties

Property Type Description
alignment TextAlignment
baseline float
bitmapFont UIFont,
dynamicFont Font
encoding bool
finalLineHeight float
finalSize int
finalSpacingX float
fontScale float
fontSize int
fontStyle FontStyle,
glyph GlyphInfo
gradient bool
gradientBottom Color
gradientTop Color
maxLines int
pixelDensity float
premultiply bool
rectHeight int
rectWidth int
spacingX float
spacingY float
symbolStyle SymbolStyle
tint Color
useSymbols bool

Public Methods

Method Description
Align ( BetterList verts, int indexOffset, float offset ) : void

Align the vertices to be right or center-aligned given the line width specified by NGUIText.lineWidth.

CalculateOffsetToFit ( string text ) : int

Calculate the character index offset required to print the end of the specified text.

CalculatePrintedSize ( string text ) : Vector2

Get the printed size of the specified string. The returned value is in pixels.

EncodeColor ( Color c ) : string

The reverse of ParseColor -- encodes a color in RrGgBb format.

EndLine ( StringBuilder &s ) : void

Convenience function that ends the line by either appending a new line character or replacing a space with one.

GetClosestCharacter ( BetterList verts, Vector2 pos ) : int

Get the index of the closest character within the provided list of values. This function first sorts by Y, and only then by X.

GetEndOfLineThatFits ( string text ) : string

Get the end of line that would fit into a field of given width.

GetGlyph ( int ch, int prev ) : GlyphInfo

Get the specified glyph.

GetGlyphWidth ( int ch, int prev ) : float

Get the width of the specified glyph. Returns zero if the glyph could not be retrieved.

GetSymbol ( string text, int index, int textLength ) : BMSymbol,

Get the specified symbol.

ParseColor ( string text, int offset ) : Color

Parse a RrGgBb color encoded in the string.

ParseSymbol ( string text, int &index ) : bool

Parse an embedded symbol, such as [FFAA00] (set color) or [-] (undo color change). Returns whether the index was adjusted.

ParseSymbol ( string text, int &index, BetterList colors, bool premultiply, int &sub, bool &bold, bool &italic, bool &underline, bool &strike ) : bool

Parse the symbol, if possible. Returns 'true' if the 'index' was adjusted. Advanced symbol support contributed by Rudy Pangestu.

Prepare ( string text ) : void

Prepare to use the specified text.

Print ( string text, BetterList verts, BetterList uvs, BetterList cols ) : void

Print the specified text into the buffers.

PrintCaretAndSelection ( string text, int start, int end, BetterList caret, BetterList highlight ) : void

Print the caret and selection vertices. Note that it's expected that 'text' has been stripped clean of symbols.

PrintCharacterPositions ( string text, BetterList verts, BetterList indices ) : void

Print character positions and indices into the specified buffer. Meant to be used with the "find closest vertex" calculations.

RequestCharactersInTexture ( Font font, string text ) : void

Ensure that we have the requested characters present.

StripSymbols ( string text ) : string

Runs through the specified string and removes all color-encoding symbols.

Update ( ) : void

Recalculate the 'final' values.

Update ( bool request ) : void

Recalculate the 'final' values.

WrapText ( string text, string &finalText ) : bool

Text wrapping functionality. The 'width' and 'height' should be in pixels.

WrapText ( string text, string &finalText, bool keepCharCount ) : bool

Text wrapping functionality. The 'width' and 'height' should be in pixels.

Private Methods

Method Description
ReplaceSpaceWithNewline ( StringBuilder &s ) : void

Convenience function that ends the line by replacing a space with a newline character.

Method Details

Align() static public method

Align the vertices to be right or center-aligned given the line width specified by NGUIText.lineWidth.
static public Align ( BetterList verts, int indexOffset, float offset ) : void
verts BetterList
indexOffset int
offset float
return void

CalculateOffsetToFit() static public method

Calculate the character index offset required to print the end of the specified text.
static public CalculateOffsetToFit ( string text ) : int
text string
return int

CalculatePrintedSize() static public method

Get the printed size of the specified string. The returned value is in pixels.
static public CalculatePrintedSize ( string text ) : Vector2
text string
return Vector2

EncodeColor() static public method

The reverse of ParseColor -- encodes a color in RrGgBb format.
static public EncodeColor ( Color c ) : string
c Color
return string

EndLine() static public method

Convenience function that ends the line by either appending a new line character or replacing a space with one.
static public EndLine ( StringBuilder &s ) : void
s StringBuilder
return void

GetClosestCharacter() static public method

Get the index of the closest character within the provided list of values. This function first sorts by Y, and only then by X.
static public GetClosestCharacter ( BetterList verts, Vector2 pos ) : int
verts BetterList
pos Vector2
return int

GetEndOfLineThatFits() static public method

Get the end of line that would fit into a field of given width.
static public GetEndOfLineThatFits ( string text ) : string
text string
return string

GetGlyph() static public method

Get the specified glyph.
static public GetGlyph ( int ch, int prev ) : GlyphInfo
ch int
prev int
return GlyphInfo

GetGlyphWidth() static public method

Get the width of the specified glyph. Returns zero if the glyph could not be retrieved.
static public GetGlyphWidth ( int ch, int prev ) : float
ch int
prev int
return float

GetSymbol() static public method

Get the specified symbol.
static public GetSymbol ( string text, int index, int textLength ) : BMSymbol,
text string
index int
textLength int
return BMSymbol,

ParseColor() static public method

Parse a RrGgBb color encoded in the string.
static public ParseColor ( string text, int offset ) : Color
text string
offset int
return Color

ParseSymbol() static public method

Parse an embedded symbol, such as [FFAA00] (set color) or [-] (undo color change). Returns whether the index was adjusted.
static public ParseSymbol ( string text, int &index ) : bool
text string
index int
return bool

ParseSymbol() static public method

Parse the symbol, if possible. Returns 'true' if the 'index' was adjusted. Advanced symbol support contributed by Rudy Pangestu.
static public ParseSymbol ( string text, int &index, BetterList colors, bool premultiply, int &sub, bool &bold, bool &italic, bool &underline, bool &strike ) : bool
text string
index int
colors BetterList
premultiply bool
sub int
bold bool
italic bool
underline bool
strike bool
return bool

Prepare() static public method

Prepare to use the specified text.
static public Prepare ( string text ) : void
text string
return void

Print() static public method

Print the specified text into the buffers.
static public Print ( string text, BetterList verts, BetterList uvs, BetterList cols ) : void
text string
verts BetterList
uvs BetterList
cols BetterList
return void

PrintCaretAndSelection() static public method

Print the caret and selection vertices. Note that it's expected that 'text' has been stripped clean of symbols.
static public PrintCaretAndSelection ( string text, int start, int end, BetterList caret, BetterList highlight ) : void
text string
start int
end int
caret BetterList
highlight BetterList
return void

PrintCharacterPositions() static public method

Print character positions and indices into the specified buffer. Meant to be used with the "find closest vertex" calculations.
static public PrintCharacterPositions ( string text, BetterList verts, BetterList indices ) : void
text string
verts BetterList
indices BetterList
return void

RequestCharactersInTexture() static public method

Ensure that we have the requested characters present.
static public RequestCharactersInTexture ( Font font, string text ) : void
font Font
text string
return void

StripSymbols() static public method

Runs through the specified string and removes all color-encoding symbols.
static public StripSymbols ( string text ) : string
text string
return string

Update() static public method

Recalculate the 'final' values.
static public Update ( ) : void
return void

Update() static public method

Recalculate the 'final' values.
static public Update ( bool request ) : void
request bool
return void

WrapText() static public method

Text wrapping functionality. The 'width' and 'height' should be in pixels.
static public WrapText ( string text, string &finalText ) : bool
text string
finalText string
return bool

WrapText() static public method

Text wrapping functionality. The 'width' and 'height' should be in pixels.
static public WrapText ( string text, string &finalText, bool keepCharCount ) : bool
text string
finalText string
keepCharCount bool
return bool

Property Details

alignment static public property

static public TextAlignment alignment
return TextAlignment

baseline static public property

static public float baseline
return float

bitmapFont static public property

When printing text, a lot of additional data must be passed in. In order to save allocations, this data is not passed at all, but is rather set in a single place before calling the functions that use it.
static public UIFont, bitmapFont
return UIFont,

dynamicFont static public property

static public Font dynamicFont
return Font

encoding static public property

static public bool encoding
return bool

finalLineHeight static public property

static public float finalLineHeight
return float

finalSize static public property

static public int finalSize
return int

finalSpacingX static public property

static public float finalSpacingX
return float

fontScale static public property

static public float fontScale
return float

fontSize static public property

static public int fontSize
return int

fontStyle static public property

static public FontStyle, fontStyle
return FontStyle,

glyph static public property

static public GlyphInfo glyph
return GlyphInfo

gradient static public property

static public bool gradient
return bool

gradientBottom static public property

static public Color gradientBottom
return Color

gradientTop static public property

static public Color gradientTop
return Color

maxLines static public property

static public int maxLines
return int

pixelDensity static public property

static public float pixelDensity
return float

premultiply static public property

static public bool premultiply
return bool

rectHeight static public property

static public int rectHeight
return int

rectWidth static public property

static public int rectWidth
return int

spacingX static public property

static public float spacingX
return float

spacingY static public property

static public float spacingY
return float

symbolStyle static public property

static public SymbolStyle symbolStyle
return SymbolStyle

tint static public property

static public Color tint
return Color

useSymbols static public property

static public bool useSymbols
return bool