浏览代码

Button.delegatePickingToChildren

David Catuhe 6 年之前
父节点
当前提交
5492ac3a60
共有 2 个文件被更改,包括 27 次插入5 次删除
  1. 5 2
      dist/preview release/what's new.md
  2. 22 3
      gui/src/2D/controls/button.ts

+ 5 - 2
dist/preview release/what's new.md

@@ -8,6 +8,9 @@
 - WIP: Recast navigation mesh and crowd of moving agents [Demo](https://www.babylonjs-playground.com/#AJTRIL) ([CedricGuillemet](https://github.com/CedricGuillemet))
 - Classes decoupling ending up with smaller bundle sizes [Blog](https://medium.com/@babylonjs/size-matters-e0e94dad01a7) ([Deltakosh](https://github.com/deltakosh/))
 - Babylon.js controls [Doc](https://doc.babylonjs.com/features/controls) ([Sebavan](https://github.com/sebavan/) / [Deltakosh](https://github.com/deltakosh/))
+- WebXR updates:
+  - WebXR updated to spec as of July 10th ([TrevorDev](https://github.com/TrevorDev))
+  - WebXR webVR parity helpers (Vive, WMR, Oculus Rift) ([TrevorDev](https://github.com/TrevorDev))
 
 ## Updates
 
@@ -25,8 +28,7 @@
 - Added startAndReleaseDragOnPointerEvents property to pointerDragBehavior which can be set to false for custom drag triggering ([TrevorDev](https://github.com/TrevorDev))
 - Effect renderer to render one or multiple shader effects to a texture ([TrevorDev](https://github.com/TrevorDev))
 - Added url parameters to web request modifiers ([PierreLeBlond](https://github.com/PierreLeBlond))
-- WebXR updated to spec as of July 10th ([TrevorDev](https://github.com/TrevorDev))
-- WebXR webVR parity helpers (Vive, WMR, Oculus Rift) ([TrevorDev](https://github.com/TrevorDev))
+- Added `VRExperienceHelper.exitVROnDoubleTap` ([Deltakosh](https://github.com/deltakosh/))
 
 ### Engine
 - Morph targets now can morph UV channel as well ([Deltakosh](https://github.com/deltakosh/))
@@ -79,6 +81,7 @@
 
 ### GUI
 - Added `disableMobilePrompt` option to InputText for OculusQuest(and other android base VR devices) ([shinyoshiaki](https://github.com/shinyoshiaki))
+- Added `Button.delegatePickingToChildren` to let buttons delegate hit testing to embedded controls ([Deltakosh](https://github.com/deltakosh/))
 
 ### Documentation
 - Added a note on shallow bounding of getBoundingInfo ([tibotiber](https://github.com/tibotiber))

+ 22 - 3
gui/src/2D/controls/button.ts

@@ -27,6 +27,11 @@ export class Button extends Rectangle {
      */
     public pointerUpAnimation: () => void;
 
+    /**
+     * Gets or sets a boolean indicating that the button will let internal controls handle picking instead of doing it directly using its bounding info
+     */
+    public delegatePickingToChildren = false;
+
     private _image: Nullable<Image>;
     /**
      * Returns the image part of the button (if any)
@@ -83,7 +88,7 @@ export class Button extends Rectangle {
 
     // While being a container, the button behaves like a control.
     /** @hidden */
-    public _processPicking(x: number, y: number, type: number, pointerId: number, buttonIndex: number): boolean {
+    public _processPicking(x: number, y: number, type: number, pointerId: number, buttonIndex: number): boolean {     
         if (!this._isEnabled || !this.isHitTestVisible || !this.isVisible || this.notRenderable) {
             return false;
         }
@@ -91,8 +96,22 @@ export class Button extends Rectangle {
         if (!super.contains(x, y)) {
             return false;
         }
-
-        this._processObservables(type, x, y, pointerId, buttonIndex);
+        
+        let processObservables = true;
+        if (this.delegatePickingToChildren) {
+            processObservables = false;
+            for (var index = this._children.length - 1; index >= 0; index--) {
+                var child = this._children[index];
+                if (child.isEnabled && child.isHitTestVisible && child.isVisible && !child.notRenderable && child.contains(x, y)) {
+                    processObservables = true;
+                    break;
+                }
+            }
+        }
+        
+        if (processObservables) {
+            this._processObservables(type, x, y, pointerId, buttonIndex);
+        }
 
         return true;
     }