Skip to content

UI Components Overview

SceneryStack splits reusable, pre-built Nodes across two libraries with different scopes: sun provides generic, domain-agnostic controls (the things any application needs — buttons, sliders, checkboxes), while scenery-phet provides PhET-simulation-specific visualizations and controls built on top of sun and scenery. Knowing which library a component lives in tells you how broadly reusable it's meant to be.

sun: generic UI controls

Everything in sun is bound to an axon Property and otherwise has no domain knowledge — a Checkbox doesn't know or care whether it's toggling gravity or sound.

ts
import { Checkbox, HSlider, RectangularPushButton, ComboBox, AccordionBox, Panel } from 'scenerystack/sun';
ComponentUse it for
CheckboxA single boolean toggle with a label Node
HSlider / VSliderContinuous numeric input bound to a NumberProperty and Range
RectangularPushButton / TextPushButtonA momentary action button
RectangularRadioButtonGroup / RadioButtonGroupMutually-exclusive selection from a small fixed set of options
ComboBoxMutually-exclusive selection from a longer list, in a dropdown
PanelBordered/background container that auto-sizes to its content
AccordionBoxCollapsible titled container, e.g. an optional "advanced controls" section
ABSwitch / ToggleSwitchA labeled two-state switch, an alternative to Checkbox for some layouts

Live demos

These controls have interactive embeds on their API pages. Try them here, then follow the links for full option tables.

sun

Checkbox API

HSlider API

RectangularPushButton API

scenery-phet

NumberControl API

ResetAllButton API

Compose these with FlowBox/GridBox rather than positioning each one by hand:

ts
import { VBox } from 'scenerystack/scenery';
import { Checkbox, HSlider } from 'scenerystack/sun';
import { Text } from 'scenerystack/scenery';

const controlPanel = new VBox( {
  spacing: 8,
  align: 'left',
  children: [
    new Checkbox( gravityEnabledProperty, new Text( 'Gravity' ) ),
    new HSlider( massProperty, massProperty.range! )
  ]
} );

scenery-phet: simulation-specific visualizations

scenery-phet builds on sun and scenery to provide components that show up across many PhET simulations but aren't generic enough for sun — visual metaphors for physical quantities, and the handful of controls every sim needs regardless of subject matter.

ts
import { ResetAllButton, NumberControl, ThermometerNode, ArrowNode, PhetFont } from 'scenerystack/scenery-phet';
ComponentUse it for
ResetAllButtonThe standard "reset the whole screen" button — see the Reset-All Pattern
NumberControlA labeled slider plus numeric readout plus increment/decrement, bundled together
ThermometerNodeA fluid-level thermometer bound to a temperature Property
ArrowNodeA vector/force-style arrow, sized and rotated from model data
FaceNodeA smiley/frowny face, common in game-style feedback
HeaterCoolerNodeThe heater/cooler control used across thermodynamics sims
PhetFontThe standard PhET typeface — use it instead of ad hoc font strings for visual consistency

Choosing between them

If it doesn't mention a physical quantity, it probably belongs in sun

A rule of thumb: if you can describe a component without referencing anything domain-specific ("a checkbox," "a slider," "a bordered panel"), it's sun. If describing it requires a physical concept ("a thermometer," "a force arrow," "a heater/cooler"), it's scenery-phet. When you need something novel to your sim's domain that isn't in either library, build it as a plain Node/Path composition in your own view/ folder rather than trying to force-fit an existing component — see Project Structure Conventions.

Where to go next