Enable hiding the reference window (#241)

This commit is contained in:
Andrew Prifer 2022-06-29 17:06:24 +02:00 committed by GitHub
parent 2b8a1e3ed1
commit d1ef903355
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 28 deletions

View file

@ -8,11 +8,8 @@ import styled, {keyframes} from 'styled-components'
import {TiWarningOutline} from 'react-icons/ti' import {TiWarningOutline} from 'react-icons/ti'
import noiseImageUrl from './noise-transparent.png' import noiseImageUrl from './noise-transparent.png'
import useExtensionStore from '../../useExtensionStore' 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; position: relative;
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -20,7 +17,7 @@ const Container = styled.div<{minified: boolean}>`
pointer-events: auto; pointer-events: auto;
cursor: pointer; cursor: pointer;
overflow: hidden; 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); 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 { interface ReferenceWindowProps {
maxHeight: number maxHeight: number
maxWidth: number maxWidth: number
minimized: boolean
onToggleMinified: () => void
} }
const ReferenceWindow: VFC<ReferenceWindowProps> = ({maxHeight, maxWidth}) => { const ReferenceWindow: VFC<ReferenceWindowProps> = ({
maxHeight,
maxWidth,
minimized,
onToggleMinified,
}) => {
const canvasRef = useRef<HTMLCanvasElement>(null) const canvasRef = useRef<HTMLCanvasElement>(null)
const minified =
useVal(getEditorSheetObject()?.props.viewport.showReferenceWindow) ?? true
const [gl] = useExtensionStore((state) => [state.gl], shallow) const [gl] = useExtensionStore((state) => [state.gl], shallow)
const [ref, {width: origWidth, height: origHeight}] = useMeasure() const [ref, {width: origWidth, height: origHeight}] = useMeasure()
@ -136,19 +137,13 @@ const ReferenceWindow: VFC<ReferenceWindowProps> = ({maxHeight, maxWidth}) => {
} }
}, [gl, width, height, preserveDrawingBuffer]) }, [gl, width, height, preserveDrawingBuffer])
const toggleVisibility = () => {
studio.transaction(({set}) => {
set(getEditorSheetObject()!.props.viewport.showReferenceWindow, !minified)
})
}
return ( return (
<Container <Container
minified={!minified} minimized={minimized}
onClick={toggleVisibility} onClick={onToggleMinified}
style={{ style={{
width: !minified ? 32 : preserveDrawingBuffer ? `${width}px` : 'auto', width: minimized ? 32 : preserveDrawingBuffer ? `${width}px` : 'auto',
height: !minified ? 32 : preserveDrawingBuffer ? `${height}px` : 'auto', height: minimized ? 32 : preserveDrawingBuffer ? `${height}px` : 'auto',
}} }}
> >
{preserveDrawingBuffer ? ( {preserveDrawingBuffer ? (

View file

@ -184,6 +184,10 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
if (!editorObject) return <></> if (!editorObject) return <></>
const referenceWindowVisibility =
useVal(getEditorSheetObject()?.props.viewport.referenceWindow) ??
'minimized'
return ( return (
<root.div style={{overflow: 'hidden'}}> <root.div style={{overflow: 'hidden'}}>
<StyleSheetManager disableVendorPrefixes> <StyleSheetManager disableVendorPrefixes>
@ -192,12 +196,26 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
<Wrapper> <Wrapper>
<Overlay> <Overlay>
<Tools ref={setToolsContainer} /> <Tools ref={setToolsContainer} />
<ReferenceWindowContainer> {referenceWindowVisibility !== 'hidden' && (
<ReferenceWindow <ReferenceWindowContainer>
maxHeight={Math.min(bounds.height * 0.3, 150)} <ReferenceWindow
maxWidth={Math.min(bounds.width * 0.3, 250)} maxHeight={Math.min(bounds.height * 0.3, 150)}
/> maxWidth={Math.min(bounds.width * 0.3, 250)}
</ReferenceWindowContainer> minimized={referenceWindowVisibility === 'minimized'}
onToggleMinified={() => {
studio.transaction(({set}) => {
set(
getEditorSheetObject()!.props.viewport
.referenceWindow,
referenceWindowVisibility === 'minimized'
? 'maximized'
: 'minimized',
)
})
}}
/>
</ReferenceWindowContainer>
)}
{!sceneSnapshot && ( {!sceneSnapshot && (
<WaitForSceneInitMessage> <WaitForSceneInitMessage>
The scene hasn't been initialized yet. It will appear in the The scene hasn't been initialized yet. It will appear in the

View file

@ -22,9 +22,15 @@ const editorSheetObjectConfig = {
}, },
{as: 'menu', label: 'Shading'}, {as: 'menu', label: 'Shading'},
), ),
showReferenceWindow: types.boolean(true, { referenceWindow: types.stringLiteral(
label: 'Reference', 'minimized',
}), {
maximized: 'Maximized',
minimized: 'Minimized',
hidden: 'Hidden',
},
{as: 'menu', label: 'Reference Window'},
),
lighting: types.stringLiteral( lighting: types.stringLiteral(
'physical', 'physical',
{ {