浏览代码

Update inspector to start at a named tab

Gary Hsu 7 年之前
父节点
当前提交
206b016ff9
共有 3 个文件被更改,包括 21 次插入8 次删除
  1. 2 2
      inspector/src/Inspector.ts
  2. 17 4
      inspector/src/tabs/TabBar.ts
  3. 2 2
      src/Debug/babylon.debugLayer.ts

+ 2 - 2
inspector/src/Inspector.ts

@@ -28,7 +28,7 @@ export class Inspector {
     /** The original canvas style, before applying the inspector*/
     private _canvasStyle: any;
 
-    private _initialTab: number;
+    private _initialTab: number | string;
 
     private _parentElement: Nullable<HTMLElement>;
 
@@ -40,7 +40,7 @@ export class Inspector {
      * If the parameter 'popup' is false, the inspector is created as a right panel on the main window.
      * If the parameter 'popup' is true, the inspector is created in another popup.
      */
-    constructor(scene: Scene, popup?: boolean, initialTab: number = 0, parentElement: Nullable<HTMLElement> = null, newColors?: {
+    constructor(scene: Scene, popup?: boolean, initialTab: number | string = 0, parentElement: Nullable<HTMLElement> = null, newColors?: {
         backgroundColor?: string,
         backgroundColorLighter?: string,
         backgroundColorLighter2?: string,

+ 17 - 4
inspector/src/tabs/TabBar.ts

@@ -41,7 +41,7 @@ export class TabBar extends BasicElement {
     /** The list of tabs visible, displayed in the tab bar */
     private _visibleTabs: Array<Tab> = [];
 
-    constructor(inspector: Inspector, initialTab?: number) {
+    constructor(inspector: Inspector, initialTab?: number | string) {
         super();
         this._inspector = inspector;
         this._tabs.push(new SceneTab(this, this._inspector));
@@ -66,9 +66,13 @@ export class TabBar extends BasicElement {
 
         this._build();
 
-        //Check initialTab is defined and between tabs bounds
-        if (!initialTab || initialTab < 0 || initialTab >= this._tabs.length) {
-            initialTab = 0;
+        if (typeof initialTab === "string") {
+            initialTab = this.getTabIndex(initialTab);
+        } else {
+            //Check initialTab is defined and between tabs bounds
+            if (!initialTab || initialTab < 0 || initialTab >= this._tabs.length) {
+                initialTab = 0;
+            }
         }
 
         this._tabs[initialTab].active(true);
@@ -183,6 +187,15 @@ export class TabBar extends BasicElement {
         return 0;
     }
 
+    public getTabIndex(name: string): number {
+        for (let i = 0; i < this._tabs.length; i++) {
+            if (this._tabs[i].name === name) {
+                return i;
+            }
+        }
+        return 0;
+    }
+
     public get inspector(): Inspector {
         return this._inspector;
     }

+ 2 - 2
src/Debug/babylon.debugLayer.ts

@@ -52,7 +52,7 @@ module BABYLON {
         /** Creates the inspector window. */
         private _createInspector(config: {
             popup?: boolean,
-            initialTab?: number,
+            initialTab?: number | string,
             parentElement?: HTMLElement,
             newColors?: {
                 backgroundColor?: string,
@@ -117,7 +117,7 @@ module BABYLON {
 
         public show(config: {
             popup?: boolean,
-            initialTab?: number,
+            initialTab?: number | string,
             parentElement?: HTMLElement,
             newColors?: {
                 backgroundColor?: string,