diff --git a/cocos/2d/components/label-outline.ts b/cocos/2d/components/label-outline.ts index b00cb516297..7386b351f6d 100644 --- a/cocos/2d/components/label-outline.ts +++ b/cocos/2d/components/label-outline.ts @@ -121,6 +121,16 @@ export class LabelOutline extends Component { label.outlineUsed = false; } } + + /** + * @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead. + */ + public onLoad (): void { + const label = this.node.getComponent(Label); + if (label && this.enabledInHierarchy) { + label.outlineUsed = true; + } + } } cclegacy.LabelOutline = LabelOutline; diff --git a/cocos/2d/components/label-shadow.ts b/cocos/2d/components/label-shadow.ts index a5a16447bbb..c65ea7aa155 100644 --- a/cocos/2d/components/label-shadow.ts +++ b/cocos/2d/components/label-shadow.ts @@ -137,4 +137,14 @@ export class LabelShadow extends Component { label.shadowUsed = false; } } + + /** + * @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead. + */ + public onLoad (): void { + const label = this.node.getComponent(Label); + if (label && this.enabledInHierarchy) { + label.shadowUsed = true; + } + } } diff --git a/tests/ui/label.test.ts b/tests/ui/label.test.ts index 3af77017c27..f77dff0ecd9 100644 --- a/tests/ui/label.test.ts +++ b/tests/ui/label.test.ts @@ -1,5 +1,6 @@ -import { Label } from "../../cocos/2d/components"; +import { Label, LabelOutline, LabelShadow } from "../../cocos/2d/components"; import { Node } from "../../cocos/scene-graph/node"; +import { Color, Vec2 } from "../../exports/base"; test('label.string.setter', () => { let node = new Node(); @@ -25,4 +26,50 @@ test('label.string.setter', () => { expect(label.string).toStrictEqual('1'); label.string = 0; expect(label.string).toStrictEqual('0'); +}); + +test('labelOutline.setter', () => { + let node = new Node(); + node.addComponent(Label); + let label = node.getComponent(Label) as Label; + + node.addComponent(LabelOutline); + let labelOutline = node.getComponent(LabelOutline) as LabelOutline; + node._setActiveInHierarchy(true); + labelOutline.onLoad(); + expect(label.outlineUsed).toStrictEqual(true); + labelOutline.color = new Color(255, 0, 0, 255); + expect(label.outlineColor).toStrictEqual(new Color(255, 0, 0, 255)); + labelOutline.width = 2; + expect(label.outlineWidth).toStrictEqual(2); + labelOutline.enabled = false; + labelOutline.onDisable(); + expect(label.outlineUsed).toStrictEqual(false); + labelOutline.enabled = true; + labelOutline.onEnable(); + expect(label.outlineUsed).toStrictEqual(true); +}); + +test('labelShadow.setter', () => { + let node = new Node(); + node.addComponent(Label); + let label = node.getComponent(Label) as Label; + + node.addComponent(LabelShadow); + let labelShadow = node.getComponent(LabelShadow) as LabelShadow; + node._setActiveInHierarchy(true); + labelShadow.onLoad(); + expect(label.shadowUsed).toStrictEqual(true); + labelShadow.color = new Color(255, 0, 0, 255); + expect(label.shadowColor).toStrictEqual(new Color(255, 0, 0, 255)); + labelShadow.offset = new Vec2(2, 2); + expect(label.shadowOffset).toStrictEqual(new Vec2(2, 2)); + labelShadow.blur = 2; + expect(label.shadowBlur).toStrictEqual(2); + labelShadow.enabled = false; + labelShadow.onDisable(); + expect(label.shadowUsed).toStrictEqual(false); + labelShadow.enabled = true; + labelShadow.onEnable(); + expect(label.shadowUsed).toStrictEqual(true); }); \ No newline at end of file