@galacean/engine-ui 1.5.14 → 1.6.0-alpha.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/dist/browser.js CHANGED
@@ -516,20 +516,46 @@
516
516
  return ResolutionAdaptationMode;
517
517
  }({});
518
518
 
519
+ /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
520
+ /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
521
+ /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
522
+ /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
523
+ /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
524
+ /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
525
+ return HorizontalAlignmentMode;
526
+ }({});
527
+
528
+ /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
529
+ /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
530
+ /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
531
+ /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
532
+ /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
533
+ /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
534
+ return VerticalAlignmentMode;
535
+ }({});
536
+
519
537
  /**
520
538
  * The Transform component exclusive to the UI element.
521
539
  */ var UITransform = /*#__PURE__*/ function(Transform) {
522
540
  _inherits(UITransform, Transform);
523
541
  function UITransform(entity) {
524
542
  var _this;
525
- _this = Transform.call(this, entity) || this, _this._size = new engine.Vector2(100, 100), _this._pivot = new engine.Vector2(0.5, 0.5);
543
+ _this = Transform.call(this, entity) || this, _this._size = new engine.Vector2(100, 100), _this._pivot = new engine.Vector2(0.5, 0.5), _this._rect = new engine.Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
544
+ _this._onSizeChanged = _this._onSizeChanged.bind(_this);
545
+ _this._onPivotChanged = _this._onPivotChanged.bind(_this);
526
546
  // @ts-ignore
527
- _this._size._onValueChanged = _this._onSizeChange.bind(_this);
547
+ _this._size._onValueChanged = _this._onSizeChanged;
528
548
  // @ts-ignore
529
- _this._pivot._onValueChanged = _this._onPivotChange.bind(_this);
549
+ _this._pivot._onValueChanged = _this._onPivotChanged;
530
550
  return _this;
531
551
  }
532
552
  var _proto = UITransform.prototype;
553
+ /**
554
+ * @internal
555
+ */ _proto._parentChange = function _parentChange() {
556
+ this._isParentDirty = true;
557
+ this._updateWorldFlagWithParentRectChange(engine.TransformModifyFlags.WmWpWeWqWsWus);
558
+ };
533
559
  // @ts-ignore
534
560
  _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
535
561
  // @ts-ignore
@@ -537,14 +563,139 @@
537
563
  target.size.copyFrom(this._size);
538
564
  target.pivot.copyFrom(this._pivot);
539
565
  };
540
- _proto._onSizeChange = function _onSizeChange() {
566
+ _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
567
+ this._updatePositionByAlignment();
568
+ };
569
+ _proto._onWorldMatrixChange = function _onWorldMatrixChange() {
570
+ !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChange.call(this);
571
+ };
572
+ _proto._onPositionChanged = function _onPositionChanged() {
573
+ (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
574
+ Transform.prototype._onPositionChanged.call(this);
575
+ };
576
+ _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
577
+ Transform.prototype._onWorldPositionChanged.call(this);
578
+ if (this._horizontalAlignment || this._verticalAlignment) {
579
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.WorldPosition);
580
+ }
581
+ };
582
+ _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
583
+ var _this__getParentTransform;
584
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
585
+ if (parentRect) {
586
+ var position = this.position;
587
+ // @ts-ignore
588
+ position._onValueChanged = null;
589
+ var rect = this._rect;
590
+ switch(this._horizontalAlignment){
591
+ case HorizontalAlignmentMode.Left:
592
+ case HorizontalAlignmentMode.LeftAndRight:
593
+ position.x = parentRect.x - rect.x + this._alignLeft;
594
+ break;
595
+ case HorizontalAlignmentMode.Center:
596
+ position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
597
+ break;
598
+ case HorizontalAlignmentMode.Right:
599
+ position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
600
+ break;
601
+ }
602
+ switch(this._verticalAlignment){
603
+ case VerticalAlignmentMode.Top:
604
+ position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
605
+ break;
606
+ case VerticalAlignmentMode.Middle:
607
+ position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
608
+ break;
609
+ case VerticalAlignmentMode.Bottom:
610
+ case VerticalAlignmentMode.TopAndBottom:
611
+ position.y = parentRect.y - rect.y + this._alignBottom;
612
+ break;
613
+ }
614
+ // @ts-ignore
615
+ position._onValueChanged = this._onPositionChanged;
616
+ }
617
+ };
618
+ _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
619
+ var _this__getParentTransform;
620
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
621
+ if (parentRect) {
622
+ var size = this._size;
623
+ // @ts-ignore
624
+ size._onValueChanged = null;
625
+ // The values of size must be greater than 0
626
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
627
+ size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
628
+ }
629
+ if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
630
+ size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
631
+ }
632
+ // @ts-ignore
633
+ size._onValueChanged = this._onSizeChanged;
634
+ }
635
+ };
636
+ _proto._updateRectByPivot = function _updateRectByPivot() {
637
+ var _this = this, size = _this.size, pivot = _this._pivot;
638
+ var x = -pivot.x * size.x;
639
+ var y = -pivot.y * size.y;
640
+ this._rect.set(x, y, size.x, size.y);
641
+ };
642
+ _proto._onSizeChanged = function _onSizeChanged() {
643
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
644
+ this._updateSizeByAlignment();
645
+ }
646
+ this._updateRectByPivot();
647
+ this._updateWorldFlagWithSelfRectChange();
541
648
  // @ts-ignore
