# misc/devtools (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/misc/devtools/

Fixed layout constants.

## DevTools extends Object

Hierarchy panel.
- The F2 key toggles show and hide.
- Shows the scene node hierarchy as a left tree and a right inspector.
- Drag the title bar to move the panel.
- Drag any edge or corner to resize.
- Drag the center splitter to change the left and right ratio.
- Click a component header to expand or collapse its property list. (default: expanded)

Example: Open the panel and choose a tab

```js
import { DevTools } from "./build/vanilla.js";

const devTools = new DevTools();
devTools.setActiveTab(1);
devTools.setVisible(true);
console.log(devTools.isVisible(), devTools.getActiveTab());
console.log(devTools.getPanelRect().width > 0, devTools.isFramePerSecondVisible());
```

- `constructor()` (constructor, since 0.4.0): Constructor.
- `setEngine(engine)` (method, since 0.4.0): Engine configuration.
  - `engine` Engine: The engine the dev tools look into. (the dev tools own gizmo display, so the forced gizmos are turned off)
- `setRootNodes(rootNodes)` (method, since 0.4.0): Sets the root node list.
  - `rootNodes` TransformNode[]: The list of root nodes shown in the tree. (roots start expanded)
- `isVisible()` (method, since 0.4.0): Returns whether it is visible.
  - returns boolean: True if the panel is visible.
- `setVisible(isVisible)` (method, since 0.4.0): Shows and hides. (same as F2. When shown, the panel is attached to the bottom right of the window and every gizmo setting is turned on)
  - `isVisible` boolean: True to show the panel, false to hide it.
- `getActiveTab()` (method, since 0.4.0): Returns the current tab. (0 Statistics, 1 Node Hierarchy, 2 Local Storage, 3 Settings)
  - returns number: The current tab number. (0 Statistics, 1 Node Hierarchy, 2 Local Storage, 3 Settings)
- `setActiveTab(tabIndex)` (method, since 0.4.0): Sets the tab. (ignored if there is no such tab)
  - `tabIndex` number: The tab number. (0 Statistics, 1 Node Hierarchy, 2 Local Storage, 3 Settings)
- `getSelectedNode()` (method, since 0.4.0): Returns the selected node.
  - returns TransformNode | null: The selected node. (null if none)
- `setSelectedNode(node)` (method, since 0.4.0): Selects a node. (the inspector scroll goes back to the top)
  - `node` TransformNode | null: The node to select. (null clears the selection)
- `isNodeExpanded(node)` (method, since 0.4.0): Whether the node is expanded in the tree.
  - `node` TransformNode: The node to check.
  - returns boolean: True if that node is expanded in the tree.
- `setNodeExpanded(node, isExpanded)` (method, since 0.4.0): Expands and collapses a node in the tree.
  - `node` TransformNode: The node to expand or collapse.
  - `isExpanded` boolean: True to expand, false to collapse.
- `inspectNode(node)` (method, since 0.4.0): Inspects a node. (shows the panel, switches to the Node Hierarchy tab, expands the ancestors and selects the node, does not expand the node itself)
  - `node` TransformNode: Node to inspect.

  Example: Inspecting a child node expands its parent

  ```js
  import { DevTools, WorldNode } from "./build/vanilla.js";
  
  const parentNode = new WorldNode();
  const childNode = new WorldNode();
  parentNode.addChild(childNode);
  const devTools = new DevTools();
  devTools.inspectNode(childNode);
  console.log(devTools.isVisible(), devTools.getActiveTab(), devTools.isNodeExpanded(parentNode), devTools.getSelectedNode() === childNode);
  ```

- `getPanelRect()` (method, since 0.4.0): Returns the panel area. (logical coordinates inside the window)
  - returns Rect: The panel area. (logical coordinates inside the window)
- `isPointerInsidePanel()` (method, since 0.4.0): Returns whether the current touch position is inside the panel.
  - returns boolean: True if the pointer is inside the panel right now. (false while the panel is hidden)
- `tick(timeDelta)` (method, since 0.4.0): Update.
  - `timeDelta` number: Interval since the last frame. (seconds)
- `draw(graphic)` (method, since 0.4.0): Draw.
  - `graphic` Graphic: Graphic to draw with.
- `isFramePerSecondVisible()` (method, since 0.4.0): Returns whether the FPS display is on.
  - returns boolean: True if Show FPS in Settings is on. (when on, draw shows the FPS at the top left of the window even with the panel closed)
