当前位置:网站首页>NGUI-UILabel

NGUI-UILabel

2022-07-07 12:11:00 Taotaotaotao

1.1 summary
UILabel yes NGUI Components used for text display in , Support graphic display , Rich text and other functions . Please familiarize yourself with NGUI The basic usage and basic properties of .

Basic properties
Overflow type
Effect type
Font type
Alignment mode
Graphic style
The gradient
Margin
Support rich text
Multiple rows and maximum rows

The basic principle

  • There are two font schemes :Unity Dynamic fonts (trueTypeFont,TTF) and NGUI Of BitmapFont(BMFont
  • UILabel maintain mShouldBeProcessed Of bool Variable , When setting basic properties, you will mShouldBeProcessed Set to true, And override the parent class UIWidget Properties of drawingDimensions、localCorners、worldCorners、localSize And methods GetSides Medium judgement shouldBeProcessed Is it true, by true Call UILabel Of ProcessText Recalculate the information and redraw .
  • NGUIText As an auxiliary class , Is a static class , Because there are many parameters for drawing text , By its parameter cache and corresponding calculation method , Reduce the corresponding memory consumption .

  1. UILabel The core approach
  2. ProcessText
  3. technological process
  4. Calculation UILabel Set the rectangle size and the actual displayed rectangle size , Its setting rectangle size is also subject to OverFlow Impact of type , If the type is Overflow.ResizeFreely perhaps Overflow.ResizeHeight The corresponding setting size is not affected by the current width height The limitation of .
  5. call NGUIText.Update(false): Update the size of the final font 、 Character spacing finalSpacingX、 Row height finalLineHeight And whether to use runes and other information .
  6. Enable for Cycle continuously decreasing font size
    • call NGUIText.WrapText(mText, out mProcessedText, true);
      • according to regionHeight、finalLineHeight and maxLines To calculate the Label Maximum number of rows to display ; Constantly traverse characters , analysis BBCode Skip characters for rich text settings , Distinguish between ordinary characters and graphic characters, and calculate their font size respectively glyphWidth, Maintain the remaining width of each line remainingWidth, When the width is insufficient, wrap , Finally back to Label Whether to accommodate all text , And get the final displayed text finalText.
  7. call NGUIText.CalculatePrintedSize(mProcessedText):
    • According to the displayed text mProcessedText And character spacing finalSpacingX、 Row height finalLineHeight Get the display rect size
  8. According to the different OverFlow Type calculation Label Width and height .
  9. OverFlow Treatment mode
  10. ShrinkContent: Zoom content ; Decreasing mPrintedSize call NGUIText.WrapText(mText, out mProcessedText, true); Judge whether the current font size can display all text , Until the conditions are met or the font size cannot be reduced .
  11. ClampContent: Cut content ; Call call NGUIText.WrapText(mText, out mProcessedText, true); Get the final displayed text .
    • ResizeFreely: Adaptive width and height ; Call call NGUIText.WrapText(mText, out mProcessedText, true); Get the final displayed text . And call NGUIText.CalculatePrintedSize(mProcessedText); Get the displayed size , Recalculate widget The width and height of
    • ResizeHeight: Adaptive height ; similar ResizeFreely, Just recalculate widget Height .
    • OnFill technological process
    • UpdateNGUIText: Update settings current UILabel Attribute to NGUIText
    • NGUIText.Print(text, verts, uvs, cols): Fill the geometry data into the cache according to the displayed text
    • ApplyOffset: according to Pivot Type adjust vertex position
    • about Effect Not None situation , Here are 3 There are three types of principles
      • Effect.Shadow: shadow ; call ApplyShadow Add shadow processing ,ApplyShadow The function of is to fill in the current UILabel The final displayed text vertex 、UV、Color Fill in the data again , The vertex is the basis UILabel Of mEffectDistance The corresponding deviation processing should be done for the attribute of ,Effect.Shadow It's lower right , So it presents a shadow effect .
      • Effect.Outline: Stroke ; call ApplyShadow increase 4 Shadow processing in two directions , They are lower right , Top left , The upper right , The lower left , It is equivalent to tracing
      • Effect.Outline8:8 Stroke in two directions , Be similar to Effect.Outline, The direction increases to the right relative to the front , Right up , Right left , Straight down .
    • Prepare: When using dynamic fonts , call Font.RequestCharactersInTexture Refresh the texture of the desired character
    • Traverse text Every character of
    • Handle line breaks Do not handle illegal characters
    • ParseSymbol analysis BBCode: This function has multiple ref value , Respectively subscriptMode The subscript ,bold In bold ,italic Italics , underline Underline , strikethrough Center line , ignoreColor Ignore widget The color of the , That is, use the color of rich text .
    • GetSymbol: Get the corresponding graphic character information , If there is no match, it returns null
      • Handle graphic characters

        • Calculate the display range of symbol text
        • If the width cannot accommodate Line break
        • Add vertex 、UV、Color Information to cache
        • among SymbolStyle be equal to Colored When , The color of the pattern uses the current font color , In which case, only the current alpha value ,rgb All channels are 255.
      • Handle ordinary characters

        • GetGlyph(ch, prev); Get font information , According to the use of bitmapFont still dynamicFont Calculate the font data GlyphInfo, It contains the vertex coordinates of the font ,uv Coordinates and colors channel Channel settings .

      • There are superscripts and subscripts

        • glyph The two vertices of glyph.v0 and glyph.v1 Multiply by a proportional value sizeShrinkage All shrink , Reduce the vertex range
        • Shift vertices up and down according to superscript or subscript Y coordinate
      • If the width is not enough Line feed

      • If the character is a space : if BBCode The corresponding is underline , Is replaced by “ Underline ”; If the corresponding middle line , None of them correspond , be continue

      • Handle texture coordinates : Add texture coordinates to the cache

      • according to GlyphInfo Of channel value -》 Handle vertex colors , fill Color Information

        • At present channel by 0 Or for 15 When , Deal with the gradient , The algorithm is : Calculate the font vertex y The proportion of the highest and lowest points of the axis in the overall font display , Through the color interpolation of the bottom and top of the gradient, the corresponding top and bottom color values are obtained .
      • Handle vertex coordinates according to bold and italic

        • bold Equivalent to rendering each character 4 Time , Offset the vertex coordinates
        • Italics Equivalent to each character vertex has a certain offset
      • Handle underscores or center lines

        • Get corresponding GlyphInfo Information
        • Handle similar to the above
    • Handle alignment In the case of center or right : The default is from left to right , namely Alignment.Left Method handling
      • Alignment.Right: Calculate the difference between the display width and the text width , If the difference padding Greater than 0, Set the vertex coordinates of x Coordinate offset right padding
      • Alignment.Center: Calculate half the difference between the display width and the text width padding, If the difference padding Greater than 0, Set the vertex coordinates of x Coordinate offset right padding
      • Alignment.Justified:
        • The text width needs to be greater than the display width 65%;
        • Calculate half the difference between the display width and the text width padding
        • Display characters evenly on the display area
原网站

版权声明
本文为[Taotaotaotao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071014039925.html