Skip to content

ToggleNode

Overview

Display one of N nodes based on a given Property. See the option "unselectedChildrenSceneGraphStrategy" for different child management strategies and how they impact the overall bounds and performance. Supports null and undefined as possible values. Will not work correctly if the children are changed externally after instantiation (manages its own children and their visibility).

@author Sam Reid (PhET Interactive Simulations)

Class ToggleNode

import { ToggleNode } from 'scenerystack/sun';

Constructor

new ToggleNode( valueProperty : TReadOnlyProperty<T>, elements : ToggleNodeElement<T, N>[], providedOptions? : ToggleNodeOptions )

Instance Methods

dispose()

Instance Properties

nodes : N[]

(readonly)

Static Methods

CENTER( children : Layoutable[] )

A value for the alignChildren option. Centers the latter nodes on the x,y center of the first node.

CENTER_X( children : Layoutable[] )

A value for the alignChildren option. Centers the latter nodes on the x center of the first node.

CENTER_Y( children : Layoutable[] )

A value for the alignChildren option. Centers the latter nodes on the y center of the first node.

LEFT( children : Layoutable[] )

A value for the alignChildren option. Left aligns nodes on the left of the first node.

BOTTOM( children : Layoutable[] )

A value for the alignChildren option. Aligns nodes on the bottom of the first node.

CENTER_BOTTOM( children : Layoutable[] )

A value for the alignChildren option. Aligns nodes on the bottom of the first node.

A value for the alignChildren option. Right aligns nodes on the right of the first node.

NONE( children : Layoutable[] )

A value for the alignChildren option. No alignment is performed.

Type ToggleNodeElement

import type { ToggleNodeElement } from 'scenerystack/sun';

Type ToggleNodeOptions

import type { ToggleNodeOptions } from 'scenerystack/sun';
  • alignChildren?: ( children: Layoutable[] ) => void
    {function} determines the relative layout of element Nodes. See below for pre-defined layout.
  • unselectedChildrenSceneGraphStrategy?: "included" | "excluded"
    Determine whether unselected children (the ones not displayed) are in the scene graph.
  • If included (the default), unselected children are in the scene graph and hidden via setVisible(false). In this case the layout is the union of the bounds of all children (visible and invisible).
  • If excluded, children are added to the scene graph when selected and removed when not selected. The ToggleNode has the bounds of its selected child. This option can sometimes improve performance. Children added to the ToggleNode outside the constructor will not be managed correctly.
  • & StrictOmit<NodeOptions, "children">

Source Code

See the source for ToggleNode.ts in the sun repository.