Bläddra i källkod

Improve vKeyboard support

David Catuhe 7 år sedan
förälder
incheckning
12e7d75b89

+ 25 - 5
gui/src/2D/advancedDynamicTexture.ts

@@ -23,11 +23,10 @@ export interface IFocusableControl {
     processKeyboard(evt: KeyboardEvent): void;
     processKeyboard(evt: KeyboardEvent): void;
 
 
     /**
     /**
-     * Function called to let the current focused control keeps the focus
-     * @param pointerId defines the unique id of the current pointer
-     * @returns a boolean indicating if the control wants to keep the focus
+     * Function called to get the list of controls that should not steal the focus from this control
+     * @returns an array of controls
      */
      */
-    wantTokeepFocus(pointerId: number): boolean;
+    keepsFocusWith(): Nullable<Control[]>;
 }
 }
 
 
 /**
 /**
@@ -666,7 +665,28 @@ export class AdvancedDynamicTexture extends DynamicTexture {
                 delete this._lastControlDown[pointerId];
                 delete this._lastControlDown[pointerId];
 
 
                 if (this.focusedControl) {
                 if (this.focusedControl) {
-                    if (!this.focusedControl.wantTokeepFocus(pointerId)) {
+                    const friendlyControls = this.focusedControl.keepsFocusWith();
+                    
+                    let canMoveFocus = true;
+
+                    if (friendlyControls) {
+                        for (var control of friendlyControls) {
+                            // Same host, no need to keep the focus
+                            if (this === control._host) {
+                                continue;
+                            }
+
+                            // Different hosts
+                            const otherHost = control._host;
+
+                            if (otherHost._lastControlOver[pointerId] && otherHost._lastControlOver[pointerId].isAscendant(control)) {
+                                canMoveFocus = false;
+                                break;
+                            }
+                        }
+                    }
+
+                    if (canMoveFocus) {
                         this.focusedControl = null;
                         this.focusedControl = null;
                     }
                     }
                 }
                 }

+ 1 - 1
gui/src/2D/controls/control.ts

@@ -750,7 +750,7 @@ export class Control {
      * @param container defines the container to look for
      * @param container defines the container to look for
      * @returns true if the container is one of the ascendant of the control
      * @returns true if the container is one of the ascendant of the control
      */
      */
-    public isAscendant(container: Container): boolean {
+    public isAscendant(container: Control): boolean {
         if (!this.parent) {
         if (!this.parent) {
             return false;
             return false;
         }
         }

+ 5 - 19
gui/src/2D/controls/inputText.ts

@@ -277,28 +277,14 @@ export class InputText extends Control implements IFocusableControl {
     }
     }
 
 
     /**
     /**
-     * Function called to let the current focused control keeps the focus
-     * @param pointerId defines the unique id of the current pointer generating the focus change
-     * @returns a boolean indicating if the control wants to keep the focus
+     * Function called to get the list of controls that should not steal the focus from this control
+     * @returns an array of controls
      */
      */
-    public wantTokeepFocus(pointerId: number): boolean {
+    public keepsFocusWith(): Nullable<Control[]> {
         if (!this._connectedVirtualKeyboard) {
         if (!this._connectedVirtualKeyboard) {
-            return false;
+            return null;
         }
         }
-
-        // Same host, no need to keep the focus
-        if (this._host === this._connectedVirtualKeyboard._host) {
-            return false;
-        }
-
-        // Different hosts
-        const otherHost = this._connectedVirtualKeyboard._host;
-
-        if (otherHost._lastControlOver[pointerId] && otherHost._lastControlOver[pointerId].isAscendant(this._connectedVirtualKeyboard)) {
-            return true;
-        }
-
-        return false;
+        return [this._connectedVirtualKeyboard];
     }
     }
 
 
     /** @hidden */
     /** @hidden */