laymur 0.3.29 → 0.3.31
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/elements/UIElement.d.ts +6 -7
- package/dist/index.js +84 -39
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UIFullscreenLayer.d.ts +3 -7
- package/dist/layers/UILayer.d.ts +6 -19
- package/dist/miscellaneous/UIInputEvent.d.ts +5 -2
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import type { WebGLRenderer } from "three";
|
|
|
2
2
|
import type { UILayerInputListener } from "../layers/UILayer";
|
|
3
3
|
import { type UILayer } from "../layers/UILayer";
|
|
4
4
|
import type { UILayerElement, UIPlaneElement } from "../miscellaneous/asserts";
|
|
5
|
+
import { UIInputEvent } from "../miscellaneous/UIInputEvent";
|
|
5
6
|
import { UIMicro } from "../miscellaneous/UIMicro";
|
|
6
7
|
import { UIMode } from "../miscellaneous/UIMode";
|
|
7
8
|
import type { UISceneWrapperClientAPI } from "../miscellaneous/UISceneWrapperClientAPI";
|
|
@@ -41,6 +42,7 @@ export declare abstract class UIElement extends UIAnchor implements UIPlaneEleme
|
|
|
41
42
|
protected zIndexInternal: number;
|
|
42
43
|
/** Optional input listener for handling user interactions when in interactive mode. */
|
|
43
44
|
protected listener?: UILayerInputListener;
|
|
45
|
+
protected isPointerInside: boolean;
|
|
44
46
|
/** Client API for interacting with the scene wrapper (rendering system). */
|
|
45
47
|
protected readonly sceneWrapper: UISceneWrapperClientAPI;
|
|
46
48
|
/** Handle to the plane object in the rendering system. */
|
|
@@ -160,13 +162,10 @@ export declare abstract class UIElement extends UIAnchor implements UIPlaneEleme
|
|
|
160
162
|
* the element should not be used anymore.
|
|
161
163
|
*/
|
|
162
164
|
destroy(): void;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* @returns True if the click was within this element's bounds
|
|
168
|
-
*/
|
|
169
|
-
protected readonly onClick: (x: number, y: number) => boolean;
|
|
165
|
+
protected readonly onDown: (x: number, y: number) => boolean;
|
|
166
|
+
protected readonly onMove: (x: number, y: number) => boolean;
|
|
167
|
+
protected readonly onUp: (x: number, y: number) => boolean;
|
|
168
|
+
protected handleInputEvent(x: number, y: number, inputEvent: UIInputEvent): boolean;
|
|
170
169
|
/**
|
|
171
170
|
* Called before each render frame to update the element's transform matrix.
|
|
172
171
|
* Applies micro-transformations (position, rotation, scale, anchor) and updates
|
package/dist/index.js
CHANGED
|
@@ -3062,22 +3062,31 @@ class UILayer extends i {
|
|
|
3062
3062
|
this.sceneWrapper.render(renderer);
|
|
3063
3063
|
}
|
|
3064
3064
|
}
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
pointerClickInternal(x, y) {
|
|
3065
|
+
pointerDownInternal(x, y) {
|
|
3066
|
+
if (this.mode === UIMode.INTERACTIVE) {
|
|
3067
|
+
this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
|
|
3068
|
+
for (const listener of this._private_inputListeners) {
|
|
3069
|
+
if (listener.listener.catchDown(x, y)) {
|
|
3070
|
+
return;
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
pointerMoveInternal(x, y) {
|
|
3077
3076
|
if (this.mode === UIMode.INTERACTIVE) {
|
|
3078
3077
|
this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
|
|
3079
3078
|
for (const listener of this._private_inputListeners) {
|
|
3080
|
-
if (listener.listener.
|
|
3079
|
+
if (listener.listener.catchMove(x, y)) {
|
|
3080
|
+
return;
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
pointerUpInternal(x, y) {
|
|
3086
|
+
if (this.mode === UIMode.INTERACTIVE) {
|
|
3087
|
+
this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
|
|
3088
|
+
for (const listener of this._private_inputListeners) {
|
|
3089
|
+
if (listener.listener.catchUp(x, y)) {
|
|
3081
3090
|
return;
|
|
3082
3091
|
}
|
|
3083
3092
|
}
|
|
@@ -4373,8 +4382,11 @@ var source$2 = "void main() {\n vec2 transformedUV = (uvTransform * vec3(io_U
|
|
|
4373
4382
|
*/
|
|
4374
4383
|
var UIInputEvent;
|
|
4375
4384
|
(function (UIInputEvent) {
|
|
4376
|
-
|
|
4377
|
-
UIInputEvent["
|
|
4385
|
+
UIInputEvent["DOWN"] = "click";
|
|
4386
|
+
UIInputEvent["MOVE"] = "move";
|
|
4387
|
+
UIInputEvent["UP"] = "up";
|
|
4388
|
+
UIInputEvent["IN"] = "in";
|
|
4389
|
+
UIInputEvent["OUT"] = "out";
|
|
4378
4390
|
})(UIInputEvent || (UIInputEvent = {}));
|
|
4379
4391
|
|
|
4380
4392
|
/**
|
|
@@ -4702,7 +4714,7 @@ const axis = new Vector3(0, 0, 1);
|
|
|
4702
4714
|
* @param element - The UI element to test against
|
|
4703
4715
|
* @returns True if the point is within the element's bounds
|
|
4704
4716
|
*/
|
|
4705
|
-
function
|
|
4717
|
+
function isInsideElement(x, y, element) {
|
|
4706
4718
|
return (x > element.x &&
|
|
4707
4719
|
x < element.x + element.width &&
|
|
4708
4720
|
y > element.y &&
|
|
@@ -4747,18 +4759,15 @@ class UIElement extends UIAnchor {
|
|
|
4747
4759
|
this.transparencyInternal = UITransparencyMode.BLEND;
|
|
4748
4760
|
/** Internal storage for the z-index (depth) value. */
|
|
4749
4761
|
this.zIndexInternal = 0;
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
this.emit(UIInputEvent.CLICK, x, y, this);
|
|
4760
|
-
}
|
|
4761
|
-
return clicked;
|
|
4762
|
+
this.isPointerInside = false;
|
|
4763
|
+
this.onDown = (x, y) => {
|
|
4764
|
+
return this.handleInputEvent(x, y, UIInputEvent.DOWN);
|
|
4765
|
+
};
|
|
4766
|
+
this.onMove = (x, y) => {
|
|
4767
|
+
return this.handleInputEvent(x, y, UIInputEvent.MOVE);
|
|
4768
|
+
};
|
|
4769
|
+
this.onUp = (x, y) => {
|
|
4770
|
+
return this.handleInputEvent(x, y, UIInputEvent.UP);
|
|
4762
4771
|
};
|
|
4763
4772
|
this.layer.on(UILayerEvent.WILL_RENDER, this.onWillRender, this);
|
|
4764
4773
|
this.wVariable = this.solverWrapper.createVariable(width, UIPriority.P6);
|
|
@@ -4893,7 +4902,11 @@ class UIElement extends UIAnchor {
|
|
|
4893
4902
|
set mode(value) {
|
|
4894
4903
|
if (this.modeInternal !== value) {
|
|
4895
4904
|
if (value === UIMode.INTERACTIVE) {
|
|
4896
|
-
this.listener = {
|
|
4905
|
+
this.listener = {
|
|
4906
|
+
catchDown: this.onDown,
|
|
4907
|
+
catchMove: this.onMove,
|
|
4908
|
+
catchUp: this.onUp,
|
|
4909
|
+
};
|
|
4897
4910
|
this.layer["listenPointerInput"](this.listener, this.zIndexInternal);
|
|
4898
4911
|
}
|
|
4899
4912
|
else if (this.modeInternal === UIMode.INTERACTIVE && this.listener) {
|
|
@@ -4931,6 +4944,20 @@ class UIElement extends UIAnchor {
|
|
|
4931
4944
|
this.sceneWrapper.destroyPlane(this.planeHandler);
|
|
4932
4945
|
super.destroy();
|
|
4933
4946
|
}
|
|
4947
|
+
handleInputEvent(x, y, inputEvent) {
|
|
4948
|
+
const inside = isInsideElement(x, y, this);
|
|
4949
|
+
if (inside) {
|
|
4950
|
+
this.emit(inputEvent, x, y, this);
|
|
4951
|
+
}
|
|
4952
|
+
if (this.isPointerInside && !inside) {
|
|
4953
|
+
this.emit(UIInputEvent.OUT, x, y, this);
|
|
4954
|
+
}
|
|
4955
|
+
else if (!this.isPointerInside && inside) {
|
|
4956
|
+
this.emit(UIInputEvent.IN, x, y, this);
|
|
4957
|
+
}
|
|
4958
|
+
this.isPointerInside = inside;
|
|
4959
|
+
return inside;
|
|
4960
|
+
}
|
|
4934
4961
|
/**
|
|
4935
4962
|
* Called before each render frame to update the element's transform matrix.
|
|
4936
4963
|
* Applies micro-transformations (position, rotation, scale, anchor) and updates
|
|
@@ -6736,13 +6763,29 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6736
6763
|
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6737
6764
|
this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
|
|
6738
6765
|
};
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6766
|
+
this._private_onDown = (event) => {
|
|
6767
|
+
const rect = event.target instanceof HTMLElement
|
|
6768
|
+
? event.target.getBoundingClientRect()
|
|
6769
|
+
: null;
|
|
6770
|
+
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6771
|
+
const y = rect
|
|
6772
|
+
? rect.bottom - event.clientY
|
|
6773
|
+
: window.innerHeight - event.clientY;
|
|
6774
|
+
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6775
|
+
this.pointerDownInternal(x * scale, y * scale);
|
|
6776
|
+
};
|
|
6777
|
+
this._private_onMove = (event) => {
|
|
6778
|
+
const rect = event.target instanceof HTMLElement
|
|
6779
|
+
? event.target.getBoundingClientRect()
|
|
6780
|
+
: null;
|
|
6781
|
+
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6782
|
+
const y = rect
|
|
6783
|
+
? rect.bottom - event.clientY
|
|
6784
|
+
: window.innerHeight - event.clientY;
|
|
6785
|
+
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6786
|
+
this.pointerMoveInternal(x * scale, y * scale);
|
|
6787
|
+
};
|
|
6788
|
+
this._private_onUp = (event) => {
|
|
6746
6789
|
const rect = event.target instanceof HTMLElement
|
|
6747
6790
|
? event.target.getBoundingClientRect()
|
|
6748
6791
|
: null;
|
|
@@ -6751,10 +6794,12 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6751
6794
|
? rect.bottom - event.clientY
|
|
6752
6795
|
: window.innerHeight - event.clientY;
|
|
6753
6796
|
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6754
|
-
this.
|
|
6797
|
+
this.pointerUpInternal(x * scale, y * scale);
|
|
6755
6798
|
};
|
|
6756
6799
|
window.addEventListener("resize", this._private_onResize);
|
|
6757
|
-
window.addEventListener("pointerdown", this.
|
|
6800
|
+
window.addEventListener("pointerdown", this._private_onDown);
|
|
6801
|
+
window.addEventListener("pointermove", this._private_onMove);
|
|
6802
|
+
window.addEventListener("pointerup", this._private_onUp);
|
|
6758
6803
|
this.mode = mode;
|
|
6759
6804
|
this._private_resizePolicyInternal = resizePolicy;
|
|
6760
6805
|
this._private_resizePolicyInternal.on(UIResizePolicyEvent.CHANGE, this._private_onResize);
|
|
@@ -6782,7 +6827,7 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6782
6827
|
*/
|
|
6783
6828
|
destroy() {
|
|
6784
6829
|
window.removeEventListener("resize", this._private_onResize);
|
|
6785
|
-
window.removeEventListener("pointerdown", this.
|
|
6830
|
+
window.removeEventListener("pointerdown", this._private_onDown);
|
|
6786
6831
|
this._private_resizePolicyInternal.off(UIResizePolicyEvent.CHANGE, this._private_onResize);
|
|
6787
6832
|
}
|
|
6788
6833
|
/**
|