Skip to content

Commit 2f83882

Browse files
feat: drawer (#54)
* feat: drawer * Update src/App.tsx Co-authored-by: Justin Shetty <jas0504@gmail.com> * fix: layout --------- Co-authored-by: Justin Shetty <jas0504@gmail.com>
1 parent 5242ea3 commit 2f83882

2 files changed

Lines changed: 81 additions & 54 deletions

File tree

src/App.tsx

Lines changed: 76 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Box from '@mui/material/Box';
2-
import Grid from '@mui/material/Grid2';
2+
import Stack from '@mui/material/Stack';
3+
import Drawer from '@mui/material/Drawer';
4+
import IconButton from '@mui/material/IconButton';
5+
import MenuIcon from '@mui/icons-material/Menu';
36
import ConfigBar from './ConfigBar';
47
import Visualizer from './Visualizer';
58
import { Graph } from './Graph';
@@ -27,6 +30,7 @@ function App() {
2730
const [showCellId, setShowCellId] = React.useState<boolean>(false);
2831
const [showGoals, setShowGoals] = React.useState<boolean>(true);
2932
const [showGoalVectors, setShowGoalVectors] = React.useState<boolean>(false);
33+
const [drawerOpen, setDrawerOpen] = React.useState<boolean>(true);
3034

3135
const handleSkipBackward = () => {
3236
if (pixiAppRef.current?.skipBackward) {
@@ -60,54 +64,77 @@ function App() {
6064

6165
return (
6266
<StrictMode>
63-
<Box sx={{ flexGrow: 1 }}>
64-
<Grid container spacing={0}>
65-
<Grid size="grow">
66-
<Visualizer
67-
pixiAppRef = {pixiAppRef}
68-
graph={graph}
69-
solution={solution}
70-
playAnimation={playAnimation}
71-
stepSize={stepSize}
72-
loopAnimation={loopAnimation}
73-
showAgentId={showAgentId}
74-
tracePaths={tracePaths}
75-
setCanScreenshot={setCanScreenshot}
76-
showCellId={showCellId}
77-
showGoals={showGoals}
78-
showGoalVectors={showGoalVectors}
79-
/>
80-
</Grid>
81-
<Grid size={4}>
82-
<ConfigBar
83-
graph={graph}
84-
onGraphChange={useCallback((graph: Graph | null) => setGraph(graph), [])}
85-
onSolutionChange={useCallback((solution: Solution | null) => setSolution(solution), [])}
86-
playAnimation={playAnimation}
87-
onPlayAnimationChange={setPlayAnimation}
88-
onSkipBackward={handleSkipBackward}
89-
onSkipForward={handleSkipForward}
90-
onRestart={handleRestart}
91-
stepSize={stepSize}
92-
onStepSizeChange={setStepSize}
93-
loopAnimation={loopAnimation}
94-
onLoopAnimationChange={setLoopAnimation}
95-
onFitView={handleFitView}
96-
showAgentId={showAgentId}
97-
onShowAgentIdChange={setShowAgentId}
98-
tracePaths={tracePaths}
99-
onTracePathsChange={setTracePaths}
100-
canScreenshot={canScreenshot}
101-
takeScreenshot={handleTakeScreenshot}
102-
showCellId={showCellId}
103-
setShowCellId={setShowCellId}
104-
showGoals={showGoals}
105-
setShowGoals={setShowGoals}
106-
showGoalVectors={showGoalVectors}
107-
setShowGoalVectors={setShowGoalVectors}
108-
/>
109-
</Grid>
110-
</Grid>
67+
<Box sx={{ flexGrow: 1, position: 'relative' }}>
68+
<IconButton
69+
onClick={() => setDrawerOpen(true)}
70+
sx={{
71+
position: 'absolute',
72+
top: 16,
73+
right: 16,
74+
zIndex: 1000,
75+
backgroundColor: 'background.paper',
76+
'&:hover': {
77+
backgroundColor: 'action.hover',
78+
},
79+
}}
80+
>
81+
<MenuIcon />
82+
</IconButton>
83+
<Stack sx={{ height: '100vh' }}>
84+
<Visualizer
85+
pixiAppRef = {pixiAppRef}
86+
graph={graph}
87+
solution={solution}
88+
playAnimation={playAnimation}
89+
stepSize={stepSize}
90+
loopAnimation={loopAnimation}
91+
showAgentId={showAgentId}
92+
tracePaths={tracePaths}
93+
setCanScreenshot={setCanScreenshot}
94+
showCellId={showCellId}
95+
showGoals={showGoals}
96+
showGoalVectors={showGoalVectors}
97+
/>
98+
</Stack>
99+
<Drawer
100+
anchor="right"
101+
open={drawerOpen}
102+
onClose={() => setDrawerOpen(false)}
103+
keepMounted
104+
sx={{
105+
'& .MuiDrawer-paper': {
106+
width: 400,
107+
},
108+
}}
109+
>
110+
<ConfigBar
111+
graph={graph}
112+
onGraphChange={useCallback((graph: Graph | null) => setGraph(graph), [])}
113+
onSolutionChange={useCallback((solution: Solution | null) => setSolution(solution), [])}
114+
playAnimation={playAnimation}
115+
onPlayAnimationChange={setPlayAnimation}
116+
onSkipBackward={handleSkipBackward}
117+
onSkipForward={handleSkipForward}
118+
onRestart={handleRestart}
119+
stepSize={stepSize}
120+
onStepSizeChange={setStepSize}
121+
loopAnimation={loopAnimation}
122+
onLoopAnimationChange={setLoopAnimation}
123+
onFitView={handleFitView}
124+
showAgentId={showAgentId}
125+
onShowAgentIdChange={setShowAgentId}
126+
tracePaths={tracePaths}
127+
onTracePathsChange={setTracePaths}
128+
canScreenshot={canScreenshot}
129+
takeScreenshot={handleTakeScreenshot}
130+
showCellId={showCellId}
131+
setShowCellId={setShowCellId}
132+
showGoals={showGoals}
133+
setShowGoals={setShowGoals}
134+
showGoalVectors={showGoalVectors}
135+
setShowGoalVectors={setShowGoalVectors}
136+
/>
137+
</Drawer>
111138
</Box>
112139
</StrictMode>
113140
);

src/PixiApp.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ const PixiApp = forwardRef(({
391391

392392
hudRef.current.addChild(
393393
new PIXI.Text({
394-
x: width - width / 100,
395-
y: height / 100,
396-
anchor: new PIXI.Point(1, 0),
394+
x: width / 100,
395+
y: height - height / 100,
396+
anchor: new PIXI.Point(0, 1),
397397
text: "Click and drag to pan. Scroll to zoom.",
398398
style: textStyle,
399399
})
@@ -449,8 +449,8 @@ const PixiApp = forwardRef(({
449449
if (hudRef.current) {
450450
hudRef.current.children[0].x = width / 100;
451451
hudRef.current.children[0].y = height / 100;
452-
hudRef.current.children[1].x = width - width / 100;
453-
hudRef.current.children[1].y = height / 100;
452+
hudRef.current.children[1].x = width / 100;
453+
hudRef.current.children[1].y = height - height / 100;
454454
}
455455
fit();
456456
}

0 commit comments

Comments
 (0)