babylonjs-gui 5.4.0 → 5.5.0

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/babylon.gui.d.ts CHANGED
@@ -3678,6 +3678,7 @@ declare module BABYLON.GUI {
3678
3678
  protected _parseLine(line: string | undefined, context: BABYLON.ICanvasRenderingContext): object;
3679
3679
  private _getCharsToRemove;
3680
3680
  protected _parseLineEllipsis(line: string | undefined, width: number, context: BABYLON.ICanvasRenderingContext): object;
3681
+ private _getTextMetricsWidth;
3681
3682
  protected _parseLineWordWrap(line: string | undefined, width: number, context: BABYLON.ICanvasRenderingContext): object[];
3682
3683
  protected _parseLineWordWrapEllipsis(line: string | undefined, width: number, height: number, context: BABYLON.ICanvasRenderingContext): object[];
3683
3684
  protected _renderLines(context: BABYLON.ICanvasRenderingContext): void;
package/babylon.gui.js CHANGED
@@ -8622,20 +8622,28 @@ var Image = /** @class */ (function (_super) {
8622
8622
  //Top Left
8623
8623
  this._drawImage(context, 0, 0, leftWidth, topHeight, this._currentMeasure.left, this._currentMeasure.top, leftWidth, topHeight);
8624
8624
  //Top
8625
+ context.clearRect(centerLeftOffset, this._currentMeasure.top, targetCenterWidth, topHeight);
8625
8626
  this._drawImage(context, this._sliceLeft, 0, centerWidth, topHeight, centerLeftOffset, this._currentMeasure.top, targetCenterWidth, topHeight);
8626
8627
  //Top Right
8627
- this._drawImage(context, this.sliceRight, 0, rightWidth, topHeight, rightOffset, this._currentMeasure.top, rightWidth, topHeight);
8628
+ context.clearRect(rightOffset, this._currentMeasure.top, rightWidth, topHeight);
8629
+ this._drawImage(context, this._sliceRight, 0, rightWidth, topHeight, rightOffset, this._currentMeasure.top, rightWidth, topHeight);
8628
8630
  //Left
8631
+ context.clearRect(this._currentMeasure.left, centerTopOffset, leftWidth, targetCenterHeight);
8629
8632
  this._drawImage(context, 0, this._sliceTop, leftWidth, centerHeight, this._currentMeasure.left, centerTopOffset, leftWidth, targetCenterHeight);
8630
8633
  // Center
8634
+ context.clearRect(centerLeftOffset, centerTopOffset, targetCenterWidth, targetCenterHeight);
8631
8635
  this._drawImage(context, this._sliceLeft, this._sliceTop, centerWidth, centerHeight, centerLeftOffset, centerTopOffset, targetCenterWidth, targetCenterHeight);
8632
8636
  //Right
8637
+ context.clearRect(rightOffset, centerTopOffset, rightWidth, targetCenterHeight);
8633
8638
  this._drawImage(context, this._sliceRight, this._sliceTop, rightWidth, centerHeight, rightOffset, centerTopOffset, rightWidth, targetCenterHeight);
8634
8639
  //Bottom Left
8640
+ context.clearRect(this._currentMeasure.left, bottomOffset, leftWidth, bottomHeight);
8635
8641
  this._drawImage(context, 0, this._sliceBottom, leftWidth, bottomHeight, this._currentMeasure.left, bottomOffset, leftWidth, bottomHeight);
8636
8642
  //Bottom
8643
+ context.clearRect(centerLeftOffset, bottomOffset, targetCenterWidth, bottomHeight);
8637
8644
  this._drawImage(context, this.sliceLeft, this._sliceBottom, centerWidth, bottomHeight, centerLeftOffset, bottomOffset, targetCenterWidth, bottomHeight);
8638
8645
  //Bottom Right
8646
+ context.clearRect(rightOffset, bottomOffset, rightWidth, bottomHeight);
8639
8647
  this._drawImage(context, this._sliceRight, this._sliceBottom, rightWidth, bottomHeight, rightOffset, bottomOffset, rightWidth, bottomHeight);
8640
8648
  };
8641
8649
  Image.prototype.dispose = function () {
@@ -14758,9 +14766,7 @@ var TextBlock = /** @class */ (function (_super) {
14758
14766
  };
14759
14767
  TextBlock.prototype._parseLine = function (line, context) {
14760
14768
  if (line === void 0) { line = ""; }
14761
- var textMetrics = context.measureText(line);
14762
- var lineWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14763
- return { text: line, width: lineWidth };
14769
+ return { text: line, width: this._getTextMetricsWidth(context.measureText(line)) };
14764
14770
  };
14765
14771
  //Calculate how many characters approximately we need to remove
14766
14772
  TextBlock.prototype._getCharsToRemove = function (lineWidth, width, lineLength) {
@@ -14772,8 +14778,7 @@ var TextBlock = /** @class */ (function (_super) {
14772
14778
  };
14773
14779
  TextBlock.prototype._parseLineEllipsis = function (line, width, context) {
14774
14780
  if (line === void 0) { line = ""; }
14775
- var textMetrics = context.measureText(line);
14776
- var lineWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14781
+ var lineWidth = this._getTextMetricsWidth(context.measureText(line));
14777
14782
  var removeChars = this._getCharsToRemove(lineWidth, width, line.length);
14778
14783
  // unicode support. split('') does not work with unicode!
14779
14784
  // make sure Array.from is available
@@ -14782,8 +14787,7 @@ var TextBlock = /** @class */ (function (_super) {
14782
14787
  // no array.from, use the old method
14783
14788
  while (line.length > 2 && lineWidth > width) {
14784
14789
  line = line.slice(0, -removeChars);
14785
- textMetrics = context.measureText(line + "…");
14786
- lineWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14790
+ lineWidth = this._getTextMetricsWidth(context.measureText(line + "…"));
14787
14791
  removeChars = this._getCharsToRemove(lineWidth, width, line.length);
14788
14792
  }
14789
14793
  // Add on the end
@@ -14793,28 +14797,30 @@ var TextBlock = /** @class */ (function (_super) {
14793
14797
  while (characters.length && lineWidth > width) {
14794
14798
  characters.splice(characters.length - removeChars, removeChars);
14795
14799
  line = "".concat(characters.join(""), "\u2026");
14796
- textMetrics = context.measureText(line);
14797
- lineWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14800
+ lineWidth = this._getTextMetricsWidth(context.measureText(line));
14798
14801
  removeChars = this._getCharsToRemove(lineWidth, width, line.length);
14799
14802
  }
14800
14803
  }
14801
14804
  return { text: line, width: lineWidth };
14802
14805
  };
14806
+ TextBlock.prototype._getTextMetricsWidth = function (textMetrics) {
14807
+ if (textMetrics.actualBoundingBoxLeft !== undefined) {
14808
+ return Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14809
+ }
14810
+ return textMetrics.width;
14811
+ };
14803
14812
  TextBlock.prototype._parseLineWordWrap = function (line, width, context) {
14804
14813
  if (line === void 0) { line = ""; }
14805
14814
  var lines = [];
14806
14815
  var words = this.wordSplittingFunction ? this.wordSplittingFunction(line) : line.split(" ");
14807
- var textMetrics = context.measureText(line);
14808
- var lineWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14816
+ var lineWidth = this._getTextMetricsWidth(context.measureText(line));
14809
14817
  for (var n = 0; n < words.length; n++) {
14810
14818
  var testLine = n > 0 ? line + " " + words[n] : words[0];
14811
- var metrics = context.measureText(testLine);
14812
- var testWidth = Math.abs(metrics.actualBoundingBoxLeft) + Math.abs(metrics.actualBoundingBoxRight);
14819
+ var testWidth = this._getTextMetricsWidth(context.measureText(testLine));
14813
14820
  if (testWidth > width && n > 0) {
14814
14821
  lines.push({ text: line, width: lineWidth });
14815
14822
  line = words[n];
14816
- textMetrics = context.measureText(line);
14817
- lineWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
14823
+ lineWidth = this._getTextMetricsWidth(context.measureText(line));
14818
14824
  }
14819
14825
  else {
14820
14826
  lineWidth = testWidth;