-
Notifications
You must be signed in to change notification settings - Fork 4
/
GQScreenView.ts
116 lines (101 loc) · 4.63 KB
/
GQScreenView.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2018-2024, University of Colorado Boulder
/**
* GQScreenView is the base class for ScreenViews in this sim.
* It is responsible for creating Nodes that are common to all screens, and for common layout.
*
* @author Andrea Lin
* @author Chris Malley (PixelZoom, Inc.)
*/
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import ScreenView from '../../../../joist/js/ScreenView.js';
import EyeToggleButton from '../../../../scenery-phet/js/buttons/EyeToggleButton.js';
import ResetAllButton from '../../../../scenery-phet/js/buttons/ResetAllButton.js';
import PhetColorScheme from '../../../../scenery-phet/js/PhetColorScheme.js';
import { Node, VBox } from '../../../../scenery/js/imports.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import graphingQuadratics from '../../graphingQuadratics.js';
import GQConstants from '../GQConstants.js';
import GQModel from '../model/GQModel.js';
import GQViewProperties from './GQViewProperties.js';
import PointToolNode from './PointToolNode.js';
// constants
const X_SPACING = 15; // between graph and control panels
export default class GQScreenView extends ScreenView {
public constructor( model: GQModel, viewProperties: GQViewProperties, graphNode: Node,
equationAccordionBox: Node, graphControlPanel: Node, tandem: Tandem ) {
super( {
layoutBounds: GQConstants.SCREEN_VIEW_LAYOUT_BOUNDS,
tandem: tandem
} );
// Point tools moveToFront when dragged, so give them a common parent to preserve rendering order.
const pointToolsParent = new Node();
pointToolsParent.addChild( new PointToolNode(
model.leftPointTool,
model.modelViewTransform,
model.graph,
viewProperties.graphContentsVisibleProperty, {
tandem: tandem.createTandem( 'leftPointToolNode' )
} ) );
pointToolsParent.addChild( new PointToolNode(
model.rightPointTool,
model.modelViewTransform,
model.graph,
viewProperties.graphContentsVisibleProperty, {
tandem: tandem.createTandem( 'rightPointToolNode' )
} ) );
// Toggle button for showing/hiding contents of graph
const graphContentsToggleButton = new EyeToggleButton( viewProperties.graphContentsVisibleProperty, {
scale: 0.75,
baseColor: new DerivedProperty( [ viewProperties.graphContentsVisibleProperty ],
graphContentsVisible => graphContentsVisible ? 'white' : PhetColorScheme.BUTTON_YELLOW ),
left: model.modelViewTransform.modelToViewX( model.graph.xRange.max ) + 21,
bottom: model.modelViewTransform.modelToViewY( model.graph.yRange.min ),
tandem: tandem.createTandem( 'graphContentsToggleButton' ),
phetioDocumentation: 'button that shows/hides the contents of the graph'
} );
// Set maxWidth for each control panel individually
const controlPanelMaxWidth = this.layoutBounds.width - graphNode.width - ( 2 * GQConstants.SCREEN_VIEW_X_MARGIN ) - X_SPACING;
assert && assert( controlPanelMaxWidth > 0, `unexpected controlPanelMaxWidth: ${controlPanelMaxWidth}` );
equationAccordionBox.maxWidth = controlPanelMaxWidth;
graphControlPanel.maxWidth = controlPanelMaxWidth;
// Parent for all control panels, to simplify layout
const controlsParent = new VBox( {
// set maxHeight to guard against font size differences across supported browsers
maxHeight: this.layoutBounds.height - ( 2 * GQConstants.SCREEN_VIEW_Y_MARGIN ),
align: 'center',
spacing: 10,
children: [
equationAccordionBox,
graphControlPanel
]
} );
// Horizontally center controls in the space to the right of the graph.
controlsParent.boundsProperty.link( () => {
controlsParent.centerX = graphNode.right + X_SPACING + ( controlPanelMaxWidth / 2 );
controlsParent.top = GQConstants.SCREEN_VIEW_Y_MARGIN;
} );
// Reset All Button
const resetAllButton = new ResetAllButton( {
listener: () => {
this.interruptSubtreeInput(); // interrupt all listeners for this screen
model.reset();
viewProperties.reset();
},
right: this.layoutBounds.maxX - GQConstants.SCREEN_VIEW_X_MARGIN,
bottom: this.layoutBounds.maxY - GQConstants.SCREEN_VIEW_Y_MARGIN,
tandem: tandem.createTandem( 'resetAllButton' ),
phetioDocumentation: 'button that resets the screen to its initial state'
} );
const screenViewRootNode = new Node( {
children: [
controlsParent,
graphContentsToggleButton,
graphNode,
pointToolsParent,
resetAllButton
]
} );
this.addChild( screenViewRootNode );
}
}
graphingQuadratics.register( 'GQScreenView', GQScreenView );