* Set size * 设置尺寸
(wv: number, hv: number, bIgnorePivot: boolean = false)
| 249 | * 设置尺寸 |
| 250 | */ |
| 251 | public setSize(wv: number, hv: number, bIgnorePivot: boolean = false): void { |
| 252 | if (this._rawWidth !== wv || this._rawHeight !== hv) { |
| 253 | this._rawWidth = wv; |
| 254 | this._rawHeight = hv; |
| 255 | |
| 256 | if (wv < this.minWidth) wv = this.minWidth; |
| 257 | if (hv < this.minHeight) hv = this.minHeight; |
| 258 | if (this.maxWidth > 0 && wv > this.maxWidth) wv = this.maxWidth; |
| 259 | if (this.maxHeight > 0 && hv > this.maxHeight) hv = this.maxHeight; |
| 260 | |
| 261 | const dWidth = wv - this._width; |
| 262 | const dHeight = hv - this._height; |
| 263 | this._width = wv; |
| 264 | this._height = hv; |
| 265 | |
| 266 | this.handleSizeChanged(); |
| 267 | |
| 268 | if (this._pivotX !== 0 || this._pivotY !== 0) { |
| 269 | if (!this._pivotAsAnchor) { |
| 270 | if (!bIgnorePivot) { |
| 271 | this.setXY(this.x - this._pivotX * dWidth, this.y - this._pivotY * dHeight); |
| 272 | } |
| 273 | this.updatePivotOffset(); |
| 274 | } else { |
| 275 | this.applyPivot(); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | this.updateGear(2); |
| 280 | |
| 281 | if (this._parent) { |
| 282 | this._relations?.onOwnerSizeChanged(dWidth, dHeight, this._pivotAsAnchor || !bIgnorePivot); |
| 283 | this._parent.setBoundsChangedFlag(); |
| 284 | if (this._group) { |
| 285 | this._group.setBoundsChangedFlag(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | this.emit(FGUIEvents.SIZE_CHANGED); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Ensure size is calculated correctly |
no test coverage detected