Skip to content

Commit

Permalink
add validValues to dropper.soluteProperty, #271
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 23, 2023
1 parent e48561d commit 235e65e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion js/common/model/Dropper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Dropper extends PHMovable {
// See https://github.com/phetsims/ph-scale/issues/178
public readonly visibleProperty: Property<boolean>;

public constructor( solute: Solute, position: Vector2, dragBounds: Bounds2, providedOptions: DropperOptions ) {
public constructor( solute: Solute, solutes: Solute[], position: Vector2, dragBounds: Bounds2, providedOptions: DropperOptions ) {

const options = optionize<DropperOptions, SelfOptions, PHMovableOptions>()( {

Expand All @@ -59,6 +59,7 @@ export default class Dropper extends PHMovable {
super( position, dragBounds, options );

this.soluteProperty = new Property( solute, {
validValues: solutes,
tandem: options.tandem.createTandem( 'soluteProperty' ),
phetioValueType: Solute.SoluteIO,
phetioDocumentation: 'the solute dispensed by the dropper'
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/PHModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class PHModel<T extends Solution> implements TModel {
this.beaker = new Beaker( PHScaleConstants.BEAKER_POSITION );

const yDropper = this.beaker.position.y - this.beaker.size.height - 15;
this.dropper = new Dropper( Solute.WATER,
this.dropper = new Dropper( Solute.WATER, this.solutes,
new Vector2( this.beaker.position.x - 50, yDropper ),
new Bounds2( this.beaker.left + 40, yDropper, this.beaker.right - 200, yDropper ), {
tandem: options.tandem.createTandem( 'dropper' )
Expand Down
5 changes: 4 additions & 1 deletion js/common/view/SoluteComboBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type SoluteComboBoxOptions = SelfOptions &
export default class SoluteComboBox extends ComboBox<Solute> {

public constructor( selectedSoluteProperty: Property<Solute>,
solutes: Solute[], soluteListParent: Node,
soluteListParent: Node,
providedOptions: SoluteComboBoxOptions ) {

const options = optionize<SoluteComboBoxOptions, SelfOptions, ComboBoxOptions>()( {
Expand All @@ -41,6 +41,9 @@ export default class SoluteComboBox extends ComboBox<Solute> {

const items: ComboBoxItem<Solute>[] = [];

const solutes = selectedSoluteProperty.validValues!;
assert && assert( solutes );

// Create items for the listbox
solutes.forEach( solute => {

Expand Down
2 changes: 1 addition & 1 deletion js/macro/view/MacroScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class MacroScreenView extends ScreenView {

// solutes combo box
const soluteListParent = new Node();
const soluteComboBox = new SoluteComboBox( model.dropper.soluteProperty, model.solutes, soluteListParent, {
const soluteComboBox = new SoluteComboBox( model.dropper.soluteProperty, soluteListParent, {
maxWidth: 400,
tandem: options.tandem.createTandem( 'soluteComboBox' )
} );
Expand Down
2 changes: 1 addition & 1 deletion js/micro/view/MicroScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class MicroScreenView extends ScreenView {

// solutes combo box
const soluteListParent = new Node();
const soluteComboBox = new SoluteComboBox( model.dropper.soluteProperty, model.solutes, soluteListParent, {
const soluteComboBox = new SoluteComboBox( model.dropper.soluteProperty, soluteListParent, {
maxWidth: 400,
tandem: options.tandem.createTandem( 'soluteComboBox' )
} );
Expand Down

0 comments on commit 235e65e

Please sign in to comment.