542
649
  this._entity._updateFlagManager.dispatch(512);
543
650
  };
544
- _proto._onPivotChange = function _onPivotChange() {
651
+ _proto._onPivotChanged = function _onPivotChanged() {
652
+ this._updateRectByPivot();
653
+ this._updateWorldFlagWithSelfRectChange();
545
654
  // @ts-ignore
546
655
  this._entity._updateFlagManager.dispatch(1024);
547
656
  };
657
+ _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
658
+ var worldFlags = 0;
659
+ if (this._horizontalAlignment || this._verticalAlignment) {
660
+ this._updatePositionByAlignment();
661
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
662
+ worldFlags = engine.TransformModifyFlags.WmWp;
663
+ !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
664
+ }
665
+ var children = this.entity.children;
666
+ for(var i = 0, n = children.length; i < n; i++){
667
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
668
+ (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, worldFlags);
669
+ }
670
+ };
671
+ _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
672
+ if (parentChange === void 0) parentChange = true;
673
+ var selfChange = false;
674
+ if (parentChange) {
675
+ var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
676
+ if (horizontalAlignment || verticalAlignment) {
677
+ if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
678
+ this._updateSizeByAlignment();
679
+ this._updateRectByPivot();
680
+ selfChange = true;
681
+ }
682
+ this._updatePositionByAlignment();
683
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
684
+ flags |= engine.TransformModifyFlags.WmWp;
685
+ }
686
+ }
687
+ var containDirtyFlags = this._isContainDirtyFlags(flags);
688
+ !containDirtyFlags && this._worldAssociatedChange(flags);
689
+ if (selfChange || !containDirtyFlags) {
690
+ var children = this.entity.children;
691
+ for(var i = 0, n = children.length; i < n; i++){
692
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
693
+ (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, flags, selfChange);
694
+ }
695
+ }
696
+ // @ts-ignore
697
+ selfChange && this._entity._updateFlagManager.dispatch(512);
698
+ };
548
699
  _create_class(UITransform, [
549
700
  {
550
701
  key: "size",
@@ -571,6 +722,178 @@
571
722
  if (pivot === value) return;
572
723
  (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
573
724
  }
725
+ },
726
+ {
727
+ key: "horizontalAlignment",
728
+ get: /**
729
+ * Horizontal alignment mode.
730
+ *
731
+ * @remarks
732
+ * Controls how the element aligns horizontally within its parent:
733
+ * - `Left` - Align to parent's left edge
734
+ * - `Center` - Align to parent's horizontal center
735
+ * - `Right` - Align to parent's right edge
736
+ * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
737
+ */ function get() {
738
+ return this._horizontalAlignment;
739
+ },
740
+ set: function set(value) {
741
+ if (this._horizontalAlignment === value) return;
742
+ this._horizontalAlignment = value;
743
+ switch(value){
744
+ case HorizontalAlignmentMode.Left:
745
+ case HorizontalAlignmentMode.Right:
746
+ case HorizontalAlignmentMode.Center:
747
+ this._onPositionChanged();
748
+ break;
749
+ case HorizontalAlignmentMode.LeftAndRight:
750
+ this._onPositionChanged();
751
+ this._onSizeChanged();
752
+ break;
753
+ }
754
+ }
755
+ },
756
+ {
757
+ key: "alignLeft",
758
+ get: /**
759
+ * Left margin when horizontalAlignment is Left or LeftAndRight.
760
+ *
761
+ * @remarks
762
+ * Only effective when horizontalAlignment includes Left mode.
763
+ * Distance from the parent's left edge to the element's left edge.
764
+ */ function get() {
765
+ return this._alignLeft;
766
+ },
767
+ set: function set(value) {
768
+ if (!Number.isFinite(value)) return;
769
+ if (engine.MathUtil.equals(value, this._alignLeft)) return;
770
+ this._alignLeft = value;
771
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
772
+ this._onPositionChanged();
773
+ this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
774
+ }
775
+ }
776
+ },
777
+ {
778
+ key: "alignRight",
779
+ get: /**
780
+ * Right margin when horizontalAlignment is Right or LeftAndRight.
781
+ *
782
+ * @remarks
783
+ * Only effective when horizontalAlignment includes Right mode.
784
+ * Distance from the parent's right edge to the element's right edge.
785
+ */ function get() {
786
+ return this._alignRight;
787
+ },
788
+ set: function set(value) {
789
+ if (!Number.isFinite(value)) return;
790
+ if (engine.MathUtil.equals(value, this._alignRight)) return;
791
+ this._alignRight = value;
792
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
793
+ this._onPositionChanged();
794
+ this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
795
+ }
796
+ }
797
+ },
798
+ {
799
+ key: "alignCenter",
800
+ get: /**
801
+ * Horizontal center offset when horizontalAlignment is Center.
802
+ *
803
+ * @remarks
804
+ * Only effective when horizontalAlignment is Center mode.
805
+ * Positive values move the element to the right, negative values to the left.
806
+ */ function get() {
807
+ return this._alignCenter;
808
+ },
809
+ set: function set(value) {
810
+ if (!Number.isFinite(value)) return;
811
+ if (engine.MathUtil.equals(value, this._alignCenter)) return;
812
+ this._alignCenter = value;
813
+ this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
814
+ }
815
+ },
816
+ {
817
+ key: "verticalAlignment",
818
+ get: /**
819
+ * Vertical alignment mode.
820
+ *
821
+ * @remarks
822
+ * Controls how the element aligns vertically within its parent:
823
+ * - `Top` - Align to parent's top edge
824
+ * - `Middle` - Align to parent's vertical center
825
+ * - `Bottom` - Align to parent's bottom edge
826
+ * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
827
+ */ function get() {
828
+ return this._verticalAlignment;
829
+ },
830
+ set: function set(value) {
831
+ if (this._verticalAlignment === value) return;
832
+ this._verticalAlignment = value;
833
+ switch(value){
834
+ case VerticalAlignmentMode.Top:
835
+ case VerticalAlignmentMode.Bottom:
836
+ case VerticalAlignmentMode.Middle:
837
+ this._onPositionChanged();
838
+ break;
839
+ case VerticalAlignmentMode.TopAndBottom:
840
+ this._onPositionChanged();
841
+ this._onSizeChanged();
842
+ break;
843
+ }
844
+ }
845
+ },
846
+ {
847
+ key: "alignTop",
848
+ get: /**
849
+ * Top margin when verticalAlignment is Top or TopAndBottom.
850
+ *
851
+ * @remarks
852
+ * Only effective when verticalAlignment includes Top mode.
853
+ * Used to offset the element from the parent's top edge.
854
+ */ function get() {
855
+ return this._alignTop;
856
+ },
857
+ set: function set(value) {
858
+ if (!Number.isFinite(value)) return;
859
+ if (engine.MathUtil.equals(value, this._alignTop)) return;
860
+ this._alignTop = value;
861
+ if (this._verticalAlignment & VerticalAlignmentMode.Top) {
862
+ this._onPositionChanged();
863
+ this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
864
+ }
865
+ }
866
+ },
867
+ {
868
+ key: "alignBottom",
869
+ get: /**
870
+ * Bottom inset used in vertical alignment formulas.
871
+ */ function get() {
872
+ return this._alignBottom;
873
+ },
874
+ set: function set(value) {
875
+ if (!Number.isFinite(value)) return;
876
+ if (engine.MathUtil.equals(value, this._alignBottom)) return;
877
+ this._alignBottom = value;
878
+ if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
879
+ this._onPositionChanged();
880
+ this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
881
+ }
882
+ }
883
+ },
884
+ {
885
+ key: "alignMiddle",
886
+ get: /**
887
+ * Vertical middle offset relative to parent's middle.
888
+ */ function get() {
889
+ return this._alignMiddle;
890
+ },
891
+ set: function set(value) {
892
+ if (!Number.isFinite(value)) return;
893
+ if (engine.MathUtil.equals(value, this._alignMiddle)) return;
894
+ this._alignMiddle = value;
895
+ this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
896
+ }
574
897
  }
