Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox mini-sprint #914

Closed
zepumph opened this issue Nov 12, 2024 · 18 comments
Closed

Checkbox mini-sprint #914

zepumph opened this issue Nov 12, 2024 · 18 comments

Comments

@zepumph
Copy link
Member

zepumph commented Nov 12, 2024

The PhET-iO team is revisiting many common code components to make improvements and add value.

UPDATE: THIS LIST WAS EXPANDED IN PHET-IO MEETING AGENGA, SEE NOTEST FROM 11/14.

PhET-iO:

  • Consistent APIs for like components
  • What is instrumented?
    • nodes for visibility
    • customization of content
    • listening to the input (instead of just the model Property)
  • What is phetioFeatured
  • What has linked elements?
  • Label/icon instrumentation in relation (dependency injection)
  • VisibleProperty needed?
  • Visibility for a subset of content (combining if currently "one per node")
  • EnabledProperty needed?
  • Display only mode needed?
  • Migration needs (ok to break the API sometimes?)

Other

  • Accessible names and help text API
  • Review current API for more complex description for improvements (context/object responses and state description)
  • Dynamic layout implementation check

UPDATE: THIS LIST WAS EXPANDED IN PHET-IO MEETING AGENGA, SEE NOTEST FROM 11/14.

@arouinfar
Copy link
Contributor

@zepumph @samreid I reviewed Checkbox in several sims using the list we generated as a guide. I focused on the design-related aspects, ignoring things like migration.

The tree structure of Checkbox is very consistent across sims and follows this pattern:

- checkbox
    enabledProperty
    visibleProperty
    *property
    + fireListener  (not featured)
    + toggleAction  (not featured)
  • It is always desirable for Checkbox to have a LinkedProperty. I do not know if this is done on a sim-by-sim basis, or if there is something that is/could be done in sun to streamline this.

  • The phetioFeatured defaults are appropriate (Checkbox itself, enabledProperty and visibleProperty), but it would be nice if the target of the LinkedProperty could also be featured by default, see Should CheckBox and other UI component LinkedElement property be phetioFeatured? #782.

  • A displayOnlyProperty would be immensely useful in Checkbox. Checkboxes often serve as a legend, so using enabledProperty to prevent interaction is problematic, as it changes the appearance of the Checkbox. Two examples of this are in Natural Selection and Graphing Quadratics.

    image image
  • When in 'display' mode, the checkbox itself would be hidden, leaving its associated label/icon visible. From what I know about dynamic layout, I suspect the contents to shift to the left to fill the empty space, but that would look pretty bad in a sim like Natural Selection. It would look nicer if the contents stayed in place. Perhaps that could be an option?
    image image

@samreid
Copy link
Member

samreid commented Nov 14, 2024

This patch adds displayOnlyProperty to Checkbox. I tested it in studio and it seems to be working well. I tested that it correctly disables interaction (pickable false) when display only is true. Keyboard can still focus it but no longer change it when in display only mode.

My first review question about this proposal is that the implementation would be at odds with outside code trying to control the pickability, like myCheckbox.pickable = true.

Second review question is about how/how much to factor out between occurrences like this one and ComboBox and other cases. For instance, we have EnabledProperty which is similar.

@zepumph can you please review and advise?

Subject: [PATCH] Add displayOnlyProperty to Checkbox, see https://github.com/phetsims/sun/issues/914
---
Index: js/Checkbox.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Checkbox.ts b/js/Checkbox.ts
--- a/js/Checkbox.ts	(revision bfd00648a383eb16915781d62a98fce079511cf2)
+++ b/js/Checkbox.ts	(date 1731601312264)
@@ -25,6 +25,8 @@
 import Tandem from '../../tandem/js/Tandem.js';
 import Utterance, { TAlertable } from '../../utterance-queue/js/Utterance.js';
 import sun from './sun.js';
+import Property from '../../axon/js/Property.js';
+import BooleanProperty from '../../axon/js/BooleanProperty.js';
 
 // constants
 const BOOLEAN_VALIDATOR = { valueType: 'boolean' };
