@galacean/engine-ui 0.0.0-experimental-2.0-game.17 → 0.0.0-experimental-2.0-game.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -2998,6 +2998,15 @@
2998
2998
  this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2999
2999
  this._subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
3000
3000
  };
3001
+ /**
3002
+ * Switch the sub font to a specific font size, used by the SHRINK overflow measurement.
3003
+ */ _proto._applyFontSizeForShrink = function _applyFontSizeForShrink(fontSize) {
3004
+ var font = this._font;
3005
+ // @ts-ignore
3006
+ var subFont = font._getSubFont(fontSize, this._fontStyle);
3007
+ subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, fontSize, this._fontStyle);
3008
+ this._subFont = subFont;
3009
+ };
3001
3010
  _proto._updatePosition = function _updatePosition() {
3002
3011
  var e = this._transformEntity.transform.worldMatrix.elements;
3003
3012
  // prettier-ignore
@@ -3050,18 +3059,30 @@
3050
3059
  }
3051
3060
  };
3052
3061
  _proto._updateLocalData = function _updateLocalData() {
3062
+ var _this = this;
3053
3063
  // @ts-ignore
3054
3064
  var pixelsPerResolution = engine.Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
3055
3065
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
3056
3066
  var charRenderInfos = Text._charRenderInfos;
3057
- var charFont = this._getSubFont();
3058
3067
  var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
3059
3068
  var rendererWidth = size.x;
3060
3069
  var rendererHeight = size.y;
3061
3070
  var offsetWidth = rendererWidth * (0.5 - pivot.x);
3062
3071
  var offsetHeight = rendererHeight * (0.5 - pivot.y);
3063
- var characterSpacing = this._characterSpacing * this._fontSize;
3064
- var textMetrics = this.enableWrapping ? engine.TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing) : engine.TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing);
3072
+ var fontSize = this._fontSize;
3073
+ var textMetrics;
3074
+ if (this._overflowMode === engine.OverflowMode.Shrink) {
3075
+ var result = engine.TextUtils.measureTextWithShrink(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._fontSize, this._lineSpacing, this._characterSpacing, this.enableWrapping, function(sizeValue) {
3076
+ return _this._applyFontSizeForShrink(sizeValue);
3077
+ });
3078
+ fontSize = result.fontSize;
3079
+ textMetrics = result.metrics;
3080
+ } else {
3081
+ var characterSpacing = this._characterSpacing * fontSize;
3082
+ textMetrics = this.enableWrapping ? engine.TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing) : engine.TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing);
3083
+ }
3084
+ var charFont = this._getSubFont();
3085
+ var characterSpacing1 = this._characterSpacing * fontSize;
3065
3086
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
3066
3087
  // @ts-ignore
3067
3088
  var charRenderInfoPool = this.engine._charRenderInfoPool;
@@ -3082,7 +3103,10 @@
3082
3103
  startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
3083
3104
  break;
3084
3105
  case engine.TextVerticalAlignment.Center:
3085
- startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
3106
+ // Center the text block (lineHeight * lineCount) within the renderer, independent of
3107
+ // `height` — which equals the renderer height for Truncate/Shrink and would otherwise
3108
+ // push the text upward by (rendererHeight - blockHeight) / 2 when the box is taller.
3109
+ startY = lineHeight * linesLen * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
3086
3110
  break;
3087
3111
  case engine.TextVerticalAlignment.Bottom:
3088
3112
  startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
@@ -3134,7 +3158,7 @@
3134
3158
  j === firstRow && (minX = Math.min(minX, left));
3135
3159
  maxX = Math.max(maxX, right);
3136
3160
  }
3137
- startX += charInfo.xAdvance + characterSpacing;
3161
+ startX += charInfo.xAdvance + characterSpacing1;
3138
3162
  }
3139
3163
  }
3140
3164
  startY -= lineHeight;
@@ -3194,7 +3218,7 @@
3194
3218
  };
3195
3219
  _proto._isTextNoVisible = function _isTextNoVisible() {
3196
3220
  var size = this._transformEntity.transform.size;
3197
- return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === engine.OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
3221
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || (this.overflowMode === engine.OverflowMode.Truncate || this.overflowMode === engine.OverflowMode.Shrink) && size.y <= 0 || !this._getRootCanvas();
3198
3222
  };
3199
3223
  _proto._buildChunk = function _buildChunk(textChunk, count) {
3200
3224
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;