@babylonjs/gui 9.25.0 → 9.26.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.
Files changed (42) hide show
  1. package/2D/controls/colorpicker.pure.js +2 -2
  2. package/2D/controls/colorpicker.pure.js.map +1 -1
  3. package/2D/controls/container.pure.d.ts +9 -0
  4. package/2D/controls/container.pure.js +14 -2
  5. package/2D/controls/container.pure.js.map +1 -1
  6. package/2D/controls/control.pure.d.ts +26 -1
  7. package/2D/controls/control.pure.js +104 -71
  8. package/2D/controls/control.pure.js.map +1 -1
  9. package/2D/controls/flexPanel.d.ts +1 -0
  10. package/2D/controls/flexPanel.js +4 -0
  11. package/2D/controls/flexPanel.js.map +1 -0
  12. package/2D/controls/flexPanel.pure.d.ts +91 -0
  13. package/2D/controls/flexPanel.pure.js +318 -0
  14. package/2D/controls/flexPanel.pure.js.map +1 -0
  15. package/2D/controls/index.d.ts +1 -0
  16. package/2D/controls/index.js +1 -0
  17. package/2D/controls/index.js.map +1 -1
  18. package/2D/controls/inputText.pure.js +7 -6
  19. package/2D/controls/inputText.pure.js.map +1 -1
  20. package/2D/controls/inputTextArea.pure.js +14 -13
  21. package/2D/controls/inputTextArea.pure.js.map +1 -1
  22. package/2D/controls/line.pure.js +9 -9
  23. package/2D/controls/line.pure.js.map +1 -1
  24. package/2D/controls/pure.d.ts +1 -0
  25. package/2D/controls/pure.js +1 -0
  26. package/2D/controls/pure.js.map +1 -1
  27. package/2D/controls/sliders/baseSlider.js +11 -11
  28. package/2D/controls/sliders/baseSlider.js.map +1 -1
  29. package/2D/controls/sliders/imageScrollBar.js +3 -3
  30. package/2D/controls/sliders/imageScrollBar.js.map +1 -1
  31. package/2D/controls/sliders/scrollBar.pure.js +3 -3
  32. package/2D/controls/sliders/scrollBar.pure.js.map +1 -1
  33. package/2D/controls/stackPanel.pure.js +1 -1
  34. package/2D/controls/stackPanel.pure.js.map +1 -1
  35. package/2D/controls/textBlock.pure.js +10 -10
  36. package/2D/controls/textBlock.pure.js.map +1 -1
  37. package/2D/multiLinePoint.js +2 -2
  38. package/2D/multiLinePoint.js.map +1 -1
  39. package/2D/valueAndUnit.d.ts +15 -3
  40. package/2D/valueAndUnit.js +36 -11
  41. package/2D/valueAndUnit.js.map +1 -1
  42. package/package.json +3 -2