@@ -84,6 +86,10 @@
   // Handles layout of the content, rectangles and mouse/touch areas
   private readonly constraint: CheckboxConstraint;
 
+  // For use via PhET-iO, see https://github.com/phetsims/sun/issues/451
+  // This is not generally controlled by the user, so it is not reset when the Reset All button is pressed.
+  private readonly displayOnlyProperty: Property<boolean>;
+
   public constructor( property: PhetioProperty<boolean>, content: Node, providedOptions?: CheckboxOptions ) {
 
     const options = optionize<CheckboxOptions, SelfOptions, ParentOptions>()( {
@@ -234,6 +240,16 @@
       tandemName: 'property'
     } );
 
+    this.displayOnlyProperty = new BooleanProperty( false, {
+      tandem: options.tandem.createTandem( 'displayOnlyProperty' ),
+      phetioFeatured: true,
+      phetioDocumentation: 'disables interaction and makes it appear like a display that shows the current selection'
+    } );
+    this.displayOnlyProperty.link( displayOnly => {
+      checkboxNode.visible = !displayOnly;
+      this.pickable = !displayOnly;
+    } );
+
     // support for binder documentation, stripped out in builds and only runs when ?binder is specified
     assert && phet?.chipper?.queryParameters?.binder && InstanceRegistry.registerDataURL( 'sun', 'Checkbox', this );
 
@@ -247,6 +263,7 @@
       this.checkedNode.dispose();
       checkboxNode.dispose();
       fireListener.dispose();
+      this.displayOnlyProperty.dispose();
 
       if ( property.hasListener( checkboxCheckedListener ) ) {
         property.unlink( checkboxCheckedListener );

@samreid samreid removed their assignment Nov 14, 2024
@kathy-phet kathy-phet changed the title Checkbox minisprint Checkbox mini-sprint Nov 14, 2024
@zepumph
Copy link
Member Author

zepumph commented Nov 14, 2024

Today in phet-io meeting we discussed the need for the toggleAction and firedEmitter. We certainly don't need both, but perhaps we don't need either. We should discuss what researchers need from UI components, because likely it is just looking at the model properties.

samreid added a commit that referenced this issue Dec 4, 2024
@samreid
Copy link
Member

samreid commented Dec 4, 2024

It is always desirable for Checkbox to have a LinkedProperty.

I added an assertion for this. It seemed to be passing local aqua fuzzing, so let's double check on CT. But I'm not convinced that an assertion is the right level for this, we may want another validation flag.

  • UPDATE: We agreed this should be buried behind a Validation flag.

@samreid
Copy link
Member

samreid commented Dec 4, 2024

The phetioFeatured defaults are appropriate (Checkbox itself, enabledProperty and visibleProperty), but it would be nice if the target of the LinkedProperty could also be featured by default,

There is no way for a Property to know if it will later be consumed by a CheckBox, so that cannot inform the Property default metadata. Should we add an assertion for this case?

  • UPDATE: We agreed this could be covered by an assert && Tandem.VALIDATION. So the new validation assertion will be: if the checkbox is featured, then the property must also be featured.
Subject: [PATCH] Use Tandem.VALIDATION, see https://github.com/phetsims/sun/issues/914
---
Index: js/Checkbox.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Checkbox.ts b/js/Checkbox.ts
--- a/js/Checkbox.ts	(revision 73a4e885e0bb273251f52007795ee99f4cd0e7a4)
+++ b/js/Checkbox.ts	(date 1733342312504)
@@ -237,6 +237,10 @@
     if ( assert && Tandem.VALIDATION && this.isPhetioInstrumented() ) {
       assert && assert( property.isPhetioInstrumented(), 'Property should be instrumented if Checkbox is instrumented' );
       assert && assert( options.phetioLinkProperty, 'Property should be linked if Checkbox is instrumented' );
+
+      if ( this.phetioFeatured ) {
+        assert && assert( property.phetioFeatured, 'Property should be featured in the controlling Checkbox is featured' );
+      }
     }
 
     // support for binder documentation, stripped out in builds and only runs when ?binder is specified

UPDATE: with this patch, here is a list of repos that fail this assertion:

blackbody-spectrum
build-an-atom
calculus-grapher
capacitor-lab-basics
chains
charges-and-fields
concentration
coulombs-law
faradays-electromagnetic-lab
faradays-law
fourier-making-waves
gas-properties
geometric-optics
geometric-optics-basics
gravity-force-lab
gravity-force-lab-basics
greenhouse-effect
hookes-law
keplers-laws
magnets-and-electromagnets
molarity
molecules-and-light
my-solar-system
natural-selection
number-pairs
ohms-law
ph-scale-basics
projectile-data-lab
projectile-motion
proportion-playground
quantum-measurement
resistance-in-a-wire
scenery-phet
states-of-matter
states-of-matter-basics
sun
wave-on-a-string
wilder

That list was long enough for me to double check before visiting each site and adding phetioFeatured to those Properties. (Noting each simulation may have many cases).

@arouinfar or @zepumph what do you think?

@samreid samreid assigned samreid and unassigned zepumph Dec 4, 2024
samreid added a commit that referenced this issue Dec 4, 2024
@samreid samreid assigned zepumph and arouinfar and unassigned samreid Dec 4, 2024
zepumph added a commit that referenced this issue Dec 4, 2024
zepumph added a commit to phetsims/blackbody-spectrum that referenced this issue Dec 4, 2024
zepumph added a commit to phetsims/faradays-electromagnetic-lab that referenced this issue Dec 4, 2024
@zepumph
Copy link
Member Author

zepumph commented Dec 4, 2024

More display only Property notes:

Subject: [PATCH] Add displayOnlyProperty to Checkbox, see https://github.com/phetsims/sun/issues/914
---
Index: js/Checkbox.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Checkbox.ts b/js/Checkbox.ts
--- a/js/Checkbox.ts	(revision 018efb020653313d2b4083829447c893896b0e21)
+++ b/js/Checkbox.ts	(date 1733348415402)
@@ -6,7 +6,9 @@
  * @author Chris Malley (PixelZoom, Inc.)
  */
 
+import BooleanProperty from '../../axon/js/BooleanProperty.js';
 import PhetioProperty from '../../axon/js/PhetioProperty.js';
+import Property from '../../axon/js/Property.js';
 import validate from '../../axon/js/validate.js';
 import Bounds2 from '../../dot/js/Bounds2.js';
 import { m3 } from '../../dot/js/Matrix3.js';
@@ -84,6 +86,10 @@
   // Handles layout of the content, rectangles and mouse/touch areas
   private readonly constraint: CheckboxConstraint;
 
+  // For use via PhET-iO, see https://github.com/phetsims/sun/issues/451
+  // This is not generally controlled by the user, so it is not reset when the Reset All button is pressed.
+  private readonly displayOnlyProperty: Property<boolean>;
+
   public constructor( property: PhetioProperty<boolean>, content: Node, providedOptions?: CheckboxOptions ) {
 
     const options = optionize<CheckboxOptions, SelfOptions, ParentOptions>()( {
@@ -245,6 +251,17 @@
       // }
     }
 
+    this.displayOnlyProperty = new BooleanProperty( false, {
+      tandem: options.tandem.createTandem( 'displayOnlyProperty' ),
+      phetioFeatured: true,
+      phetioDocumentation: 'disables interaction for use as a legend'
+    } );
+    this.displayOnlyProperty.link( displayOnly => {
+      checkboxNode.visible = !displayOnly;
+      this.tagName = displayOnly ? 'p' : 'input'; // TODO: this take away focusability, but still includes the text in the PDOM. Otherwise it is focusable and says "checkbox, unavailable" on NVDA.
+      this.inputEnabled = !displayOnly;
+    } );
+
     // support for binder documentation, stripped out in builds and only runs when ?binder is specified
     assert && window.phet?.chipper?.queryParameters?.binder && InstanceRegistry.registerDataURL( 'sun', 'Checkbox', this );
 
@@ -258,6 +275,7 @@
       this.checkedNode.dispose();
       checkboxNode.dispose();
       fireListener.dispose();
+      this.displayOnlyProperty.dispose();
 
       if ( property.hasListener( checkboxCheckedListener ) ) {
         property.unlink( checkboxCheckedListener );

@zepumph
Copy link
Member Author

zepumph commented Dec 5, 2024

We made good progress trying to understand the relationship between enabled and displayOnly, and how it effects inputEnabled. Here is a patch that we likely could have committed, but I didn't test enough.

Subject: [PATCH] Add displayOnlyProperty to Checkbox, see https://github.com/phetsims/sun/issues/914
---
Index: perennial/js/listContinuousTests.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/perennial/js/listContinuousTests.js b/perennial/js/listContinuousTests.js
--- a/perennial/js/listContinuousTests.js	(revision 72c34f2e56b7b16acb3d2008ac7a37ac194de231)
+++ b/perennial/js/listContinuousTests.js	(date 1733356339036)
@@ -160,6 +160,7 @@
     } );
   }
 
+  // TODO: add built debug version? https://github.com/phetsims/sun/issues/914
   tests.push( {
     test: [ repo, 'fuzz', 'built' ],
     type: 'sim-test',
Index: axon/js/Property.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/axon/js/Property.ts b/axon/js/Property.ts
--- a/axon/js/Property.ts	(revision 46d1abcde81e4450fb8663e2a5ebf383fc01c7bf)
+++ b/axon/js/Property.ts	(date 1733356282058)
@@ -62,6 +62,7 @@
    * Overridden to make public
    */
   public override set( value: T ): void {
+    assert && assertSlow && assert( this.isSettable(), 'Trying to set an Property that is isSettable:false' );
     super.set( value );
   }
 
Index: sun/js/Checkbox.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/sun/js/Checkbox.ts b/sun/js/Checkbox.ts
--- a/sun/js/Checkbox.ts	(revision 018efb020653313d2b4083829447c893896b0e21)
+++ b/sun/js/Checkbox.ts	(date 1733357422612)
@@ -6,7 +6,10 @@
  * @author Chris Malley (PixelZoom, Inc.)
  */
 
+import BooleanProperty from '../../axon/js/BooleanProperty.js';
+import DerivedProperty from '../../axon/js/DerivedProperty.js';
 import PhetioProperty from '../../axon/js/PhetioProperty.js';
+import Property from '../../axon/js/Property.js';
 import validate from '../../axon/js/validate.js';
 import Bounds2 from '../../dot/js/Bounds2.js';
 import { m3 } from '../../dot/js/Matrix3.js';
@@ -84,6 +87,10 @@
   // Handles layout of the content, rectangles and mouse/touch areas
   private readonly constraint: CheckboxConstraint;
 
+  // For use via PhET-iO, see https://github.com/phetsims/sun/issues/451
+  // This is not generally controlled by the user, so it is not reset when the Reset All button is pressed.
+  private readonly displayOnlyProperty: Property<boolean>;
+
   public constructor( property: PhetioProperty<boolean>, content: Node, providedOptions?: CheckboxOptions ) {
 
     const options = optionize<CheckboxOptions, SelfOptions, ParentOptions>()( {
@@ -245,6 +252,22 @@
       // }
     }
 
+    // TODO: DESIGN: An assertion that you cannot be display only AND enabled? Or a no op? I doubt it.
+    this.displayOnlyProperty = new BooleanProperty( false, {
+      tandem: options.tandem.createTandem( 'displayOnlyProperty' ),
+      phetioFeatured: true,
+      phetioDocumentation: 'disables interaction for use as a legend'
+    } );
+
+    this.inputEnabledProperty = DerivedProperty.and( [ DerivedProperty.not( this.displayOnlyProperty ), this.enabledProperty ] );
+    this.displayOnlyProperty.link( displayOnly => {
+      checkboxNode.visible = !displayOnly;
+      console.log( 'displayOnly', displayOnly );
+
+      // TODO: this takes away focusability, but still includes the text in the PDOM. Otherwise it is focusable and says "checkbox, unavailable" on NVDA. What's best? https://github.com/phetsims/sun/issues/914
+      this.tagName = displayOnly ? 'p' : 'input';
+    } );
+
     // support for binder documentation, stripped out in builds and only runs when ?binder is specified
     assert && window.phet?.chipper?.queryParameters?.binder && InstanceRegistry.registerDataURL( 'sun', 'Checkbox', this );
 
@@ -258,6 +281,7 @@
       this.checkedNode.dispose();
       checkboxNode.dispose();
       fireListener.dispose();
+      this.displayOnlyProperty.dispose();
 
       if ( property.hasListener( checkboxCheckedListener ) ) {
         property.unlink( checkboxCheckedListener );
Index: scenery/js/nodes/Node.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/scenery/js/nodes/Node.ts b/scenery/js/nodes/Node.ts
--- a/scenery/js/nodes/Node.ts	(revision f744a1526185eeb12aed37875f3ee194e8b3181e)
+++ b/scenery/js/nodes/Node.ts	(date 1733356978806)
@@ -448,7 +448,10 @@
   public readonly opacityProperty: TinyProperty<number>;
 
   // Disabled opacity, in the range from 0 (fully transparent) to 1 (fully opaque).
-  // Combined with the normal opacity ONLY when the node is disabled.
+  // Combined with the normal opacity ONLY when the node is disabled. Note, the rendered
+  // disabled opacity depends greatly on the value of this.opacity. This acts as a multiplier
+  // to that value. i.e. read disabledOpacity = .5 as "50% of the current opacity", so if
+  // this.opacity is .5, then this renders as 25% opacity, see this.getEffectiveOpacity
   // NOTE: This is fired synchronously when the opacity of the Node is toggled
   public readonly disabledOpacityProperty: TinyProperty<number>;
 
@@ -791,6 +794,8 @@
 
     this._inputEnabledProperty = new TinyForwardingProperty( DEFAULT_OPTIONS.inputEnabled,
       DEFAULT_OPTIONS.phetioInputEnabledPropertyInstrumented );
+    this._inputEnabledProperty.lazyLink( x => console.log( 'inputEnabled', x ) );
+
     this.clipAreaProperty = new TinyProperty<Shape | null>( DEFAULT_OPTIONS.clipArea );
     this.voicingVisibleProperty = new TinyProperty<boolean>( true );
     this._mouseArea = DEFAULT_OPTIONS.mouseArea;
@@ -4410,8 +4415,13 @@
    */
   protected onEnabledPropertyChange( enabled: boolean ): void {
     !enabled && this.interruptSubtreeInput();
-    this.inputEnabled = enabled;
+
+    // We don't want to overstep here if inputEnabledProperty has been set elsewhere to be a DerivedProperty.
+    if ( this.inputEnabledProperty.isSettable() ) {
+      this.inputEnabled = enabled;
+    }
 
+    // 1 means "no different than the current, enabled opacity", see this.getEffectiveOpacity()
     if ( this.disabledOpacityProperty.value !== 1 ) {
       this.filterChangeEmitter.emit();
     }
Index: axon/js/TinyForwardingProperty.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/axon/js/TinyForwardingProperty.ts b/axon/js/TinyForwardingProperty.ts
--- a/axon/js/TinyForwardingProperty.ts	(revision 46d1abcde81e4450fb8663e2a5ebf383fc01c7bf)
+++ b/axon/js/TinyForwardingProperty.ts	(date 1733357422612)
@@ -240,6 +240,12 @@
     return this.targetProperty || null;
   }
 
+  // A TinyForwardingProperty is settable if the target property is settable.
+  public override isSettable(): boolean {
+
+    return this.targetProperty ? this.targetProperty.isSettable() : super.isSettable();
+  }
+
   /**
    * This currently also involves deleting the field.
    */

samreid added a commit to phetsims/assert that referenced this issue Dec 5, 2024
samreid added a commit to phetsims/charges-and-fields that referenced this issue Dec 5, 2024
samreid added a commit to phetsims/molarity that referenced this issue Dec 5, 2024
zepumph added a commit to phetsims/scenery that referenced this issue Dec 6, 2024
@zepumph
Copy link
Member Author

zepumph commented Dec 9, 2024

more discussion about how best to account for gates that want to control inputEnabled:

Subject: [PATCH] https://github.com/phetsims/sun/issues/914
---
Index: js/Checkbox.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Checkbox.ts b/js/Checkbox.ts
--- a/js/Checkbox.ts	(revision 2096c82ddc24bacb4d7c86a091a9b154ab6c7e9e)
+++ b/js/Checkbox.ts	(date 1733767471749)
@@ -6,7 +6,11 @@
  * @author Chris Malley (PixelZoom, Inc.)
  */
 
+import BooleanProperty from '../../axon/js/BooleanProperty.js';
+import DerivedProperty from '../../axon/js/DerivedProperty.js';
 import PhetioProperty from '../../axon/js/PhetioProperty.js';
+import Property from '../../axon/js/Property.js';
+import TReadOnlyProperty from '../../axon/js/TReadOnlyProperty.js';
 import validate from '../../axon/js/validate.js';
 import Bounds2 from '../../dot/js/Bounds2.js';
 import { m3 } from '../../dot/js/Matrix3.js';
@@ -84,6 +88,10 @@
   // Handles layout of the content, rectangles and mouse/touch areas
   private readonly constraint: CheckboxConstraint;
 
+  // For use via PhET-iO, see https://github.com/phetsims/sun/issues/451
+  // This is not generally controlled by the user, so it is not reset when the Reset All button is pressed.
+  private readonly displayOnlyProperty: Property<boolean>;
+
   public constructor( property: PhetioProperty<boolean>, content: Node, providedOptions?: CheckboxOptions ) {
 
     const options = optionize<CheckboxOptions, SelfOptions, ParentOptions>()( {
@@ -209,14 +217,67 @@
     } );
     this.addInputListener( fireListener );
 
+    this.displayOnlyProperty = new BooleanProperty( false, {
+      tandem: options.tandem.createTandem( 'displayOnlyProperty' ),
+      phetioFeatured: true,
+      phetioDocumentation: 'disables interaction for use as a legend'
+    } );
+
+    // A dynamic property that can work with multiple dependencies to keep the right value.
+    // TODO: Use TinyForwardingProperty or DynamicProperty as a container to hold a single DerivedProperty that changes as gates update (added or removed)?
+    // TODO: Can we use GatedBooleanProperty for this still? PhET-iO makes things challenging, but perhaps we can add assertion to the dynamic stuff that we aren't PhET-iO instrumented when we need this.
+    // TODO: Remember that issue about how we want to be able to swap out two instances in the PhET-iO API without calling it a disposal of a static element.
+    this.setInputEnabledProperty( new GatedDynamicBooleanProperty( {
+      gates: [ this.enabledProperty, DerivedProperty.not( this.displayOnlyProperty ) ]
+    } ) );
+
+
+    // TODO: But this is still horrible for PhET-iO, we'll keep talking.
+    this.setInputEnabledProperty( new DerivedProperty( [ this.inputEnabledProperty.target, new GatedDynamicBooleanProperty( {
+      gates: [ this.enabledProperty, DerivedProperty.not( this.displayOnlyProperty ) ]
+    } ) ] ) );
+
+    // const x = ....;
+    // x.addGate( this.enabledProperty );
+    // x.addGate( DerivedProperty.not( this.displayOnlyProperty ) );
+
+    //////////////////////////////
+    // A the usage site
+    const myCheckbox = new Checkbox();
+    const x2 = myCheckbox.inputEnabledProperty.targetProperty; // or myCheckbox.gatedInputEnabledPropertygetter();
+    affirm( myCheckbox.inputEnabledProperty.targetProperty instanceof GatedDynamicBooleanProperty );
+    x2.addGate();
+
+
+    // Other ideas that got us here
+    // // this.addInputEnabledPropertyGate( DerivedProperty.not( this.displayOnlyProperty ) );
+    //
+    // this.inputEnabledProperty.addGate(!DerivedProperty.not( this.displayOnlyProperty ));
+    //
+    // const x = new DisplayOnlyProperty( this.enabledProperty, this.inputEnabledProperty );
+    // x.addInputEnabledGate( this.enabledProperty );
+    // x.addInputEnabledGate( anotherGate );
+    // // x.addInputEnabledGate( DerivedProperty.not( this.displayOnlyProperty ) );
+    //
+    // this.addInputEnabledPropertyGate( DerivedProperty.not( this.displayOnlyProperty ) );
+
     // sync with property
     const checkboxCheckedListener = ( checked: boolean ) => {
       this.checkedNode.visible = checked;
       this.uncheckedNode.visible = !checked;
-      this.pdomChecked = checked;
+      if ( !this.displayOnlyProperty.value ) {
+        this.pdomChecked = checked; // TODO????
+      }
     };
+
     property.link( checkboxCheckedListener );
 
+    this.displayOnlyProperty.link( displayOnly => {
+      checkboxNode.visible = !displayOnly;
+      this.tagName = displayOnly ? 'p' : 'input'; //TODO: still a work in progress.
+      checkboxCheckedListener && checkboxCheckedListener( property.value );
+    } );
+
     // Apply additional options
     this.mutate( options );
 
@@ -256,6 +317,7 @@
       this.checkedNode.dispose();
       checkboxNode.dispose();
       fireListener.dispose();
+      this.displayOnlyProperty.dispose();
 
       if ( property.hasListener( checkboxCheckedListener ) ) {
         property.unlink( checkboxCheckedListener );
@@ -266,6 +328,14 @@
     };
   }
 
+  public override set inputEnabledProperty( property: TReadOnlyProperty<boolean> | null ) {
+    assert && assert( false, 'Checkbox.inputEnabledProperty is read-only' );
+  }
+
+  public override setInputEnabledProperty( newTarget: TReadOnlyProperty<boolean> | null ): this {
+    assert && assert( false, 'Checkbox.inputEnabledProperty is read-only' );
+  }
+
   public override dispose(): void {
     this.constraint.dispose();
 

jessegreenberg pushed a commit to phetsims/perennial that referenced this issue Dec 10, 2024
zepumph added a commit to phetsims/density-buoyancy-common that referenced this issue Dec 13, 2024
zepumph added a commit that referenced this issue Dec 13, 2024
@zepumph
Copy link
Member Author

zepumph commented Dec 13, 2024

zepumph added a commit that referenced this issue Dec 13, 2024
zepumph added a commit to phetsims/solar-system-common that referenced this issue Dec 13, 2024
zepumph added a commit to phetsims/natural-selection that referenced this issue Dec 13, 2024
zepumph added a commit that referenced this issue Dec 13, 2024
@zepumph
Copy link
Member Author

zepumph commented Dec 13, 2024

Alright. ToggleAction was removed, and more opt-ins have been done. Over to @arouinfar to take a look through other usages to see if we want any more displayOnlyProperty opt-ins.

@samreid can you please review my commits?

@zepumph zepumph assigned samreid and arouinfar and unassigned zepumph Dec 13, 2024
samreid added a commit that referenced this issue Dec 16, 2024
@samreid
Copy link
Member

samreid commented Dec 16, 2024

The code commits look good, and I added a bit of documentation. Leaving assigned to @arouinfar for steps identified above.

@zepumph
Copy link
Member Author

zepumph commented Dec 16, 2024

from standup today, @arouinfar is going to create a separate issue to go over current hydrogen sims that may want this added. Above @samreid and I made one more minor change to remove an unused option. Also please note that likely the linked element code in Checkbox will change over in #921.

Over to @arouinfar. I believe this issue just needs a review of the current checkbox instrumentation level, and the look and feel of displayOnlyProperty.

@arouinfar
Copy link
Contributor

@samreid @zepumph I reviewed on main, and things look good. I opened #923 to add displayOnlyProperty to Hydrogen sims.

Is there anything else we need to do for this issue, perhaps migration rules?

@arouinfar arouinfar assigned samreid and zepumph and unassigned arouinfar Dec 17, 2024
@zepumph
Copy link
Member Author

zepumph commented Dec 17, 2024

All good here. Thanks!

@zepumph zepumph closed this as completed Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants