-
Notifications
You must be signed in to change notification settings - Fork 12
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
Should Dialog API be unified with Node API? #455
Comments
That's only because Dialog had (has?) a
This could be true of any UI component. A solution should not depend on the existence of a Dialog at startup. Dialogs should be created when it makes the most sense to create them, which is usually on demand.
I see no reason to have 2 Properties;
What does "it has a pretty different way of being displayed" mean? I agree that Dialog will (eventually) have a different way of being added to the scene graph, since it will be associated with something like Java's glass pane. But I don't understand why the API to show/hide a Dialog is not simply
The default state of a Dialog should be
Dialog cannot be seen until |
The API and implementation are different than for typical scenery Nodes. // normal way to creating and showing a scenery Node
const myNode = new MyNode();
myParent.addChild(myNode);
// API for creating and showing a dialog
const myDialog = new MyDialog();
myDialog.show(); |
Where are you getting this API? It doesn't match current reality, nor does it match anything that I recall discussing. The only difference in APIs is that Dialogs are (or should be) invisible by default, and needs to be made visible to "show" the dialog. So: // normal way to creating and showing a scenery Node
const myNode = new MyNode();
myParent.addChild(myNode);
// API for creating and showing a dialog
const myDialog = new MyDialog(); // defaults to invisible
dialogParent.addChild( myDialog );
// ... and when it's time to show the dialog:
myDialog.visible = true; |
There are 24 matches of dialog = dialog || new OopsDialog( numberTooBigString );
dialog.show(); |
Ah, I see... In the current implementation, So to answer the original question, which was "Should Dialog API be unified with Node API?"... No, the APIs should not be unified, because Node and Dialog have different needs:
Typical uses would look like: // Node
const myNode = new MyNode(); // visible:true by default
myParent.addChild(myNode); // explicitly added to the scenegraph
myNode = false; // explicitly made invisible
myNode = true; // explicitly made visible
// Dialog
const myDialog = new MyDialog(); // visible:false by default, implicitly added to the scenegraph
myDialog.visible = true; // explicitly made visible, "show"
myDialog.visible = false; // explicitly made invisible, "hide" |
I understand that Dialog has different needs than a typical Node. But can you please clarify the flaws with this proposed API? const myDialog = new MyDialog();
phet.joist.sim.glassPane.addChild(myDialog); Is it mainly that |
It's not clear what you're proposing in the previous comment. Is Dialog Client code should not be explicitly adding popups (dialogs, list boxes, menus,...) to a global like |
Yes, as it is for Node. I'm trying to understand the disadvantages of unifying the Dialog API with the Node API.
As proposed in #455 (comment) hide would be done via
We could encapsulate that in Dialog like so: const myDialog = new MyDialog(); // dialog is visible but not part of the scenery graph
myDialog.addToGlassPane(); // dialog is added to phet.joist.sim.glassPane or equivalent
I'm trying to understand whether an API that deviates from Node's defaults is advantageous here, and if so, why. Also, would we ever want to add a Dialog to a parent node other than the glass pane? What about during testing? |
Hard to say without knowing more about PhET's "glass pane" feature. I doubt that there is a single glass pane instance. At a minimum, I think we'll need a glass pane per ScreenView (for screen-specific popups), and a global glass pane for the Sim (for PhET menu, About dialog, Options dialog, ...) |
In that case, we may need a way for clients to specify the dialog parent. Possibly something like: // Option A
new Dialog({parent: myScreen.glassPane}) // defaults to parent: phet.joist.sim.glassPane
// Option B
myScreen.glassPane.addChild(myDialog); |
What I've learned from this discussion is that deciding what the "best" API is for Dialog can't (and shouldn't) be done without an understanding of how Dialogs (and other popups) will ultimately be displayed. |
After reading through this issue, I don't see an obvious improvement in changing the API. My vote would be to do nothing. |
Ditto. |
This seems like it warrants further deliberation once we resume development on dialogs, unassigning until then. |
This came from discussion in #369. The typical client-side API for Node is:
The way we typically use Dialog is like so:
There are a few problems with the latter API.
visibleProperty
which is always true and an additionalisShowingProperty
which is true if the node has been added to the scene graph. I'm sure our clients could learn to understand this and deal with it, but it seems confusing.Here is one proposed API that overcomes some of the problems (and introduces new problems):
My first concern is performance. Is it a problem to always have the MyDialog in memory and in a layer (though invisible)? @jonathanolson would be best suited to answer that question since it requires an understanding of scenery implementation detail. If it is problematic to always have the MyDialog in the scene graph, we could try something like this:
Also note that Dialog show/hide currently has a11y specific logic that we would need to move if we choose one of these other paradigms.
Requesting initial comments from @jonathanolson @pixelzoom and @zepumph.
The text was updated successfully, but these errors were encountered: