Skip to content
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

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"cocos/render-scene/scene/submodel.ts": "cocos/render-scene/scene/submodel.jsb.ts",
"cocos/render-scene/scene/index.ts": "cocos/render-scene/scene/index.jsb.ts",
"cocos/render-scene/scene/reflection-probe.ts": "cocos/render-scene/scene/reflection-probe.jsb.ts",
"cocos/2d/renderer/batcher-2d.ts": "cocos/2d/renderer/batcher-2d.jsb.ts",
"cocos/2d/renderer/native-2d.ts": "cocos/2d/renderer/native-2d.jsb.ts",
"cocos/gfx/base/pipeline-state.ts": "cocos/gfx/base/pipeline-state.jsb.ts",
"cocos/gfx/base/pipeline-sub-state.ts": "cocos/gfx/base/pipeline-sub-state.jsb.ts",
Expand Down
62 changes: 0 additions & 62 deletions cocos/2d/assembler/label/bmfont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,68 +50,6 @@ export const bmfont: IAssembler = {
// Fill All
fillMeshVertices3D(node, renderer, comp.renderData!, tempColor);
},

appendQuad (comp: Label, spriteFrame: SpriteFrame, rect: Rect, rotated: boolean, x: number, y: number, scale: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete this function?

Copy link
Contributor Author

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

const renderData = comp.renderData;
if (!renderData) {
return;
}

const dataOffset = renderData.dataLength;

renderData.dataLength += 4;
renderData.resize(renderData.dataLength, renderData.dataLength / 2 * 3);

const dataList = renderData.data;
const texW = spriteFrame.width;
const texH = spriteFrame.height;

const rectWidth = rect.width;
const rectHeight = rect.height;

let l = 0;
let b = 0;
let t = 0;
let r = 0;
if (!rotated) {
l = (rect.x) / texW;
r = (rect.x + rectWidth) / texW;
b = (rect.y + rectHeight) / texH;
t = (rect.y) / texH;

dataList[dataOffset].u = l;
dataList[dataOffset].v = b;
dataList[dataOffset + 1].u = r;
dataList[dataOffset + 1].v = b;
dataList[dataOffset + 2].u = l;
dataList[dataOffset + 2].v = t;
dataList[dataOffset + 3].u = r;
dataList[dataOffset + 3].v = t;
} else {
l = (rect.x) / texW;
r = (rect.x + rectHeight) / texW;
b = (rect.y + rectWidth) / texH;
t = (rect.y) / texH;

dataList[dataOffset].u = l;
dataList[dataOffset].v = t;
dataList[dataOffset + 1].u = l;
dataList[dataOffset + 1].v = b;
dataList[dataOffset + 2].u = r;
dataList[dataOffset + 2].v = t;
dataList[dataOffset + 3].u = r;
dataList[dataOffset + 3].v = b;
}

dataList[dataOffset].x = x;
dataList[dataOffset].y = y - rectHeight * scale;
dataList[dataOffset + 1].x = x + rectWidth * scale;
dataList[dataOffset + 1].y = y - rectHeight * scale;
dataList[dataOffset + 2].x = x;
dataList[dataOffset + 2].y = y;
dataList[dataOffset + 3].x = x + rectWidth * scale;
dataList[dataOffset + 3].y = y;
},
};

js.addon(bmfont, bmfontUtils);
174 changes: 88 additions & 86 deletions cocos/2d/assembler/label/bmfontUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does comp should know actualFontSize?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand All @@ -131,17 +159,12 @@

const indexCount = renderData.indexCount;
this.createQuadIndices(indexCount);
renderData.chunk.setIndexBuffer(QUAD_INDICES);

Check failure on line 162 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `ArrayLike<number>`

_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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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!');
Expand All @@ -287,7 +289,7 @@
}
const quadCount = indexCount / 6;
QUAD_INDICES = null;
QUAD_INDICES = new Uint16Array(indexCount);

Check failure on line 292 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Iterable<number>`
let offset = 0;
for (let i = 0; i < quadCount; i++) {
QUAD_INDICES[offset++] = 0 + i * 4;
Expand Down
Loading
Loading