575
898
  ]);
576
899
  return UITransform;
@@ -583,16 +906,25 @@
583
906
  ], UITransform.prototype, "_pivot", void 0);
584
907
  __decorate([
585
908
  engine.ignoreClone
586
- ], UITransform.prototype, "_onSizeChange", null);
909
+ ], UITransform.prototype, "_rect", void 0);
587
910
  __decorate([
588
911
  engine.ignoreClone
589
- ], UITransform.prototype, "_onPivotChange", null);
912
+ ], UITransform.prototype, "_onPositionChanged", null);
913
+ __decorate([
914
+ engine.ignoreClone
915
+ ], UITransform.prototype, "_onWorldPositionChanged", null);
916
+ __decorate([
917
+ engine.ignoreClone
918
+ ], UITransform.prototype, "_onSizeChanged", null);
919
+ __decorate([
920
+ engine.ignoreClone
921
+ ], UITransform.prototype, "_onPivotChanged", null);
590
922
  /**
591
923
  * @internal
592
924
  * extends TransformModifyFlags
593
925
  */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
594
- /** Size. */ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
595
- /** Pivot. */ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
926
+ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
927
+ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
596
928
  return UITransformModifyFlags;
597
929
  }({});
598
930
 
@@ -2369,7 +2701,6 @@
2369
2701
  };
