当前位置:网站首页>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 .
- UILabel The core approach
- ProcessText
- technological process
- 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 .
- call
NGUIText.Update(false)
: Update the size of the final font 、 Character spacingfinalSpacingX
、 Row heightfinalLineHeight
And whether to use runes and other information . - 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.
- call
- call NGUIText.CalculatePrintedSize(mProcessedText):
- According to the displayed text mProcessedText And character spacing
finalSpacingX
、 Row heightfinalLineHeight
Get the display rect size
- According to the displayed text mProcessedText And character spacing
- According to the different OverFlow Type calculation Label Width and height .
- OverFlow Treatment mode
- 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 . - 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 callNGUIText.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 NGUITextNGUIText.Print(text, verts, uvs, cols)
: Fill the geometry data into the cache according to the displayed textApplyOffset
: 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 .
- Effect.Shadow: shadow ; call
- 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
- glyph The two vertices of glyph.v0 and glyph.v1 Multiply by a proportional value
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
- ResizeFreely: Adaptive width and height ; Call call
边栏推荐
- What is high cohesion and low coupling?
- 110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
- Sonar:cognitive complexity
- Completion report of communication software development and Application
- 【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)
- DOM parsing XML error: content is not allowed in Prolog
- 《通信软件开发与应用》课程结业报告
- MATLAB实现Huffman编码译码含GUI界面
- Baidu digital person Du Xiaoxiao responded to netizens' shouts online to meet the Shanghai college entrance examination English composition
猜你喜欢
5V串口接3.3V单片机串口怎么搞?
千人规模互联网公司研发效能成功之路
EPP+DIS学习之路(1)——Hello world!
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
zero-shot, one-shot和few-shot
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
Flet tutorial 17 basic introduction to card components (tutorial includes source code)
一起探索云服务之云数据库
Detailed explanation of debezium architecture of debezium synchronization
随机推荐
How to understand the clothing industry chain and supply chain
Tsinghua Yaoban programmers, online marriage was scolded?
Hi3516全系统类型烧录教程
EPP+DIS学习之路(1)——Hello world!
PowerShell cs-utf-16le code goes online
How to connect 5V serial port to 3.3V MCU serial port?
112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
Summed up 200 Classic machine learning interview questions (with reference answers)
111. Network security penetration test - [privilege escalation 9] - [windows 2008 R2 kernel overflow privilege escalation]
Introduction to three methods of anti red domain name generation
2022年在启牛开华泰的账户安全吗?
DOM parsing XML error: content is not allowed in Prolog
2022 8th "certification Cup" China University risk management and control ability challenge
What are the technical differences in source code anti disclosure
About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection
Visual studio 2019 (localdb) \mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports version 782 and earlier
数据库系统原理与应用教程(008)—— 数据库相关概念练习题
Sonar:cognitive complexity
zero-shot, one-shot和few-shot
如何理解服装产业链及供应链