mirror of
https://github.com/galacean/engine.git
synced 2026-06-03 17:20:03 +08:00
fix: the error in text.bounds when there is no root canvas (#2543)
This commit is contained in:
@@ -598,7 +598,8 @@ export class Text extends UIRenderer implements ITextRenderer {
|
||||
this._text === "" ||
|
||||
this._fontSize === 0 ||
|
||||
(this.enableWrapping && size.x <= 0) ||
|
||||
(this.overflowMode === OverflowMode.Truncate && size.y <= 0)
|
||||
(this.overflowMode === OverflowMode.Truncate && size.y <= 0) ||
|
||||
!this._getRootCanvas()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,26 @@ describe("Text", async () => {
|
||||
expect(label.enableWrapping).to.eq(true);
|
||||
});
|
||||
|
||||
it("get bounds", () => {
|
||||
const textWithoutCanvas = root.addComponent(Text);
|
||||
textWithoutCanvas.text = "hello world";
|
||||
const bounds = textWithoutCanvas.bounds;
|
||||
expect(bounds.min).to.deep.include({ x: -50, y: -50, z: 0 });
|
||||
expect(bounds.max).to.deep.include({ x: 50, y: 50, z: 0 });
|
||||
|
||||
const labelBounds = label.bounds;
|
||||
expect(labelBounds.min).to.deep.include({ x: -50, y: -50, z: 0 });
|
||||
expect(labelBounds.max).to.deep.include({ x: 50, y: 50, z: 0 });
|
||||
label.text = "hello world";
|
||||
const labelBounds2 = label.bounds;
|
||||
expect(labelBounds2.min).to.deep.include({ x: -50, y: -50, z: 0 });
|
||||
expect(labelBounds2.max).to.deep.include({ x: 50, y: 50, z: 0 });
|
||||
(<UITransform>label.entity.transform).size.x = 200;
|
||||
const labelBounds3 = label.bounds;
|
||||
expect(labelBounds3.min).to.deep.include({ x: -100, y: -50, z: 0 });
|
||||
expect(labelBounds3.max).to.deep.include({ x: 100, y: 50, z: 0 });
|
||||
});
|
||||
|
||||
it("emoji", () => {
|
||||
const textEntity = canvasEntity.createChild("text");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user