当前位置:网站首页>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
边栏推荐
- Superscalar processor design yaoyongbin Chapter 9 instruction execution excerpt
- 【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
- 30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
- What are the top-level domain names? How is it classified?
- 防红域名生成的3种方法介绍
- EPP+DIS学习之路(1)——Hello world!
- 数据库系统原理与应用教程(008)—— 数据库相关概念练习题
- Basic introduction to the 16 tabs tab control in the fleet tutorial (the tutorial includes source code)
- 清华姚班程序员,网上征婚被骂?
- [filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
猜你喜欢
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
Problem: the string and characters are typed successively, and the results conflict
Introduction and application of smoothstep in unity: optimization of dissolution effect
SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
5V串口接3.3V单片机串口怎么搞?
Hi3516 full system type burning tutorial
Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
随机推荐
什么是局域网域名?如何解析?
SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
《通信软件开发与应用》课程结业报告
<No. 8> 1816. Truncate sentences (simple)
千人规模互联网公司研发效能成功之路
Introduction to three methods of anti red domain name generation
【全栈计划 —— 编程语言之C#】基础入门知识一文懂
Fleet tutorial 15 introduction to GridView Basics (tutorial includes source code)
[neural network] convolutional neural network CNN [including Matlab source code 1932]
总结了200道经典的机器学习面试题(附参考答案)
Use references
Hi3516全系统类型烧录教程
The road to success in R & D efficiency of 1000 person Internet companies
Camera calibration (2): summary of monocular camera calibration
Summed up 200 Classic machine learning interview questions (with reference answers)
College entrance examination composition, high-frequency mention of science and Technology
Improve application security through nonce field of play integrity API
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
Apache installation problem: configure: error: APR not found Please read the documentation
18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)