浏览代码

fix filter issues

David Catuhe 6 年之前
父节点
当前提交
a189503b72

+ 10 - 0
gui/src/2D/advancedDynamicTexture.ts

@@ -217,6 +217,16 @@ export class AdvancedDynamicTexture extends DynamicTexture {
     }
 
     /**
+     * Will return all controls that are inside this texture
+     * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
+     * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
+     * @return all child controls
+     */
+    public getDescendants(directDescendantsOnly?: boolean, predicate?: (control: Control) => boolean): Control[] {
+        return this._rootContainer.getDescendants(directDescendantsOnly, predicate);
+    }
+
+    /**
      * Gets or sets the current focused control
      */
     public get focusedControl(): Nullable<IFocusableControl> {

+ 19 - 0
gui/src/2D/controls/container.ts

@@ -314,6 +314,25 @@ export class Container extends Control {
     }
 
     /** @hidden */
+    public _getDescendants(results: Control[], directDescendantsOnly: boolean = false, predicate?: (control: Control) => boolean): void {
+        if (!this.children) {
+            return;
+        }
+
+        for (var index = 0; index < this.children.length; index++) {
+            var item = this.children[index];
+
+            if (!predicate || predicate(item)) {
+                results.push(item);
+            }
+
+            if (!directDescendantsOnly) {
+                item._getDescendants(results, false, predicate);
+            }
+        }
+    }
+
+    /** @hidden */
     public _processPicking(x: number, y: number, type: number, pointerId: number, buttonIndex: number): boolean {
         if (!this.isVisible || this.notRenderable) {
             return false;

+ 19 - 0
gui/src/2D/controls/control.ts

@@ -882,6 +882,25 @@ export class Control {
         this.notRenderable = false;
     }
 
+    /** @hidden */
+    public _getDescendants(results: Control[], directDescendantsOnly: boolean = false, predicate?: (control: Control) => boolean): void {
+        // Do nothing by default
+    }
+
+    /**
+     * Will return all controls that have this control as ascendant
+     * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
+     * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
+     * @return all child controls
+     */
+    public getDescendants(directDescendantsOnly?: boolean, predicate?: (control: Control) => boolean): Control[] {
+        var results = new Array<Control>();
+
+        this._getDescendants(results, directDescendantsOnly, predicate);
+
+        return results;
+    }
+
     /**
      * Link current control with a target mesh
      * @param mesh defines the mesh to link with

+ 9 - 0
inspector/src/components/sceneExplorer/entities/gui/advancedDynamicTextureTreeItemComponent.tsx

@@ -22,6 +22,15 @@ export class AdvancedDynamicTextureTreeItemComponent extends React.Component<IAd
         this.state = { isInPickingMode: false };
     }
 
+    componentWillUnmount() {
+        let adt = this.props.texture;
+
+        if (this._onControlPickedObserver) {
+            adt.onControlPickedObservable.remove(this._onControlPickedObserver);
+            this._onControlPickedObserver = null;
+        }
+    }
+
     onPickingMode() {
         let adt = this.props.texture;
 

+ 6 - 5
inspector/src/components/sceneExplorer/treeItemSelectableComponent.tsx

@@ -1,5 +1,5 @@
 import { TreeItemSpecializedComponent } from "./treeItemSpecializedComponent";
-import { Observable, Nullable, Node, IExplorerExtensibilityGroup } from "babylonjs";
+import { Observable, Nullable, IExplorerExtensibilityGroup } from "babylonjs";
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
 import { faMinus, faPlus } from "@fortawesome/free-solid-svg-icons";
 import { Tools } from "../../tools";
@@ -117,15 +117,16 @@ export class TreeItemSelectableComponent extends React.Component<ITreeItemSelect
         entity.metadata.isExpanded = this.state.isExpanded;
 
         if (this.props.filter) {
-
-            if (entity.name.indexOf(this.props.filter) === -1) {
+            const lowerCaseFilter = this.props.filter.toLowerCase();
+            if (!entity.name || entity.name.toLowerCase().indexOf(lowerCaseFilter) === -1) {
                 if (!hasChildren) {
                     return null;
                 }
 
                 if (entity.getDescendants) {
-                    if (entity.getDescendants(false, (n: Node) => {
-                        !this.props.filter || n.name.indexOf(this.props.filter) !== -1
+                    if (entity.getDescendants(false, (n: any) => {
+                        console.log(n.name);
+                        return n.name && n.name.toLowerCase().indexOf(lowerCaseFilter) !== -1
                     }).length === 0) {
                         return null;
                     }