@galacean/engine-ui 2.0.0-alpha.43 → 2.0.0-alpha.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-ui",
3
- "version": "2.0.0-alpha.43",
3
+ "version": "2.0.0-alpha.45",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -27,10 +27,10 @@
27
27
  "types/**/*"
28
28
  ],
29
29
  "devDependencies": {
30
- "@galacean/engine": "2.0.0-alpha.43"
30
+ "@galacean/engine": "2.0.0-alpha.45"
31
31
  },
32
32
  "peerDependencies": {
33
- "@galacean/engine": "2.0.0-alpha.43"
33
+ "@galacean/engine": "2.0.0-alpha.45"
34
34
  },
35
35
  "scripts": {
36
36
  "b:types": "tsc"
@@ -1 +1,37 @@
1
- export {};
1
+ import { Matrix, RenderElement } from "@galacean/engine";
2
+ /**
3
+ * @internal
4
+ * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
5
+ *
6
+ * Think of it as stacking elements onto numbered shelves (depths):
7
+ * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
8
+ * - Overlapping + batch-compatible — share the same shelf, still cluster.
9
+ * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
10
+ *
11
+ * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
12
+ * share the same depth and get clustered together. Once depth is assigned, sort by
13
+ * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
14
+ * by-product of materials clustering within each depth band.
15
+ *
16
+ * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
17
+ * are derived from the union AABB of input elements (the bounds transform itself is the
18
+ * work the loop must do anyway, so the union accumulation just piggybacks). This stays
19
+ * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
20
+ * on canvas configuration.
21
+ */
22
+ export declare class UIBatchSorter {
23
+ private static readonly _gridDim;
24
+ private static readonly _entries;
25
+ private static readonly _grid;
26
+ private static readonly _dirtyCells;
27
+ private static readonly _localBoundsPool;
28
+ private static readonly _worldToLocal;
29
+ /**
30
+ * Reorders `elements` in place for optimal batching.
31
+ * @param elements - in hierarchy order (depth-first traversal); mutated in place
32
+ * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
33
+ */
34
+ static sort(elements: RenderElement[], canvasWorldMatrix: Matrix): void;
35
+ private static _rectOverlap;
36
+ private static _compareEntries;
37
+ }
@@ -1,16 +1,44 @@
1
- import { Camera, Component, Vector2 } from "@galacean/engine";
1
+ import { Camera, Component, DisorderedArray, Entity, Ray, RenderElement, Vector2, Vector3 } from "@galacean/engine";
2
2
  import type { ICloneHook } from "@galacean/engine";
3
3
  import { CanvasRenderMode } from "../enums/CanvasRenderMode";
4
4
  import { ResolutionAdaptationMode } from "../enums/ResolutionAdaptationMode";
5
+ import { UIHitResult } from "../input/UIHitResult";
5
6
  import { IElement } from "../interface/IElement";
7
+ import { UIRenderer } from "./UIRenderer";
6
8
  /**
7
9
  * The UI Canvas component serves as the root node for UI elements,
8
10
  * handling rendering and events based on it.
9
11
  */
10
12
  export declare class UICanvas extends Component implements IElement, ICloneHook<UICanvas> {
13
+ /** @internal */
14
+ static _hierarchyCounter: number;
11
15
  private static _tempGroupAbleList;
12
16
  private static _tempVec3;
13
17
  private static _tempMat;
18
+ /** @internal */
19
+ _canvasIndex: number;
20
+ /** @internal */
21
+ _rootCanvas: UICanvas;
22
+ /** @internal */
23
+ _indexInRootCanvas: number;
24
+ /** @internal */
25
+ _isRootCanvasDirty: boolean;
26
+ /** @internal */
27
+ _rootCanvasListeningEntities: Entity[];
28
+ /** @internal */
29
+ _isRootCanvas: boolean;
30
+ /** @internal */
31
+ _renderElements: RenderElement[];
32
+ /** @internal */
33
+ _batchedRenderElements: RenderElement[];
34
+ /** @internal */
35
+ _sortDistance: number;
36
+ /** @internal */
37
+ _orderedRenderers: UIRenderer[];
38
+ /** @internal */
39
+ _realRenderMode: number;
40
+ /** @internal */
41
+ _disorderedElements: DisorderedArray<IElement>;
14
42
  private _renderMode;
15
43
  private _camera;
16
44
  private _cameraObserver;
@@ -65,9 +93,41 @@ export declare class UICanvas extends Component implements IElement, ICloneHook<
65
93
  */
66
94
  get distance(): number;
67
95
  set distance(value: number);
96
+ /**
97
+ * @internal
98
+ */
99
+ constructor(entity: Entity);
100
+ /**
101
+ * @internal
102
+ */
103
+ _raycast(ray: Ray, out: UIHitResult, distance?: number): boolean;
104
+ /**
105
+ * @internal
106
+ */
107
+ _getRootCanvas(): UICanvas;
108
+ /**
109
+ * @internal
110
+ */
111
+ _canRender(camera: Camera): boolean;
112
+ /**
113
+ * @internal
114
+ */
115
+ _canDispatchEvent(camera: Camera): boolean;
116
+ /**
117
+ * @internal
118
+ */
119
+ _prepareRender(context: any): void;
120
+ /**
121
+ * @internal
122
+ */
123
+ _updateSortDistance(isOrthographic: boolean, cameraPosition: Vector3, cameraForward: Vector3): void;
68
124
  _onEnableInScene(): void;
69
125
  _onDisableInScene(): void;
70
126
  _onDisable(): void;
127
+ /**
128
+ * @internal
129
+ */
130
+ _rootCanvasListener(flag: number, param: any): void;
71
131
  /**
72
132
  * @inheritdoc
73
133
  */
@@ -1,9 +1,34 @@
1
- import { Component, Entity } from "@galacean/engine";
1
+ import { Component, DisorderedArray, Entity } from "@galacean/engine";
2
2
  import { IGroupAble } from "../interface/IGroupAble";
3
+ import { UICanvas } from "./UICanvas";
3
4
  export declare class UIGroup extends Component implements IGroupAble {
5
+ /** @internal */
6
+ _indexInGroup: number;
7
+ /** @internal */
8
+ _indexInRootCanvas: number;
9
+ /** @internal */
10
+ _group: UIGroup;
11
+ /** @internal */
12
+ _rootCanvas: UICanvas;
13
+ /** @internal */
14
+ _disorderedElements: DisorderedArray<IGroupAble>;
15
+ /** @internal */
16
+ _globalAlpha: number;
17
+ /** @internal */
18
+ _globalInteractive: boolean;
4
19
  private _alpha;
5
20
  private _interactive;
6
21
  private _ignoreParentGroup;
22
+ /** @internal */
23
+ _rootCanvasListeningEntities: Entity[];
24
+ /** @internal */
25
+ _groupListeningEntities: Entity[];
26
+ /** @internal */
27
+ _isRootCanvasDirty: boolean;
28
+ /** @internal */
29
+ _isGroupDirty: boolean;
30
+ /** @internal */
31
+ _groupDirtyFlags: number;
7
32
  /**
8
33
  * Whether to ignore the parent group.
9
34
  * @remarks If this parameter set to `true`,
@@ -21,9 +46,37 @@ export declare class UIGroup extends Component implements IGroupAble {
21
46
  */
22
47
  get alpha(): number;
23
48
  set alpha(value: number);
49
+ /**
50
+ * @internal
51
+ */
52
+ _getGlobalAlpha(): number;
53
+ /**
54
+ * @internal
55
+ */
56
+ _getGlobalInteractive(): boolean;
24
57
  constructor(entity: Entity);
25
58
  _onEnableInScene(): void;
26
59
  _onDisableInScene(): void;
60
+ /**
61
+ * @internal
62
+ */
63
+ _getRootCanvas(): UICanvas;
64
+ /**
65
+ * @internal
66
+ */
67
+ _getGroup(): UIGroup;
68
+ /**
69
+ * @internal
70
+ */
71
+ _groupListener(flag: number): void;
72
+ /**
73
+ * @internal
74
+ */
75
+ _rootCanvasListener(flag: number): void;
76
+ /**
77
+ * @internal
78
+ */
79
+ _onGroupModify(flags: GroupModifyFlags, isPass?: boolean): void;
27
80
  private _isContainDirtyFlags;
28
81
  private _isContainDirtyFlag;
29
82
  private _setDirtyFlagTrue;
@@ -1,11 +1,43 @@
1
- import { Color, Renderer, Vector3, Vector4 } from "@galacean/engine";
1
+ import { Color, Entity, Matrix, Plane, Ray, Renderer, ShaderProperty, Vector3, Vector4 } from "@galacean/engine";
2
+ import type { PrimitiveChunkManager } from "@galacean/engine";
3
+ import { UIHitResult } from "../input/UIHitResult";
2
4
  import { IGraphics } from "../interface/IGraphics";
5
+ import { UICanvas } from "./UICanvas";
6
+ import { GroupModifyFlags, UIGroup } from "./UIGroup";
3
7
  export declare class UIRenderer extends Renderer implements IGraphics {
8
+ /** @internal */
9
+ static _tempVec30: Vector3;
10
+ /** @internal */
11
+ static _tempVec31: Vector3;
12
+ /** @internal */
13
+ static _tempMat: Matrix;
14
+ /** @internal */
15
+ static _tempPlane: Plane;
16
+ /** @internal */
17
+ static _textureProperty: ShaderProperty;
4
18
  /**
5
19
  * Custom boundary for raycast detection.
6
20
  * @remarks this is based on `this.entity.transform`.
7
21
  */
8
22
  raycastPadding: Vector4;
23
+ /** @internal */
24
+ _rootCanvas: UICanvas;
25
+ /** @internal */
26
+ _indexInRootCanvas: number;
27
+ /** @internal */
28
+ _isRootCanvasDirty: boolean;
29
+ /** @internal */
30
+ _rootCanvasListeningEntities: Entity[];
31
+ /** @internal */
32
+ _group: UIGroup;
33
+ /** @internal */
34
+ _indexInGroup: number;
35
+ /** @internal */
36
+ _isGroupDirty: boolean;
37
+ /** @internal */
38
+ _groupListeningEntities: Entity[];
39
+ /** @internal */
40
+ _subChunk: any;
9
41
  private _raycastEnabled;
10
42
  protected _color: Color;
11
43
  /**
@@ -18,13 +50,49 @@ export declare class UIRenderer extends Renderer implements IGraphics {
18
50
  */
19
51
  get raycastEnabled(): boolean;
20
52
  set raycastEnabled(value: boolean);
53
+ /**
54
+ * @internal
55
+ */
56
+ constructor(entity: Entity);
21
57
  _canBatch(preElement: any, curElement: any): boolean;
22
58
  _batch(preElement: any, curElement: any): void;
23
59
  _updateTransformShaderData(context: any, onlyMVP: boolean): void;
24
60
  _prepareRender(context: any): void;
25
61
  _onEnableInScene(): void;
26
62
  _onDisableInScene(): void;
63
+ /**
64
+ * @internal
65
+ */
66
+ _getGlobalAlpha(): number;
67
+ /**
68
+ * @internal
69
+ */
70
+ _getRootCanvas(): UICanvas;
71
+ /**
72
+ * @internal
73
+ */
74
+ _getGroup(): UIGroup;
75
+ /**
76
+ * @internal
77
+ */
78
+ _groupListener(flag: number): void;
79
+ /**
80
+ * @internal
81
+ */
82
+ _rootCanvasListener(flag: number, entity: Entity): void;
83
+ /**
84
+ * @internal
85
+ */
86
+ _onGroupModify(flags: GroupModifyFlags): void;
27
87
  private _onColorChanged;
88
+ /**
89
+ * @internal
90
+ */
91
+ _getChunkManager(): PrimitiveChunkManager;
92
+ /**
93
+ * @internal
94
+ */
95
+ _raycast(ray: Ray, out: UIHitResult, distance?: number): boolean;
28
96
  protected _hitTest(localPosition: Vector3): boolean;
29
97
  protected _onDestroy(): void;
30
98
  }
@@ -1,4 +1,4 @@
1
- import { Transform, Vector2 } from "@galacean/engine";
1
+ import { Entity, Transform, Vector2 } from "@galacean/engine";
2
2
  import { HorizontalAlignmentMode } from "../enums/HorizontalAlignmentMode";
3
3
  import { VerticalAlignmentMode } from "../enums/VerticalAlignmentMode";
4
4
  /**
@@ -96,6 +96,14 @@ export declare class UITransform extends Transform {
96
96
  */
97
97
  get alignMiddle(): number;
98
98
  set alignMiddle(value: number);
99
+ /**
100
+ * @internal
101
+ */
102
+ constructor(entity: Entity);
103
+ /**
104
+ * @internal
105
+ */
106
+ _parentChange(): void;
99
107
  /**
100
108
  * @inheritdoc
101
109
  */
@@ -112,3 +120,11 @@ export declare class UITransform extends Transform {
112
120
  private _updateWorldFlagWithSelfRectChange;
113
121
  private _updateWorldFlagWithParentRectChange;
114
122
  }
123
+ /**
124
+ * @internal
125
+ * extends TransformModifyFlags
126
+ */
127
+ export declare enum UITransformModifyFlags {
128
+ Size = 512,
129
+ Pivot = 1024
130
+ }
@@ -1,4 +1,5 @@
1
- import { BoundingBox, ISpriteRenderer, Sprite, SpriteDrawMode, SpriteTileMode } from "@galacean/engine";
1
+ import { BoundingBox, Entity, ISpriteRenderer, Sprite, SpriteDrawMode, SpriteTileMode } from "@galacean/engine";
2
+ import { RootCanvasModifyFlags } from "../UICanvas";
2
3
  import { UIRenderer } from "../UIRenderer";
3
4
  /**
4
5
  * UI element that renders an image.
@@ -29,6 +30,14 @@ export declare class Image extends UIRenderer implements ISpriteRenderer {
29
30
  */
30
31
  get sprite(): Sprite;
31
32
  set sprite(value: Sprite | null);
33
+ /**
34
+ * @internal
35
+ */
36
+ constructor(entity: Entity);
37
+ /**
38
+ * @internal
39
+ */
40
+ _onRootCanvasModify(flag: RootCanvasModifyFlags): void;
32
41
  /**
33
42
  * @inheritdoc
34
43
  */
@@ -1,4 +1,5 @@
1
- import { BoundingBox, Entity, Font, FontStyle, ITextRenderer, OverflowMode, TextHorizontalAlignment, TextVerticalAlignment } from "@galacean/engine";
1
+ import { BoundingBox, Entity, Font, FontStyle, ITextRenderer, OverflowMode, SubFont, TextHorizontalAlignment, TextVerticalAlignment } from "@galacean/engine";
2
+ import { RootCanvasModifyFlags } from "../UICanvas";
2
3
  import { UIRenderer } from "../UIRenderer";
3
4
  /**
4
5
  * UI component used to render text.
@@ -80,6 +81,30 @@ export declare class Text extends UIRenderer implements ITextRenderer {
80
81
  */
81
82
  get bounds(): BoundingBox;
82
83
  constructor(entity: Entity);
84
+ /**
85
+ * @internal
86
+ */
87
+ protected _onDestroy(): void;
88
+ /**
89
+ * @internal
90
+ */
91
+ _isContainDirtyFlag(type: number): boolean;
92
+ /**
93
+ * @internal
94
+ */
95
+ _setDirtyFlagTrue(type: number): void;
96
+ /**
97
+ * @internal
98
+ */
99
+ _setDirtyFlagFalse(type: number): void;
100
+ /**
101
+ * @internal
102
+ */
103
+ _getSubFont(): SubFont;
104
+ /**
105
+ * @internal
106
+ */
107
+ _onRootCanvasModify(flag: RootCanvasModifyFlags): void;
83
108
  protected _updateBounds(worldBounds: BoundingBox): void;
84
109
  protected _render(context: any): void;
85
110
  private _resetSubFont;
@@ -1,10 +1,33 @@
1
- import { Script } from "@galacean/engine";
1
+ import { Entity, Script } from "@galacean/engine";
2
+ import { UIGroup } from "../..";
2
3
  import { IGroupAble } from "../../interface/IGroupAble";
4
+ import { UICanvas } from "../UICanvas";
5
+ import { GroupModifyFlags } from "../UIGroup";
3
6
  import { Transition } from "./transition/Transition";
4
7
  /**
5
8
  * Interactive component.
6
9
  */
7
10
  export declare class UIInteractive extends Script implements IGroupAble {
11
+ /** @internal */
12
+ _rootCanvas: UICanvas;
13
+ /** @internal */
14
+ _indexInRootCanvas: number;
15
+ /** @internal */
16
+ _isRootCanvasDirty: boolean;
17
+ /** @internal */
18
+ _rootCanvasListeningEntities: Entity[];
19
+ /** @internal */
20
+ _group: UIGroup;
21
+ /** @internal */
22
+ _indexInGroup: number;
23
+ /** @internal */
24
+ _isGroupDirty: boolean;
25
+ /** @internal */
26
+ _groupListeningEntities: Entity[];
27
+ /** @internal */
28
+ _globalInteractive: boolean;
29
+ /** @internal */
30
+ _globalInteractiveDirty: boolean;
8
31
  protected _transitions: Transition[];
9
32
  protected _interactive: boolean;
10
33
  protected _state: InteractiveState;
@@ -20,6 +43,10 @@ export declare class UIInteractive extends Script implements IGroupAble {
20
43
  */
21
44
  get interactive(): boolean;
22
45
  set interactive(value: boolean);
46
+ /**
47
+ * @internal
48
+ */
49
+ constructor(entity: Entity);
23
50
  /**
24
51
  * Add transition on this interactive.
25
52
  * @param transition - The transition
@@ -40,8 +67,32 @@ export declare class UIInteractive extends Script implements IGroupAble {
40
67
  onPointerEnter(): void;
41
68
  onPointerExit(): void;
42
69
  onDestroy(): void;
70
+ /**
71
+ * @internal
72
+ */
73
+ _getRootCanvas(): UICanvas;
74
+ /**
75
+ * @internal
76
+ */
77
+ _getGroup(): UIGroup;
43
78
  _onEnableInScene(): void;
44
79
  _onDisableInScene(): void;
80
+ /**
81
+ * @internal
82
+ */
83
+ _groupListener(flag: number): void;
84
+ /**
85
+ * @internal
86
+ */
87
+ _rootCanvasListener(flag: number): void;
88
+ /**
89
+ * @internal
90
+ */
91
+ _onGroupModify(flags: GroupModifyFlags): void;
92
+ /**
93
+ * @internal
94
+ */
95
+ _getGlobalInteractive(): boolean;
45
96
  private _updateState;
46
97
  private _getInteractiveState;
47
98
  }
@@ -1,11 +1,13 @@
1
1
  import { Color, DataObject, Sprite } from "@galacean/engine";
2
2
  import type { ICloneHook } from "@galacean/engine";
3
3
  import { UIRenderer } from "../../UIRenderer";
4
- import { InteractiveState } from "../UIInteractive";
4
+ import { InteractiveState, UIInteractive } from "../UIInteractive";
5
5
  /**
6
6
  * The transition behavior of UIInteractive.
7
7
  */
8
8
  export declare abstract class Transition<T extends TransitionValueType = TransitionValueType, K extends UIRenderer = UIRenderer> extends DataObject implements ICloneHook<Transition<T, K>> {
9
+ /** @internal */
10
+ _interactive: UIInteractive;
9
11
  protected _target: K;
10
12
  protected _normal: T;
11
13
  protected _pressed: T;
@@ -52,6 +54,14 @@ export declare abstract class Transition<T extends TransitionValueType = Transit
52
54
  * @inheritdoc
53
55
  */
54
56
  _onClone(target: Transition<T, K>): void;
57
+ /**
58
+ * @internal
59
+ */
60
+ _setState(state: InteractiveState, instant: boolean): void;
61
+ /**
62
+ * @internal
63
+ */
64
+ _onUpdate(delta: number): void;
55
65
  protected abstract _getTargetValueCopy(): T;
56
66
  protected abstract _updateCurrentValue(srcValue: T, destValue: T, weight: number): void;
57
67
  protected abstract _applyValue(value: T): void;
package/types/index.d.ts CHANGED
@@ -15,8 +15,12 @@ export declare class EntityExtension {
15
15
  }
16
16
  declare module "@galacean/engine" {
17
17
  interface Engine {
18
+ _uiDefaultMaterial: Material;
19
+ _getUIDefaultMaterial(): Material;
18
20
  }
19
21
  interface Entity {
22
+ _uiHierarchyVersion: number;
23
+ _updateUIHierarchyVersion(version: number): void;
20
24
  }
21
25
  }
22
26
  /**
@@ -1 +1,12 @@
1
- export {};
1
+ import { Entity, Vector3 } from "@galacean/engine";
2
+ import { UIRenderer } from "../component/UIRenderer";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class UIHitResult {
7
+ entity: Entity;
8
+ distance: number;
9
+ point: Vector3;
10
+ normal: Vector3;
11
+ component: UIRenderer;
12
+ }
@@ -1 +1,26 @@
1
- export {};
1
+ import { Pointer, PointerEventEmitter, Scene } from "@galacean/engine";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class UIPointerEventEmitter extends PointerEventEmitter {
6
+ private static _MAX_PATH_DEPTH;
7
+ private static _tempSet;
8
+ private static _path;
9
+ private static _tempArray0;
10
+ private static _tempArray1;
11
+ private _enteredPath;
12
+ private _pressedPath;
13
+ private _draggedPath;
14
+ _init(): void;
15
+ processRaycast(scenes: readonly Scene[], pointer: Pointer): void;
16
+ processDrag(pointer: Pointer): void;
17
+ processDown(pointer: Pointer): void;
18
+ processUp(pointer: Pointer): void;
19
+ processLeave(pointer: Pointer): void;
20
+ dispose(): void;
21
+ private _updateRaycast;
22
+ private _composedPath;
23
+ private _findCommonInPath;
24
+ private _findDiffInPath;
25
+ private _bubble;
26
+ }