-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【don't merge】UI subsystem additions #15890
Changes from all commits
9a44d15
c3a318f
5db43b0
b3526b9
115e5f6
293b665
1f224fa
cc36e02
ce2eb7d
1bf1d16
f640f84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,104 +23,132 @@ | |
*/ | ||
|
||
import { JSB } from 'internal:constants'; | ||
import { IConfig, FontAtlas } from '../../assets/bitmap-font'; | ||
import { FontAtlas, BitmapFont } from '../../assets/bitmap-font'; | ||
import { SpriteFrame } from '../../assets/sprite-frame'; | ||
import { Rect, error } from '../../../core'; | ||
import { Rect, Vec2, error } from '../../../core'; | ||
import { Label, Overflow, CacheMode } from '../../components/label'; | ||
import { UITransform } from '../../framework/ui-transform'; | ||
import { LetterAtlas, shareLabelInfo } from './font-utils'; | ||
import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager'; | ||
import { TextProcessing } from './text-processing'; | ||
import { TextOutputLayoutData, TextOutputRenderData } from './text-output-data'; | ||
import { TextStyle } from './text-style'; | ||
import { TextLayout } from './text-layout'; | ||
import { view } from '../../../ui/view'; | ||
|
||
const _defaultLetterAtlas = new LetterAtlas(64, 64); | ||
const _defaultFontAtlas = new FontAtlas(null); | ||
|
||
let _comp: Label | null = null; | ||
let _uiTrans: UITransform | null = null; | ||
|
||
let _fntConfig: IConfig | null = null; | ||
let _spriteFrame: SpriteFrame|null = null; | ||
let QUAD_INDICES; | ||
|
||
export const bmfontUtils = { | ||
|
||
updateProcessingData (style: TextStyle, layout: TextLayout, | ||
outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData, | ||
comp: Label, trans: UITransform): void { | ||
style.fontSize = comp.fontSize; | ||
style.actualFontSize = comp.fontSize; | ||
style.originFontSize = _fntConfig ? _fntConfig.fontSize : comp.fontSize; | ||
layout.horizontalAlign = comp.horizontalAlign; | ||
layout.verticalAlign = comp.verticalAlign; | ||
layout.spacingX = comp.spacingX; | ||
updateLayoutProcessingData ( | ||
style: TextStyle, | ||
layout: TextLayout, | ||
outputLayoutData: TextOutputLayoutData, | ||
comp: Label, | ||
trans: UITransform, | ||
): void { | ||
style.fontSize = comp.fontSize; //both | ||
style.actualFontSize = comp.fontSize; //both | ||
layout.horizontalAlign = comp.horizontalAlign; //both | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like the options in the layout are also part of the style, maybe merge the layout into the style? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In design, style should only affect rendering, but because of the use of canvas, some rendering-related information is needed in the layout, and there is actually information that affects both rendering and layout, so it can't be completely separated. |
||
layout.verticalAlign = comp.verticalAlign; //both | ||
layout.spacingX = comp.spacingX; // layout only | ||
const overflow = comp.overflow; | ||
layout.overFlow = overflow; | ||
layout.lineHeight = comp.lineHeight; | ||
|
||
outputLayoutData.nodeContentSize.width = trans.width; | ||
outputLayoutData.nodeContentSize.height = trans.height; | ||
layout.overFlow = overflow; // both | ||
layout.lineHeight = comp.lineHeight; // both | ||
|
||
// should wrap text | ||
if (overflow === Overflow.NONE) { | ||
layout.wrapping = false; | ||
outputLayoutData.nodeContentSize.width += shareLabelInfo.margin * 2; | ||
outputLayoutData.nodeContentSize.height += shareLabelInfo.margin * 2; | ||
layout.wrapping = false; // both | ||
} else if (overflow === Overflow.RESIZE_HEIGHT) { | ||
layout.wrapping = true; | ||
outputLayoutData.nodeContentSize.height += shareLabelInfo.margin * 2; | ||
} else { | ||
layout.wrapping = comp.enableWrapText; | ||
} | ||
outputRenderData.uiTransAnchorX = trans.anchorX; | ||
outputRenderData.uiTransAnchorY = trans.anchorY; | ||
const fontAsset = comp.font as BitmapFont; | ||
style.fntConfig = fontAsset.fntConfig; // layout only | ||
style.originFontSize = fontAsset.fntConfig?.fontSize; //both | ||
style.fontAtlas = fontAsset.fontDefDictionary; | ||
if (!style.fontAtlas) { | ||
style.fontAtlas = _defaultFontAtlas; | ||
} | ||
|
||
style.isOutlined = false; | ||
style.outlineWidth = 0; | ||
|
||
style.hash = ''; | ||
}, | ||
|
||
// render Only | ||
updateRenderProcessingData ( | ||
style: TextStyle, | ||
outputRenderData: TextOutputRenderData, | ||
comp: Label, | ||
anchor: Readonly<Vec2>, | ||
): void { | ||
// render info | ||
outputRenderData.uiTransAnchorX = anchor.x; | ||
outputRenderData.uiTransAnchorY = anchor.y; | ||
|
||
if (comp.font instanceof BitmapFont) { | ||
const fontAsset = comp.font; | ||
style.spriteFrame = fontAsset.spriteFrame; | ||
dynamicAtlasManager.packToDynamicAtlas(comp, style.spriteFrame); | ||
} | ||
style.color.set(comp.color); // render only | ||
}, | ||
|
||
updateLayoutData (comp: Label): void { | ||
if (comp.layoutDirty) { | ||
const trans = comp.node._uiProps.uiTransformComp!; | ||
const processing = TextProcessing.instance; | ||
const style = comp.textStyle; | ||
const layout = comp.textLayout; | ||
const outputLayoutData = comp.textLayoutData; | ||
style.fontScale = view.getScaleX(); | ||
|
||
shareLabelInfo.lineHeight = comp.lineHeight; | ||
shareLabelInfo.fontSize = comp.fontSize; | ||
this.updateLayoutProcessingData(style, layout, outputLayoutData, comp, trans); | ||
|
||
style.spriteFrame = _spriteFrame; | ||
style.fntConfig = _fntConfig; | ||
style.fontFamily = shareLabelInfo.fontFamily; | ||
// TextProcessing | ||
processing.processingString(true, style, layout, outputLayoutData, comp.string); | ||
|
||
style.color.set(comp.color); | ||
comp.actualFontSize = style.actualFontSize; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does comp should know actualFontSize? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain interface compatibility |
||
trans.setContentSize(outputLayoutData.nodeContentSize); | ||
|
||
comp._resetLayoutDirty(); | ||
} | ||
}, | ||
|
||
updateRenderData (comp: Label): void { | ||
if (!comp.renderData) { | ||
return; | ||
} | ||
|
||
if (_comp === comp) { return; } | ||
|
||
if (comp.renderData.vertDirty) { | ||
_comp = comp; | ||
_uiTrans = _comp.node._uiProps.uiTransformComp!; | ||
const renderData = comp.renderData; | ||
|
||
const processing = TextProcessing.instance; | ||
const style = comp.textStyle; | ||
const layout = comp.textLayout; | ||
const outputLayoutData = comp.textLayoutData; | ||
const outputRenderData = comp.textRenderData; | ||
style.fontScale = view.getScaleX(); | ||
this._updateFontFamily(comp); | ||
|
||
this.updateProcessingData(style, layout, outputLayoutData, outputRenderData, comp, _uiTrans); | ||
|
||
this._updateLabelInfo(comp); | ||
const anchor = comp.node._uiProps.uiTransformComp!.anchorPoint; | ||
this.updateRenderProcessingData(style, outputRenderData, comp, anchor); | ||
|
||
style.fontDesc = shareLabelInfo.fontDesc; | ||
|
||
// TextProcessing | ||
processing.processingString(true, style, layout, outputLayoutData, comp.string); | ||
// generateVertex | ||
this.resetRenderData(comp); | ||
outputRenderData.quadCount = 0; | ||
processing.generateRenderInfo(true, style, layout, outputLayoutData, outputRenderData, | ||
comp.string, this.generateVertexData); | ||
processing.generateRenderInfo( | ||
true, | ||
style, | ||
layout, | ||
outputLayoutData, | ||
outputRenderData, | ||
comp.string, | ||
this.generateVertexData, | ||
); | ||
|
||
renderData.dataLength = outputRenderData.quadCount; | ||
renderData.resize(renderData.dataLength, renderData.dataLength / 2 * 3); | ||
|
@@ -131,17 +159,12 @@ | |
|
||
const indexCount = renderData.indexCount; | ||
this.createQuadIndices(indexCount); | ||
renderData.chunk.setIndexBuffer(QUAD_INDICES); | ||
|
||
_comp.actualFontSize = style.actualFontSize; | ||
_uiTrans.setContentSize(outputLayoutData.nodeContentSize); | ||
this.updateUVs(comp);// dirty need | ||
this.updateColor(comp); // dirty need | ||
|
||
renderData.vertDirty = false; | ||
_comp = null; | ||
|
||
this._resetProperties(); | ||
} | ||
|
||
if (comp.spriteFrame) { | ||
|
@@ -194,8 +217,17 @@ | |
}, | ||
|
||
// callBack function | ||
generateVertexData (style: TextStyle, outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData, offset: number, | ||
spriteFrame: SpriteFrame, rect: Rect, rotated: boolean, x: number, y: number): void { | ||
generateVertexData ( | ||
style: TextStyle, | ||
outputLayoutData: TextOutputLayoutData, | ||
outputRenderData: TextOutputRenderData, | ||
offset: number, | ||
spriteFrame: SpriteFrame, | ||
rect: Rect, | ||
rotated: boolean, | ||
x: number, | ||
y: number, | ||
): void { | ||
const dataOffset = offset; | ||
const scale = style.bmfontScale; | ||
|
||
|
@@ -250,36 +282,6 @@ | |
dataList[dataOffset + 3].y = y; | ||
}, | ||
|
||
_updateFontFamily (comp): void { | ||
const fontAsset = comp.font; | ||
_spriteFrame = fontAsset.spriteFrame; | ||
_fntConfig = fontAsset.fntConfig; | ||
shareLabelInfo.fontAtlas = fontAsset.fontDefDictionary; | ||
if (!shareLabelInfo.fontAtlas) { | ||
if (comp.cacheMode === CacheMode.CHAR) { | ||
shareLabelInfo.fontAtlas = _defaultLetterAtlas; | ||
} else { | ||
shareLabelInfo.fontAtlas = _defaultFontAtlas; | ||
} | ||
} | ||
|
||
dynamicAtlasManager.packToDynamicAtlas(comp, _spriteFrame); | ||
// TODO update material and uv | ||
}, | ||
|
||
_updateLabelInfo (comp): void { | ||
// clear | ||
shareLabelInfo.hash = ''; | ||
shareLabelInfo.margin = 0; | ||
}, | ||
|
||
_resetProperties (): void { | ||
_fntConfig = null; | ||
_spriteFrame = null; | ||
shareLabelInfo.hash = ''; | ||
shareLabelInfo.margin = 0; | ||
}, | ||
|
||
createQuadIndices (indexCount): void { | ||
if (indexCount % 6 !== 0) { | ||
error('illegal index count!'); | ||
|
@@ -287,7 +289,7 @@ | |
} | ||
const quadCount = indexCount / 6; | ||
QUAD_INDICES = null; | ||
QUAD_INDICES = new Uint16Array(indexCount); | ||
let offset = 0; | ||
for (let i = 0; i < quadCount; i++) { | ||
QUAD_INDICES[offset++] = 0 + i * 4; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why delete this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless function,now use generateVertexData in bmfontUtils