From d1ef903355420c4518699424c022d8b895b8241f Mon Sep 17 00:00:00 2001 From: Andrew Prifer <2991360+AndrewPrifer@users.noreply.github.com> Date: Wed, 29 Jun 2022 17:06:24 +0200 Subject: [PATCH] Enable hiding the reference window (#241) --- .../ReferenceWindow/ReferenceWindow.tsx | 33 ++++++++----------- .../extension/components/SnapshotEditor.tsx | 30 +++++++++++++---- packages/r3f/src/extension/editorStuff.ts | 12 +++++-- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/packages/r3f/src/extension/components/ReferenceWindow/ReferenceWindow.tsx b/packages/r3f/src/extension/components/ReferenceWindow/ReferenceWindow.tsx index 799b296..52e65d7 100644 --- a/packages/r3f/src/extension/components/ReferenceWindow/ReferenceWindow.tsx +++ b/packages/r3f/src/extension/components/ReferenceWindow/ReferenceWindow.tsx @@ -8,11 +8,8 @@ import styled, {keyframes} from 'styled-components' import {TiWarningOutline} from 'react-icons/ti' import noiseImageUrl from './noise-transparent.png' import useExtensionStore from '../../useExtensionStore' -import {useVal} from '@theatre/react' -import {getEditorSheetObject} from '../../editorStuff' -import studio from '@theatre/studio' -const Container = styled.div<{minified: boolean}>` +const Container = styled.div<{minimized: boolean}>` position: relative; display: flex; justify-content: center; @@ -20,7 +17,7 @@ const Container = styled.div<{minified: boolean}>` pointer-events: auto; cursor: pointer; overflow: hidden; - border-radius: ${({minified}) => (minified ? '2px' : '4px')}; + border-radius: ${({minimized}) => (minimized ? '2px' : '4px')}; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.15); ` @@ -76,14 +73,18 @@ const Warning = styled.div` interface ReferenceWindowProps { maxHeight: number maxWidth: number + minimized: boolean + onToggleMinified: () => void } -const ReferenceWindow: VFC = ({maxHeight, maxWidth}) => { +const ReferenceWindow: VFC = ({ + maxHeight, + maxWidth, + minimized, + onToggleMinified, +}) => { const canvasRef = useRef(null) - const minified = - useVal(getEditorSheetObject()?.props.viewport.showReferenceWindow) ?? true - const [gl] = useExtensionStore((state) => [state.gl], shallow) const [ref, {width: origWidth, height: origHeight}] = useMeasure() @@ -136,19 +137,13 @@ const ReferenceWindow: VFC = ({maxHeight, maxWidth}) => { } }, [gl, width, height, preserveDrawingBuffer]) - const toggleVisibility = () => { - studio.transaction(({set}) => { - set(getEditorSheetObject()!.props.viewport.showReferenceWindow, !minified) - }) - } - return ( {preserveDrawingBuffer ? ( diff --git a/packages/r3f/src/extension/components/SnapshotEditor.tsx b/packages/r3f/src/extension/components/SnapshotEditor.tsx index 5a2076d..8d98067 100644 --- a/packages/r3f/src/extension/components/SnapshotEditor.tsx +++ b/packages/r3f/src/extension/components/SnapshotEditor.tsx @@ -184,6 +184,10 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => { if (!editorObject) return <> + const referenceWindowVisibility = + useVal(getEditorSheetObject()?.props.viewport.referenceWindow) ?? + 'minimized' + return ( @@ -192,12 +196,26 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => { - - - + {referenceWindowVisibility !== 'hidden' && ( + + { + studio.transaction(({set}) => { + set( + getEditorSheetObject()!.props.viewport + .referenceWindow, + referenceWindowVisibility === 'minimized' + ? 'maximized' + : 'minimized', + ) + }) + }} + /> + + )} {!sceneSnapshot && ( The scene hasn't been initialized yet. It will appear in the diff --git a/packages/r3f/src/extension/editorStuff.ts b/packages/r3f/src/extension/editorStuff.ts index d235598..6a76902 100644 --- a/packages/r3f/src/extension/editorStuff.ts +++ b/packages/r3f/src/extension/editorStuff.ts @@ -22,9 +22,15 @@ const editorSheetObjectConfig = { }, {as: 'menu', label: 'Shading'}, ), - showReferenceWindow: types.boolean(true, { - label: 'Reference', - }), + referenceWindow: types.stringLiteral( + 'minimized', + { + maximized: 'Maximized', + minimized: 'Minimized', + hidden: 'Hidden', + }, + {as: 'menu', label: 'Reference Window'}, + ), lighting: types.stringLiteral( 'physical', {