* Update content layout * 更新内容布局
()
| 507 | * 更新内容布局 |
| 508 | */ |
| 509 | protected updateLayout(): void { |
| 510 | if (!this._content) return; |
| 511 | |
| 512 | if (!this._content2 && !this._content.texture && !this._content.frames?.length) { |
| 513 | if (this._autoSize) { |
| 514 | this._updatingLayout = true; |
| 515 | this.setSize(50, 30); |
| 516 | this._updatingLayout = false; |
| 517 | } |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | let cw = this.sourceWidth; |
| 522 | let ch = this.sourceHeight; |
| 523 | |
| 524 | if (this._autoSize) { |
| 525 | this._updatingLayout = true; |
| 526 | if (cw === 0) cw = 50; |
| 527 | if (ch === 0) ch = 30; |
| 528 | this.setSize(cw, ch); |
| 529 | this._updatingLayout = false; |
| 530 | |
| 531 | if (cw === this._width && ch === this._height) { |
| 532 | if (this._content2) { |
| 533 | this._content2.setXY(0, 0); |
| 534 | if (this._useResize) { |
| 535 | this._content2.setSize(cw, ch); |
| 536 | } else { |
| 537 | this._content2.setScale(1, 1); |
| 538 | } |
| 539 | } else { |
| 540 | this._content.width = cw; |
| 541 | this._content.height = ch; |
| 542 | this._content.x = 0; |
| 543 | this._content.y = 0; |
| 544 | } |
| 545 | return; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | let sx = 1; |
| 550 | let sy = 1; |
| 551 | |
| 552 | if (this._fill !== ELoaderFillType.None) { |
| 553 | sx = this.width / this.sourceWidth; |
| 554 | sy = this.height / this.sourceHeight; |
| 555 | |
| 556 | if (sx !== 1 || sy !== 1) { |
| 557 | if (this._fill === ELoaderFillType.ScaleMatchHeight) { |
| 558 | sx = sy; |
| 559 | } else if (this._fill === ELoaderFillType.ScaleMatchWidth) { |
| 560 | sy = sx; |
| 561 | } else if (this._fill === ELoaderFillType.Scale) { |
| 562 | if (sx > sy) sx = sy; |
| 563 | else sy = sx; |
| 564 | } else if (this._fill === ELoaderFillType.ScaleNoBorder) { |
| 565 | if (sx > sy) sy = sx; |
| 566 | else sx = sy; |
no test coverage detected