babylonjs-gui 5.0.0-alpha.65 → 5.0.0-beta.1

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.js CHANGED
@@ -1925,6 +1925,29 @@ var Button = /** @class */ (function (_super) {
1925
1925
  }
1926
1926
  _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick, pi);
1927
1927
  };
1928
+ /**
1929
+ * Serializes the current button
1930
+ * @param serializationObject defines the JSON serialized object
1931
+ */
1932
+ Button.prototype.serialize = function (serializationObject) {
1933
+ _super.prototype.serialize.call(this, serializationObject);
1934
+ if (this._textBlock) {
1935
+ serializationObject.textBlockName = this._textBlock.name;
1936
+ }
1937
+ if (this._image) {
1938
+ serializationObject.imageName = this._image.name;
1939
+ }
1940
+ };
1941
+ /** @hidden */
1942
+ Button.prototype._parseFromContent = function (serializedObject, host) {
1943
+ _super.prototype._parseFromContent.call(this, serializedObject, host);
1944
+ if (serializedObject.textBlockName) {
1945
+ this._textBlock = this.getChildByName(serializedObject.textBlockName);
1946
+ }
1947
+ if (serializedObject.imageName) {
1948
+ this._image = this.getChildByName(serializedObject.imageName);
1949
+ }
1950
+ };
1928
1951
  // Statics
1929
1952
  /**
1930
1953
  * Creates a new button made with an image and a text
@@ -5774,6 +5797,7 @@ var Control = /** @class */ (function () {
5774
5797
  }
5775
5798
  };
5776
5799
  Control.prototype._evaluateClippingState = function (parentMeasure) {
5800
+ this._currentMeasure.transformToRef(this._transformMatrix, this._evaluatedMeasure);
5777
5801
  if (this.parent && this.parent.clipChildren) {
5778
5802
  parentMeasure.transformToRef(this.parent._transformMatrix, this._evaluatedParentMeasure);
5779
5803
  // Early clip
@@ -13941,6 +13965,10 @@ var TextWrapping;
13941
13965
  * Ellipsize the text, i.e. shrink with trailing … when text is larger than Control.width.
13942
13966
  */
13943
13967
  TextWrapping[TextWrapping["Ellipsis"] = 2] = "Ellipsis";
13968
+ /**
13969
+ * Wrap the text word-wise and clip the text when the text's height is larger than the Control.height, and shrink the last line with trailing … .
13970
+ */
13971
+ TextWrapping[TextWrapping["WordWrapEllipsis"] = 3] = "WordWrapEllipsis";
13944
13972
  })(TextWrapping || (TextWrapping = {}));
