Skip to content

Commit

Permalink
add control for showing fluid displaced, phetsims/buoyancy#113
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Mar 15, 2024
1 parent 923c560 commit 498c938
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion js/buoyancy/view/BuoyancyLabScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default class BuoyancyLabScreenView extends DensityBuoyancyScreenView<Buo
new FluidDisplacedPanel( this.waterLevelVolumeProperty, maxBlockVolume, {
visibleProperty: model.showDisplacedFluidProperty
} ),
new MultiSectionPanelsNode( [ new DisplayOptionsNode( model ) ] )
new MultiSectionPanelsNode( [ new DisplayOptionsNode( model, {
showFluidDisplacedProperty: model.showDisplacedFluidProperty
} ) ] )
]
} );

Expand Down
10 changes: 9 additions & 1 deletion js/common/view/DisplayOptionsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import DensityBuoyancyCommonConstants from '../DensityBuoyancyCommonConstants.js
import DensityBuoyancyCommonColors from './DensityBuoyancyCommonColors.js';
import DensityBuoyancyModel from '../model/DensityBuoyancyModel.js';
import optionize, { combineOptions } from '../../../../phet-core/js/optionize.js';
import Property from '../../../../axon/js/Property.js';

// constants
const arrowSpacing = 15;
Expand All @@ -39,6 +40,9 @@ const checkboxSpacing = 5;

type SelfOptions = {
includeVectorScaleControl?: boolean;

// If provided, a checkbox control will be added to this panel, null to omit.
showFluidDisplacedProperty?: Property<boolean> | null;
};

type DisplayOptionsNodeOptions = SelfOptions & VBoxOptions;
Expand All @@ -48,6 +52,7 @@ export default class DisplayOptionsNode extends VBox {

const options = optionize<DisplayOptionsNodeOptions, SelfOptions, VBoxOptions>()( {
includeVectorScaleControl: true,
showFluidDisplacedProperty: null,
spacing: DensityBuoyancyCommonConstants.MARGIN,
align: 'left'
}, providedOptions );
Expand Down Expand Up @@ -115,7 +120,10 @@ export default class DisplayOptionsNode extends VBox {
align: 'left',
children: [
new Checkbox( model.showMassesProperty, new Text( DensityBuoyancyCommonStrings.massesStringProperty, labelOptions ), checkboxOptions ),
new Checkbox( model.showForceValuesProperty, new Text( DensityBuoyancyCommonStrings.forceValuesStringProperty, labelOptions ), checkboxOptions )
new Checkbox( model.showForceValuesProperty, new Text( DensityBuoyancyCommonStrings.forceValuesStringProperty, labelOptions ), checkboxOptions ),
...( options.showFluidDisplacedProperty ?
[ new Checkbox( options.showFluidDisplacedProperty, new Text( DensityBuoyancyCommonStrings.fluidDisplacedStringProperty, labelOptions ), checkboxOptions ) ] :
[] )
]
} )
]
Expand Down

0 comments on commit 498c938

Please sign in to comment.