Skip to content

Commit

Permalink
opt out of overwriting range in MaterialControlNode when there is a d…
Browse files Browse the repository at this point in the history
…ensity slider that already has a range, #268

Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Jul 26, 2024
1 parent 7589378 commit dde07b2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions js/buoyancy-basics/model/BuoyancyBasicsExploreModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js';
import Property from '../../../../axon/js/Property.js';
import Matrix3 from '../../../../dot/js/Matrix3.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Range from '../../../../dot/js/Range.js';
import Cube from '../../common/model/Cube.js';
import DensityBuoyancyModel, { DensityBuoyancyModelOptions } from '../../common/model/DensityBuoyancyModel.js';
import Material from '../../common/model/Material.js';
Expand Down Expand Up @@ -45,6 +46,11 @@ export default class BuoyancyBasicsExploreModel extends DensityBuoyancyModel {
} );

const sharedBlockOptions = {
customMaterialOptions: {
densityPropertyOptions: {
range: new Range( 10, 10000 )
}
},
availableMassMaterials: [
...Material.SIMPLE_MASS_MATERIALS,
'CUSTOM'
Expand Down
1 change: 1 addition & 0 deletions js/buoyancy-basics/view/BuoyancyBasicsExploreScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class BuoyancyBasicsExploreScreenView extends BuoyancyScreenView<
this.popupLayer, {
useDensityControlInsteadOfMassControl: true,
syncCustomMaterialDensity: false,
ownsCustomDensityRange: false,
customKeepsConstantDensity: true,
tandem: tandem,
minCustomMass: 0.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default class BuoyancyApplicationsScreenView extends BuoyancyScreenView<B
minCustomVolumeLiters: 0.5,
showMassAsReadout: true,
customKeepsConstantDensity: true,
ownsCustomDensityRange: false, // Bottle has a good range for itself.
tandem: materialInsideControlsTandem,

// When controlling the material inside, the custom density is an independent variable and should not automatically
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/BlockControlNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import DensityBuoyancyCommonStrings from '../../DensityBuoyancyCommonStrings.js'
import { combineOptions } from '../../../../phet-core/js/optionize.js';
import PrecisionSliderThumb from './PrecisionSliderThumb.js';
import UnitConversionProperty from '../../../../axon/js/UnitConversionProperty.js';
import Range from '../../../../dot/js/Range.js';

export type BlockControlNodeOptions = MaterialMassVolumeControlNodeOptions;

Expand Down Expand Up @@ -68,14 +67,15 @@ export default class BlockControlNode extends MaterialMassVolumeControlNode {
const densityNumberControl = new NumberControl(
DensityBuoyancyCommonStrings.densityStringProperty,
densityAsLitersProperty,
new Range( customDensityProperty.range.min / DensityBuoyancyCommonConstants.LITERS_IN_CUBIC_METER, 10 ),
densityAsLitersProperty.range,
combineOptions<NumberControlOptions>( {
sliderOptions: {
accessibleName: DensityBuoyancyCommonStrings.densityStringProperty,
thumbNode: new PrecisionSliderThumb( {
tandem: densityNumberControlTandem.createTandem( 'slider' ).createTandem( 'thumbNode' ),
thumbFill: options.color
} )
} ),
phetioLinkedProperty: customDensityProperty
},
numberDisplayOptions: {
valuePattern: DensityBuoyancyCommonConstants.KILOGRAMS_PER_VOLUME_PATTERN_STRING_PROPERTY
Expand Down
6 changes: 5 additions & 1 deletion js/common/view/MaterialControlNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type SelfMaterialControlNodeOptions = {

syncCustomMaterialDensity?: boolean;

// When true, this control will set the MaterialProperty's custom materials density range based on provided custom schema.
ownsCustomDensityRange?: boolean;

// A label, if provided to be placed to the right of the ComboBox
labelNode?: Node | null;

Expand All @@ -47,6 +50,7 @@ export default class MaterialControlNode extends VBox {

const options = optionize<MaterialControlNodeOptions, SelfMaterialControlNodeOptions, VBoxOptions>()( {
syncCustomMaterialDensity: true,
ownsCustomDensityRange: true,
labelNode: null,
minCustomMass: 0.5,
maxCustomMass: 10,
Expand Down Expand Up @@ -79,7 +83,7 @@ export default class MaterialControlNode extends VBox {

// Set the custom density range, then this control owns the range of the density.
// TODO: Should this move to the model somehow? https://github.com/phetsims/density-buoyancy-common/issues/268
if ( customMaterials.length > 0 ) {
if ( customMaterials.length > 0 && options.ownsCustomDensityRange ) {
materialProperty.customMaterial.densityProperty.rangeProperty.link( () => {
materialProperty.customMaterial.densityProperty.rangeProperty.value = new Range(
options.minCustomMass / options.maxVolumeLiters * DensityBuoyancyCommonConstants.LITERS_IN_CUBIC_METER,
Expand Down

0 comments on commit dde07b2

Please sign in to comment.