laymur 0.3.30 → 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.
@@ -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. */
@@ -163,6 +165,7 @@ export declare abstract class UIElement extends UIAnchor implements UIPlaneEleme
163
165
  protected readonly onDown: (x: number, y: number) => boolean;
164
166
  protected readonly onMove: (x: number, y: number) => boolean;
165
167
  protected readonly onUp: (x: number, y: number) => boolean;
168
+ protected handleInputEvent(x: number, y: number, inputEvent: UIInputEvent): boolean;
166
169
  /**
167
170
  * Called before each render frame to update the element's transform matrix.
168
171
  * Applies micro-transformations (position, rotation, scale, anchor) and updates
package/dist/index.js CHANGED
@@ -4385,6 +4385,8 @@ var UIInputEvent;
4385
4385
  UIInputEvent["DOWN"] = "click";
4386
4386
  UIInputEvent["MOVE"] = "move";
4387
4387
  UIInputEvent["UP"] = "up";
4388
+ UIInputEvent["IN"] = "in";
4389
+ UIInputEvent["OUT"] = "out";
4388
4390
  })(UIInputEvent || (UIInputEvent = {}));
4389
4391
 
4390
4392
  /**
@@ -4757,26 +4759,15 @@ class UIElement extends UIAnchor {
4757
4759
  this.transparencyInternal = UITransparencyMode.BLEND;
4758
4760
  /** Internal storage for the z-index (depth) value. */
4759
4761
  this.zIndexInternal = 0;
4762
+ this.isPointerInside = false;
4760
4763
  this.onDown = (x, y) => {
4761
- const clicked = isInsideElement(x, y, this);
4762
- if (clicked) {
4763
- this.emit(UIInputEvent.DOWN, x, y, this);
4764
- }
4765
- return clicked;
4764
+ return this.handleInputEvent(x, y, UIInputEvent.DOWN);
4766
4765
  };
4767
4766
  this.onMove = (x, y) => {
4768
- const clicked = isInsideElement(x, y, this);
4769
- if (clicked) {
4770
- this.emit(UIInputEvent.MOVE, x, y, this);
4771
- }
4772
- return clicked;
4767
+ return this.handleInputEvent(x, y, UIInputEvent.MOVE);
4773
4768
  };
4774
4769
  this.onUp = (x, y) => {
4775
- const clicked = isInsideElement(x, y, this);
4776
- if (clicked) {
4777
- this.emit(UIInputEvent.UP, x, y, this);
4778
- }
4779
- return clicked;
4770
+ return this.handleInputEvent(x, y, UIInputEvent.UP);
4780
4771
  };
4781
4772
  this.layer.on(UILayerEvent.WILL_RENDER, this.onWillRender, this);
4782
4773
  this.wVariable = this.solverWrapper.createVariable(width, UIPriority.P6);
@@ -4953,6 +4944,20 @@ class UIElement extends UIAnchor {
4953
4944
  this.sceneWrapper.destroyPlane(this.planeHandler);
4954
4945
  super.destroy();
4955
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
+ }
4956
4961
  /**
4957
4962
  * Called before each render frame to update the element's transform matrix.
4958
4963
  * Applies micro-transformations (position, rotation, scale, anchor) and updates