13945
13973
  /**
13946
13974
  * Class used to create text block control
@@ -14203,7 +14231,7 @@ var TextBlock = /** @class */ (function (_super) {
14203
14231
  }
14204
14232
  _super.prototype._processMeasures.call(this, parentMeasure, context);
14205
14233
  // Prepare lines
14206
- this._lines = this._breakLines(this._currentMeasure.width, context);
14234
+ this._lines = this._breakLines(this._currentMeasure.width, this._currentMeasure.height, context);
14207
14235
  this.onLinesReadyObservable.notifyObservers(this);
14208
14236
  var maxLineWidth = 0;
14209
14237
  for (var i = 0; i < this._lines.length; i++) {
@@ -14295,7 +14323,7 @@ var TextBlock = /** @class */ (function (_super) {
14295
14323
  context.miterLimit = 2;
14296
14324
  }
14297
14325
  };
14298
- TextBlock.prototype._breakLines = function (refWidth, context) {
14326
+ TextBlock.prototype._breakLines = function (refWidth, refHeight, context) {
14299
14327
  var lines = [];
14300
14328
  var _lines = this.text.split("\n");
14301
14329
  if (this._textWrapping === TextWrapping.Ellipsis) {
@@ -14310,9 +14338,15 @@ var TextBlock = /** @class */ (function (_super) {
14310
14338
  lines.push.apply(lines, this._parseLineWordWrap(_line, refWidth, context));
14311
14339
  }
14312
14340
  }
14313
- else {
14341
+ else if (this._textWrapping === TextWrapping.WordWrapEllipsis) {
14314
14342
  for (var _b = 0, _lines_3 = _lines; _b < _lines_3.length; _b++) {
14315
14343
  var _line = _lines_3[_b];
14344
+ lines.push.apply(lines, this._parseLineWordWrapEllipsis(_line, refWidth, refHeight, context));
14345
+ }
14346
+ }
14347
+ else {
14348
+ for (var _c = 0, _lines_4 = _lines; _c < _lines_4.length; _c++) {
14349
+ var _line = _lines_4[_c];
14316
14350
  lines.push(this._parseLine(_line, context));
14317
14351
  }
14318
14352
  }
@@ -14376,6 +14410,24 @@ var TextBlock = /** @class */ (function (_super) {
14376
14410
  lines.push({ text: line, width: lineWidth });
14377
14411
  return lines;
14378
14412
  };
14413
+ TextBlock.prototype._parseLineWordWrapEllipsis = function (line, width, height, context) {
14414
+ if (line === void 0) { line = ""; }
14415
+ var lines = this._parseLineWordWrap(line, width, context);
14416
+ for (var n = 1; n <= lines.length; n++) {
14417
+ var currentHeight = this._computeHeightForLinesOf(n);
14418
+ if (currentHeight > height && n > 1) {
14419
+ var lastLine = lines[n - 2];
14420
+ var currentLine = lines[n - 1];
14421
+ lines[n - 2] = this._parseLineEllipsis("" + (lastLine.text + currentLine.text), width, context);
14422
+ var linesToRemove = lines.length - n + 1;
14423
+ for (var i = 0; i < linesToRemove; i++) {
14424
+ lines.pop();
14425
+ }
14426
+ return lines;
14427
+ }
14428
+ }
14429
+ return lines;
14430
+ };
14379
14431
  TextBlock.prototype._renderLines = function (context) {
14380
14432
  var height = this._currentMeasure.height;
14381
14433
  var rootY = 0;
@@ -14405,6 +14457,20 @@ var TextBlock = /** @class */ (function (_super) {
14405
14457
  rootY += this._fontOffset.height;
14406
14458
  }
14407
14459
  };
14460
+ TextBlock.prototype._computeHeightForLinesOf = function (lineCount) {
14461
+ var newHeight = this._paddingTopInPixels + this._paddingBottomInPixels + this._fontOffset.height * lineCount;
14462
+ if (lineCount > 0 && this._lineSpacing.internalValue !== 0) {
14463
+ var lineSpacing = 0;
14464
+ if (this._lineSpacing.isPixel) {
14465
+ lineSpacing = this._lineSpacing.getValue(this._host);
14466
+ }
14467
+ else {
14468
+ lineSpacing = this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
14469
+ }
14470
+ newHeight += (lineCount - 1) * lineSpacing;
14471
+ }
14472
+ return newHeight;
14473
+ };
14408
14474
  /**
14409
14475
  * Given a width constraint applied on the text block, find the expected height
14410
14476
  * @returns expected height
@@ -14412,26 +14478,15 @@ var TextBlock = /** @class */ (function (_super) {
14412
14478
  TextBlock.prototype.computeExpectedHeight = function () {
14413
14479
  var _a;
14414
14480
  if (this.text && this.widthInPixels) {
14415
- // Shoudl abstract platform instead of using LastCreatedEngine
14481
+ // Should abstract platform instead of using LastCreatedEngine
14416
14482
  var context_1 = (_a = babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_1__["Engine"].LastCreatedEngine) === null || _a === void 0 ? void 0 : _a.createCanvas(0, 0).getContext("2d");
14417
14483
  if (context_1) {
14418
14484
  this._applyStates(context_1);
14419
14485
  if (!this._fontOffset) {
14420
14486
  this._fontOffset = _control__WEBPACK_IMPORTED_MODULE_3__["Control"]._GetFontOffset(context_1.font);
14421
14487
  }
14422
- var lines = this._lines ? this._lines : this._breakLines(this.widthInPixels - this._paddingLeftInPixels - this._paddingRightInPixels, context_1);
14423
- var newHeight = this._paddingTopInPixels + this._paddingBottomInPixels + this._fontOffset.height * lines.length;
14424
- if (lines.length > 0 && this._lineSpacing.internalValue !== 0) {
14425
- var lineSpacing = 0;
14426
- if (this._lineSpacing.isPixel) {
14427
- lineSpacing = this._lineSpacing.getValue(this._host);
14428
- }
14429
- else {
14430
- lineSpacing = this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
14431
- }
14432
- newHeight += (lines.length - 1) * lineSpacing;
14433
- }
14434
- return newHeight;
14488
+ var lines = this._lines ? this._lines : this._breakLines(this.widthInPixels - this._paddingLeftInPixels - this._paddingRightInPixels, this.heightInPixels - this._paddingTopInPixels - this._paddingBottomInPixels, context_1);
14489
+ return this._computeHeightForLinesOf(lines.length);
14435
14490
  }
14436
14491
  }
14437
14492
  return 0;