laymur 0.2.8 → 0.2.9

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/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export * from "./elements/UIScene";
19
19
  export * from "./elements/UIText";
20
20
  export * from "./layers/UIFullscreenLayer";
21
21
  export * from "./layers/UILayer";
22
+ export * from "./miscellaneous/UIAnchorMode";
22
23
  export * from "./miscellaneous/UIExpression";
23
24
  export * from "./miscellaneous/UIMicro";
24
25
  export * from "./miscellaneous/UIMode";
package/dist/index.js CHANGED
@@ -1815,6 +1815,17 @@ function resolvePriority(priority) {
1815
1815
  return priority ?? UIPriority.P0;
1816
1816
  }
1817
1817
 
1818
+ /**
1819
+ * Defines the anchor mode for UIMicro, determining which transformations are applied around the anchor point.
1820
+ */
1821
+ var UIAnchorMode;
1822
+ (function (UIAnchorMode) {
1823
+ /** Rotation and scaling are applied around the anchor point */
1824
+ UIAnchorMode[UIAnchorMode["ROTATION_SCALE"] = 0] = "ROTATION_SCALE";
1825
+ /** Position, rotation, and scaling transformations are all applied around the anchor point */
1826
+ UIAnchorMode[UIAnchorMode["POSITION_ROTATION_SCALE"] = 1] = "POSITION_ROTATION_SCALE";
1827
+ })(UIAnchorMode || (UIAnchorMode = {}));
1828
+
1818
1829
  const tempColor = new Color();
1819
1830
  class UISceneWrapper {
1820
1831
  constructor(w, h) {
@@ -1897,16 +1908,24 @@ class UISceneWrapper {
1897
1908
  renderer.setClearColor(0x000000, 1);
1898
1909
  for (const [element, object] of this._private_elements) {
1899
1910
  const micro = element.micro;
1900
- const cos = Math.cos(micro.rotation);
1901
- const sin = Math.sin(micro.rotation);
1902
1911
  const width = element.width * micro.scaleX;
1903
1912
  const height = element.height * micro.scaleY;
1904
1913
  const anchorOffsetX = micro.anchorX * width;
1905
1914
  const anchorOffsetY = micro.anchorY * height;
1915
+ const cos = Math.cos(micro.rotation);
1916
+ const sin = Math.sin(micro.rotation);
1906
1917
  const rotatedAnchorX = anchorOffsetX * cos - anchorOffsetY * sin;
1907
1918
  const rotatedAnchorY = anchorOffsetX * sin + anchorOffsetY * cos;
1908
- object.position.x = element.x + micro.x - rotatedAnchorX;
1909
- object.position.y = element.y + micro.y - rotatedAnchorY;
1919
+ if (micro.anchorMode === UIAnchorMode.POSITION_ROTATION_SCALE) {
1920
+ object.position.x = element.x + micro.x - rotatedAnchorX;
1921
+ object.position.y = element.y + micro.y - rotatedAnchorY;
1922
+ }
1923
+ else {
1924
+ const rawAnchorOffsetX = micro.anchorX * element.width;
1925
+ const rawAnchorOffsetY = micro.anchorY * element.height;
1926
+ object.position.x = element.x + rawAnchorOffsetX - rotatedAnchorX;
1927
+ object.position.y = element.y + rawAnchorOffsetY - rotatedAnchorY;
1928
+ }
1910
1929
  object.scale.x = width;
1911
1930
  object.scale.y = height;
1912
1931
  object.rotation.z = micro.rotation;
@@ -3626,7 +3645,7 @@ class UIDummy extends UIAnchor {
3626
3645
  /** Default position value for x and y coordinates. */
3627
3646
  const DEFAULT_POSITION = 0;
3628
3647
  /** Default anchor point value for anchorX and anchorY. */
3629
- const DEFAULT_ANCHOR = 0;
3648
+ const DEFAULT_ANCHOR = 0.5;
3630
3649
  /** Default scale value for scaleX and scaleY. */
3631
3650
  const DEFAULT_SCALE = 1;
3632
3651
  /** Default rotation value in radians. */
@@ -3661,6 +3680,8 @@ class UIMicro {
3661
3680
  this._private_scaleYInternal = DEFAULT_SCALE;
3662
3681
  /** Internal storage for rotation in radians. */
3663
3682
  this._private_rotationInternal = DEFAULT_ROTATION;
3683
+ /** Internal storage for anchor mode determining which transformations are applied around the anchor point. */
3684
+ this._private_anchorModeInternal = UIAnchorMode.ROTATION_SCALE;
3664
3685
  /** Flag indicating if any transformation properties have changed. */
3665
3686
  this._private_recalculationRequired = false;
3666
3687
  }
@@ -3720,6 +3741,13 @@ class UIMicro {
3720
3741
  get angle() {
3721
3742
  return MathUtils.radToDeg(this._private_rotationInternal);
3722
3743
  }
3744
+ /**
3745
+ * Gets the current anchor mode determining which transformations are applied around the anchor point.
3746
+ * @returns The anchor mode (ROTATION_SCALE or POSITION_ROTATION_SCALE)
3747
+ */
3748
+ get anchorMode() {
3749
+ return this._private_anchorModeInternal;
3750
+ }
3723
3751
  /**
3724
3752
  * Gets the rotation angle in radians.
3725
3753
  * @returns The rotation angle in radians
@@ -3819,6 +3847,16 @@ class UIMicro {
3819
3847
  this._private_recalculationRequired = true;
3820
3848
  }
3821
3849
  }
3850
+ /**
3851
+ * Sets the anchor mode determining which transformations are applied around the anchor point.
3852
+ * @param value - The anchor mode (ROTATION_SCALE or POSITION_ROTATION_SCALE)
3853
+ */
3854
+ set anchorMode(value) {
3855
+ if (value !== this._private_anchorModeInternal) {
3856
+ this._private_anchorModeInternal = value;
3857
+ this._private_recalculationRequired = true;
3858
+ }
3859
+ }
3822
3860
  /**
3823
3861
  * Resets all transformation properties to their default values.
3824
3862
  *
@@ -5599,5 +5637,5 @@ function isUITextSpan(obj) {
5599
5637
  (!("style" in obj) || isUITextStyle(obj.style)));
5600
5638
  }
5601
5639
 
5602
- export { UIAnchor, UIAspectConstraint, UIConstraint, UIConstraint2DBuilder, UICustomConstraint, UIDummy, UIElement, UIElementEvent, UIExpression, UIFullscreenLayer, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UILayer, UILayerEvent, UIMicro, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIRelation, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePadding, resolvePriority, resolveRelation, resolveTextStyle };
5640
+ export { UIAnchor, UIAnchorMode, UIAspectConstraint, UIConstraint, UIConstraint2DBuilder, UICustomConstraint, UIDummy, UIElement, UIElementEvent, UIExpression, UIFullscreenLayer, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UILayer, UILayerEvent, UIMicro, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIRelation, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePadding, resolvePriority, resolveRelation, resolveTextStyle };
5603
5641
  //# sourceMappingURL=index.js.map