@@ -82,6 +82,8 @@ let Control = (() => {
82
82
  let _overlapDeltaMultiplier_decorators;
83
83
  let _overlapDeltaMultiplier_initializers = [];
84
84
  let _overlapDeltaMultiplier_extraInitializers = [];
85
+ let _get_flexGrow_decorators;
86
+ let _get_flexShrink_decorators;
85
87
  return _a = class Control {
86
88
  /**
87
89
  * Gets or sets a boolean indicating if the control is readonly (default: false).
@@ -400,7 +402,7 @@ let Control = (() => {
400
402
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
401
403
  */
402
404
  get widthInPixels() {
403
- return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
405
+ return this._getValueInPixel(this._width, this._cachedParentMeasure.width);
404
406
  }
405
407
  set widthInPixels(value) {
406
408
  if (isNaN(value)) {
@@ -430,7 +432,7 @@ let Control = (() => {
430
432
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
431
433
  */
432
434
  get heightInPixels() {
433
- return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
435
+ return this._getValueInPixel(this._height, this._cachedParentMeasure.height);
434
436
  }
435
437
  set heightInPixels(value) {
436
438
  if (isNaN(value)) {
@@ -501,10 +503,14 @@ let Control = (() => {
501
503
  /** Gets or sets font size in pixels */
502
504
  get fontSizeInPixels() {
503
505
  const fontSizeToUse = this._style ? this._style._fontSize : this._fontSize;
504
- if (fontSizeToUse.isPixel) {
505
- return fontSizeToUse.getValue(this._host);
506
+ if (fontSizeToUse.unit !== ValueAndUnit.UNITMODE_EM && fontSizeToUse.unit !== ValueAndUnit.UNITMODE_REM) {
507
+ return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
506
508
  }
507
- return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
509
+ const root = this._host?.rootContainer;
510
+ const defaultSize = _a._DefaultFontSize.getValue(this._host);
511
+ const rootSize = root && root !== this ? root.fontSizeInPixels : defaultSize;
512
+ const parentSize = this.parent ? this.parent.fontSizeInPixels : defaultSize;
513
+ return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height, parentSize, rootSize);
508
514
  }
509
515
  set fontSizeInPixels(value) {
510
516
  if (isNaN(value)) {
@@ -512,7 +518,11 @@ let Control = (() => {
512
518
  }
513
519
  this.fontSize = value + "px";
514
520
  }
515
- /** Gets or sets font size */
521
+ /**
522
+ * Gets or sets the font size in px, percent of parent height, em, or rem.
523
+ * For font declarations, em uses the parent font and rem uses the GUI root font.
524
+ * Relative font sizes on the root use the default 18px font, including adaptive scaling.
525
+ */
516
526
  get fontSize() {
517
527
  return this._fontSize.toString(this._host);
518
528
  }
@@ -624,7 +634,7 @@ let Control = (() => {
624
634
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
625
635
  */
626
636
  get paddingLeftInPixels() {
627
- return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
637
+ return this._getValueInPixel(this._paddingLeft, this._cachedParentMeasure.width);
628
638
  }
629
639
  set paddingLeftInPixels(value) {
630
640
  if (isNaN(value)) {
@@ -656,7 +666,7 @@ let Control = (() => {
656
666
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
657
667
  */
658
668
  get paddingRightInPixels() {
659
- return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
669
+ return this._getValueInPixel(this._paddingRight, this._cachedParentMeasure.width);
660
670
  }
661
671
  set paddingRightInPixels(value) {
662
672
  if (isNaN(value)) {
@@ -688,7 +698,7 @@ let Control = (() => {
688
698
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
689
699
  */
690
700
  get paddingTopInPixels() {
691
- return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
701
+ return this._getValueInPixel(this._paddingTop, this._cachedParentMeasure.height);
692
702
  }
693
703
  set paddingTopInPixels(value) {
694
704
  if (isNaN(value)) {
@@ -720,7 +730,7 @@ let Control = (() => {
720
730
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
721
731
  */
722
732
  get paddingBottomInPixels() {
723
- return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
733
+ return this._getValueInPixel(this._paddingBottom, this._cachedParentMeasure.height);
724
734
  }
725
735
  set paddingBottomInPixels(value) {
726
736
  if (isNaN(value)) {
@@ -752,7 +762,7 @@ let Control = (() => {
752
762
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
753
763
  */
754
764
  get leftInPixels() {
755
- return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
765
+ return this._getValueInPixel(this._left, this._cachedParentMeasure.width);
756
766
  }
757
767
  set leftInPixels(value) {
758
768
  if (isNaN(value)) {
@@ -777,7 +787,7 @@ let Control = (() => {
777
787
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#position-and-size
778
788
  */
779
789
  get topInPixels() {
780
- return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
790
+ return this._getValueInPixel(this._top, this._cachedParentMeasure.height);
781
791
  }
782
792
  set topInPixels(value) {
783
793
  if (isNaN(value)) {
@@ -802,7 +812,7 @@ let Control = (() => {
802
812
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#tracking-positions
803
813
  */
804
814
  get linkOffsetXInPixels() {
805
- return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
815
+ return this._getValueInPixel(this._linkOffsetX, this._cachedParentMeasure.width);
806
816
  }
807
817
  set linkOffsetXInPixels(value) {
808
818
  if (isNaN(value)) {
@@ -827,7 +837,7 @@ let Control = (() => {
827
837
  * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#tracking-positions
828
838
  */
829
839
  get linkOffsetYInPixels() {
830
- return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
840
+ return this._getValueInPixel(this._linkOffsetY, this._cachedParentMeasure.height);
831
841
  }
832
842
  set linkOffsetYInPixels(value) {
833
843
  if (isNaN(value)) {
@@ -956,6 +966,36 @@ let Control = (() => {
956
966
  }
957
967
  this.onKeyboardEventProcessedObservable.notifyObservers(evt, -1, this);
958
968
  }
969
+ /**
970
+ * Gets or sets the nonnegative share of free main-axis space in a FlexPanel.
971
+ */
972
+ get flexGrow() {
973
+ return this._flexGrow;
974
+ }
975
+ set flexGrow(value) {
976
+ if (!Number.isFinite(value) || value < 0) {
977
+ throw new RangeError("flexGrow must be finite and nonnegative");
978
+ }
979
+ if (this._flexGrow !== value) {
980
+ this._flexGrow = value;
981
+ this._markAsDirty();
982
+ }
983
+ }
984
+ /**
985
+ * Gets or sets the nonnegative shrink factor in a FlexPanel, weighted by the declared main-axis size.
986
+ */
987
+ get flexShrink() {
988
+ return this._flexShrink;
989
+ }
990
+ set flexShrink(value) {
991
+ if (!Number.isFinite(value) || value < 0) {
992
+ throw new RangeError("flexShrink must be finite and nonnegative");
993
+ }
994
+ if (this._flexShrink !== value) {
995
+ this._flexShrink = value;
996
+ this._markAsDirty();
997
+ }
998
+ }
959
999
  // Functions
960
1000
  /**
961
1001
  * Creates a new control
@@ -1177,6 +1217,8 @@ let Control = (() => {
1177
1217
  this.onBlurObservable = new Observable();
1178
1218
  /** Observable raised when a key event was processed */
1179
1219
  this.onKeyboardEventProcessedObservable = new Observable();
1220
+ this._flexGrow = 0;
1221
+ this._flexShrink = 1;
1180
1222
  this._tmpMeasureA = new Measure(0, 0, 0, 0);
1181
1223
  }
1182
1224
  /** @internal */
@@ -1370,14 +1412,14 @@ let Control = (() => {
1370
1412
  * @internal
1371
1413
  */
1372
1414
  _moveToProjectedPosition(projectedPosition) {
1373
- const oldLeft = this._left.getValue(this._host);
1374
- const oldTop = this._top.getValue(this._host);
1415
+ const oldLeft = this._getValueInPixel(this._left, 1);
1416
+ const oldTop = this._getValueInPixel(this._top, 1);
1375
1417
  const parentMeasure = this.parent?._currentMeasure;
1376
1418
  if (parentMeasure) {
1377
1419
  this._processMeasures(parentMeasure, this._host.getContext());
1378
1420
  }
1379
- let newLeft = projectedPosition.x + this._linkOffsetX.getValue(this._host) - this._currentMeasure.width / 2;
1380
- let newTop = projectedPosition.y + this._linkOffsetY.getValue(this._host) - this._currentMeasure.height / 2;
1421
+ let newLeft = projectedPosition.x + this._getValueInPixel(this._linkOffsetX, 1) - this._currentMeasure.width / 2;
1422
+ let newTop = projectedPosition.y + this._getValueInPixel(this._linkOffsetY, 1) - this._currentMeasure.height / 2;
1381
1423
  if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
1382
1424
  if (Math.abs(newLeft - oldLeft) < 0.5) {
1383
1425
  newLeft = oldLeft;
@@ -1628,8 +1670,17 @@ let Control = (() => {
1628
1670
  // Let children take some pre-measurement actions
1629
1671
  this._preMeasure(this._tempPaddingMeasure, context);
1630
1672
  this._measure();
1631
- // Let children take some post-measurement actions
1673
+ const flexMeasure = this.parent?._getLayoutMeasureForChild(this);
1674
+ if (flexMeasure) {
1675
+ this._currentMeasure.width = flexMeasure.width;
1676
+ this._currentMeasure.height = flexMeasure.height;
1677
+ }
1678
+ // Text wrapping must use the allocated flex width rather than the declared basis.
1632
1679
  this._postMeasure(this._tempPaddingMeasure, context);
1680
+ if (flexMeasure) {
1681
+ this._currentMeasure.width = flexMeasure.width;
1682
+ this._currentMeasure.height = flexMeasure.height;
1683
+ }
1633
1684
  this._computeAlignment(this._tempPaddingMeasure, context);
1634
1685
  // Let children add more features
1635
1686
  this._additionalProcessing(this._tempPaddingMeasure, context);
@@ -1666,21 +1717,23 @@ let Control = (() => {
1666
1717
  }
1667
1718
  this._isClipped = false;
1668
1719
  }
1720
+ /**
1721
+ * Resolves a GUI dimension using this control's computed font size.
1722
+ * @param value defines the dimension to resolve
1723
+ * @param reference defines the reference size for percentages
1724
+ * @returns the dimension in pixels
1725
+ * @internal
1726
+ */
1727
+ _getValueInPixel(value, reference) {
1728
+ if (value.unit === ValueAndUnit.UNITMODE_EM || value.unit === ValueAndUnit.UNITMODE_REM) {
1729
+ return value.getValueInPixel(this._host, reference, this.fontSizeInPixels, this._host?.rootContainer.fontSizeInPixels);
1730
+ }
1731
+ return value.getValueInPixel(this._host, reference);
1732
+ }
1669
1733
  /** @internal */
1670
1734
  _measure() {
1671
- // Width / Height
1672
- if (this._width.isPixel) {
1673
- this._currentMeasure.width = this._width.getValue(this._host);
1674
- }
1675
- else {
1676
- this._currentMeasure.width *= this._width.getValue(this._host);
1677
- }
1678
- if (this._height.isPixel) {
1679
- this._currentMeasure.height = this._height.getValue(this._host);
1680
- }
1681
- else {
1682
- this._currentMeasure.height *= this._height.getValue(this._host);
1683
- }
1735
+ this._currentMeasure.width = this._getValueInPixel(this._width, this._currentMeasure.width);
1736
+ this._currentMeasure.height = this._getValueInPixel(this._height, this._currentMeasure.height);
1684
1737
  if (this._fixedRatio !== 0) {
1685
1738
  if (this._fixedRatioMasterIsWidth) {
1686
1739
  this._currentMeasure.height = this._currentMeasure.width * this._fixedRatio;
@@ -1724,46 +1777,21 @@ let Control = (() => {
1724
1777
  break;
1725
1778
  }
1726
1779
  if (!this.descendantsOnlyPadding) {
1727
- if (this._paddingLeft.isPixel) {
1728
- this._currentMeasure.left += this._paddingLeft.getValue(this._host);
1729
- this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
1730
- }
1731
- else {
1732
- this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
1733
- this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
1734
- }
1735
- if (this._paddingRight.isPixel) {
1736
- this._currentMeasure.width -= this._paddingRight.getValue(this._host);
1737
- }
1738
- else {
1739
- this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
1740
- }
1741
- if (this._paddingTop.isPixel) {
1742
- this._currentMeasure.top += this._paddingTop.getValue(this._host);
1743
- this._currentMeasure.height -= this._paddingTop.getValue(this._host);
1744
- }
1745
- else {
1746
- this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
1747
- this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
1748
- }
1749
- if (this._paddingBottom.isPixel) {
1750
- this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
1751
- }
1752
- else {
1753
- this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
1754
- }
1755
- }
1756
- if (this._left.isPixel) {
1757
- this._currentMeasure.left += this._left.getValue(this._host);
1758
- }
1759
- else {
1760
- this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
1761
- }
1762
- if (this._top.isPixel) {
1763
- this._currentMeasure.top += this._top.getValue(this._host);
1780
+ const left = this._getValueInPixel(this._paddingLeft, parentWidth);
1781
+ const top = this._getValueInPixel(this._paddingTop, parentHeight);
1782
+ this._currentMeasure.left += left;
1783
+ this._currentMeasure.top += top;
1784
+ this._currentMeasure.width -= left + this._getValueInPixel(this._paddingRight, parentWidth);
1785
+ this._currentMeasure.height -= top + this._getValueInPixel(this._paddingBottom, parentHeight);
1786
+ }
1787
+ const flexMeasure = this.parent?._getLayoutMeasureForChild(this);
1788
+ if (flexMeasure) {
1789
+ x = flexMeasure.left;
1790
+ y = flexMeasure.top;
1764
1791
  }
1765
1792
  else {
1766
- this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
1793
+ this._currentMeasure.left += this._getValueInPixel(this._left, parentWidth);
1794
+ this._currentMeasure.top += this._getValueInPixel(this._top, parentHeight);
1767
1795
  }
1768
1796
  this._currentMeasure.left += x;
1769
1797
  this._currentMeasure.top += y;
@@ -2136,7 +2164,7 @@ let Control = (() => {
2136
2164
  * @returns if the dimension is fully defined
2137
2165
  */
2138
2166
  isDimensionFullyDefined(dim) {
2139
- return this.getDimension(dim).isPixel;
2167
+ return !this.getDimension(dim).isPercentage;
2140
2168
  }
2141
2169
  /**
2142
2170
  * Gets the dimension of the control along a specified axis
@@ -2431,6 +2459,8 @@ let Control = (() => {
2431
2459
  _get_disabledColorItem_decorators = [serialize()];
2432
2460
  _overlapGroup_decorators = [serialize()];
2433
2461
  _overlapDeltaMultiplier_decorators = [serialize()];
2462
+ _get_flexGrow_decorators = [serialize()];
2463
+ _get_flexShrink_decorators = [serialize()];
2434
2464
  __esDecorate(_a, null, _get_clipChildren_decorators, { kind: "getter", name: "clipChildren", static: false, private: false, access: { has: obj => "clipChildren" in obj, get: obj => obj.clipChildren }, metadata: _metadata }, null, _instanceExtraInitializers);
2435
2465
  __esDecorate(_a, null, _get_clipContent_decorators, { kind: "getter", name: "clipContent", static: false, private: false, access: { has: obj => "clipContent" in obj, get: obj => obj.clipContent }, metadata: _metadata }, null, _instanceExtraInitializers);
2436
2466
  __esDecorate(_a, null, _get_shadowOffsetX_decorators, { kind: "getter", name: "shadowOffsetX", static: false, private: false, access: { has: obj => "shadowOffsetX" in obj, get: obj => obj.shadowOffsetX }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -2468,6 +2498,8 @@ let Control = (() => {
2468
2498
  __esDecorate(_a, null, _get_isEnabled_decorators, { kind: "getter", name: "isEnabled", static: false, private: false, access: { has: obj => "isEnabled" in obj, get: obj => obj.isEnabled }, metadata: _metadata }, null, _instanceExtraInitializers);
2469
2499
  __esDecorate(_a, null, _get_disabledColor_decorators, { kind: "getter", name: "disabledColor", static: false, private: false, access: { has: obj => "disabledColor" in obj, get: obj => obj.disabledColor }, metadata: _metadata }, null, _instanceExtraInitializers);
2470
2500
  __esDecorate(_a, null, _get_disabledColorItem_decorators, { kind: "getter", name: "disabledColorItem", static: false, private: false, access: { has: obj => "disabledColorItem" in obj, get: obj => obj.disabledColorItem }, metadata: _metadata }, null, _instanceExtraInitializers);
2501
+ __esDecorate(_a, null, _get_flexGrow_decorators, { kind: "getter", name: "flexGrow", static: false, private: false, access: { has: obj => "flexGrow" in obj, get: obj => obj.flexGrow }, metadata: _metadata }, null, _instanceExtraInitializers);
2502
+ __esDecorate(_a, null, _get_flexShrink_decorators, { kind: "getter", name: "flexShrink", static: false, private: false, access: { has: obj => "flexShrink" in obj, get: obj => obj.flexShrink }, metadata: _metadata }, null, _instanceExtraInitializers);
2471
2503
  __esDecorate(null, null, _metadata_decorators, { kind: "field", name: "metadata", static: false, private: false, access: { has: obj => "metadata" in obj, get: obj => obj.metadata, set: (obj, value) => { obj.metadata = value; } }, metadata: _metadata }, _metadata_initializers, _metadata_extraInitializers);
2472
2504
  __esDecorate(null, null, _isHitTestVisible_decorators, { kind: "field", name: "isHitTestVisible", static: false, private: false, access: { has: obj => "isHitTestVisible" in obj, get: obj => obj.isHitTestVisible, set: (obj, value) => { obj.isHitTestVisible = value; } }, metadata: _metadata }, _isHitTestVisible_initializers, _isHitTestVisible_extraInitializers);
2473
2505
  __esDecorate(null, null, _isPointerBlocker_decorators, { kind: "field", name: "isPointerBlocker", static: false, private: false, access: { has: obj => "isPointerBlocker" in obj, get: obj => obj.isPointerBlocker, set: (obj, value) => { obj.isPointerBlocker = value; } }, metadata: _metadata }, _isPointerBlocker_initializers, _isPointerBlocker_extraInitializers);
@@ -2483,6 +2515,7 @@ let Control = (() => {
2483
2515
  * Gets or sets a boolean indicating if alpha must be an inherited value (false by default)
2484
2516
  */
2485
2517
  _a.AllowAlphaInheritance = false,
2518
+ _a._DefaultFontSize = new ValueAndUnit(18),
2486
2519
  _a._ClipMeasure = new Measure(0, 0, 0, 0),
2487
2520
  // Statics
2488
2521
  _a._HORIZONTAL_ALIGNMENT_LEFT = 0,