2370
2702
  _proto._buildChunk = function _buildChunk(textChunk, count) {
2371
2703
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
2372
- var finalAlpha = a * this._getGlobalAlpha();
2373
2704
  var tempIndices = engine.CharRenderInfo.triangles;
2374
2705
  var tempIndicesLength = tempIndices.length;
2375
2706
  var subChunk = textChunk.subChunk = this._getChunkManager().allocateSubChunk(count * 4);
@@ -2390,7 +2721,7 @@
2390
2721
  vertices[vo + 2] = r;
2391
2722
  vertices[vo + 3] = g;
2392
2723
  vertices[vo + 4] = b;
2393
- vertices[vo + 5] = finalAlpha;
2724
+ vertices[vo + 5] = a;
2394
2725
  }
2395
2726
  }
2396
2727
  return subChunk;
@@ -3289,6 +3620,7 @@
3289
3620
  exports.ColorTransition = ColorTransition;
3290
3621
  exports.EngineExtension = EngineExtension;
3291
3622
  exports.EntityExtension = EntityExtension;
3623
+ exports.HorizontalAlignmentMode = HorizontalAlignmentMode;
3292
3624
  exports.Image = Image;
3293
3625
  exports.ResolutionAdaptationMode = ResolutionAdaptationMode;
3294
3626
  exports.ScaleTransition = ScaleTransition;
@@ -3297,6 +3629,7 @@
3297
3629
  exports.Transition = Transition;
3298
3630
  exports.UIGroup = UIGroup;
3299
3631
  exports.UITransform = UITransform;
3632
+ exports.VerticalAlignmentMode = VerticalAlignmentMode;
3300
3633
  exports.registerGUI = registerGUI;
3301
3634
 
3302
3635
  Object.defineProperty(exports, '__esModule', { value: true });