Indicate length of the sequence

This commit is contained in:
Aria Minaei 2021-07-31 16:28:51 +02:00
parent 2daa270879
commit acf0283449
3 changed files with 82 additions and 27 deletions

View file

@ -5,19 +5,59 @@ import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import type {SequenceEditorPanelLayout} from '@theatre/studio/panels/SequenceEditorPanel/layout/layout' import type {SequenceEditorPanelLayout} from '@theatre/studio/panels/SequenceEditorPanel/layout/layout'
import {zIndexes} from '@theatre/studio/panels/SequenceEditorPanel/SequenceEditorPanel' import {zIndexes} from '@theatre/studio/panels/SequenceEditorPanel/SequenceEditorPanel'
import {topStripHeight} from '@theatre/studio/panels/SequenceEditorPanel/RightOverlay/TopStrip'
const divWidth = 1000 const coverWidth = 1000
const Container = styled.div` const Cover = styled.div`
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
background: rgb(23 23 23 / 43%); background-color: rgb(23 23 23 / 43%);
width: ${divWidth}px; width: ${coverWidth}px;
z-index: ${() => zIndexes.lengthIndicator}; z-index: ${() => zIndexes.lengthIndicatorCover};
transform-origin: left top; transform-origin: left top;
` `
const Strip = styled.div`
position: absolute;
top: 0;
left: 0;
width: 4px;
z-index: ${() => zIndexes.lengthIndicatorStrip};
pointer-events: auto;
cursor: pointer;
&:after {
display: block;
content: ' ';
position: absolute;
top: ${topStripHeight}px;
bottom: 0;
left: -1px;
width: 1px;
background-color: #000000a6;
}
&:hover:after {
background-color: #000000;
}
`
const Info = styled.div`
position: absolute;
top: ${topStripHeight + 4}px;
font-size: 10px;
left: 4px;
color: gray;
white-space: nowrap;
display: none;
${Strip}:hover & {
display: block;
}
`
const LengthIndicator: React.FC<{ const LengthIndicator: React.FC<{
layoutP: Pointer<SequenceEditorPanelLayout> layoutP: Pointer<SequenceEditorPanelLayout>
}> = ({layoutP}) => { }> = ({layoutP}) => {
@ -25,7 +65,8 @@ const LengthIndicator: React.FC<{
const sheet = val(layoutP.sheet) const sheet = val(layoutP.sheet)
const height = val(layoutP.rightDims.height) const height = val(layoutP.rightDims.height)
const startInUnitSpace = sheet.getSequence().length const sequenceLength = sheet.getSequence().length
const startInUnitSpace = sequenceLength
let startX = val(layoutP.clippedSpace.fromUnitSpace)(startInUnitSpace) let startX = val(layoutP.clippedSpace.fromUnitSpace)(startInUnitSpace)
let endX = val(layoutP.clippedSpace.width) let endX = val(layoutP.clippedSpace.width)
@ -38,24 +79,36 @@ const LengthIndicator: React.FC<{
startX = 0 startX = 0
} }
translateX = startX translateX = startX
scaleX = (endX - startX) / divWidth scaleX = (endX - startX) / coverWidth
} }
return ( return (
<Container <>
// onClick={() => { <Strip
// getStudio()!.transaction(({stateEditors}) => { title="Change Sequence Length"
// stateEditors.coreByProject.historic.sheetsById.sequence.setLength({ style={{
// ...sheet.address, height: height + 'px',
// length: 10, transform: `translateX(${translateX === 0 ? -1000 : translateX}px)`,
// }) }}
// }) >
// }} <Info>Sequence Length: {sequenceLength}</Info>
style={{ </Strip>
height: height + 'px', <Cover
transform: `translateX(${translateX}px) scale(${scaleX}, 1)`, title="Length"
}} // onClick={() => {
></Container> // getStudio()!.transaction(({stateEditors}) => {
// stateEditors.coreByProject.historic.sheetsById.sequence.setLength({
// ...sheet.address,
// length: 10,
// })
// })
// }}
style={{
height: height + 'px',
transform: `translateX(${translateX}px) scale(${scaleX}, 1)`,
}}
/>
</>
) )
}, [layoutP]) }, [layoutP])
} }

View file

@ -6,7 +6,7 @@ import type {SequenceEditorPanelLayout} from '@theatre/studio/panels/SequenceEdi
import StampsGrid from '@theatre/studio/panels/SequenceEditorPanel/FrameGrid/StampsGrid' import StampsGrid from '@theatre/studio/panels/SequenceEditorPanel/FrameGrid/StampsGrid'
import PanelDragZone from '@theatre/studio/panels/BasePanel/PanelDragZone' import PanelDragZone from '@theatre/studio/panels/BasePanel/PanelDragZone'
const height = 20 export const topStripHeight = 20
export const topStripTheme = { export const topStripTheme = {
backgroundColor: `#1f2120eb`, backgroundColor: `#1f2120eb`,
@ -18,7 +18,7 @@ const Container = styled(PanelDragZone)`
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
height: ${height}px; height: ${topStripHeight}px;
box-sizing: border-box; box-sizing: border-box;
background: ${topStripTheme.backgroundColor}; background: ${topStripTheme.backgroundColor};
border-bottom: 1px solid ${topStripTheme.borderColor}; border-bottom: 1px solid ${topStripTheme.borderColor};
@ -31,7 +31,7 @@ const TopStrip: React.FC<{layoutP: Pointer<SequenceEditorPanelLayout>}> = ({
const width = useVal(layoutP.rightDims.width) const width = useVal(layoutP.rightDims.width)
return ( return (
<Container> <Container>
<StampsGrid layoutP={layoutP} width={width} height={height} /> <StampsGrid layoutP={layoutP} width={width} height={topStripHeight} />
</Container> </Container>
) )
} }

View file

@ -49,8 +49,9 @@ export const zIndexes = (() => {
const rightBackground = scrollableArea - 1 const rightBackground = scrollableArea - 1
const seeker = rightOverlay + 1 const seeker = rightOverlay + 1
const currentFrameStamp = seeker + 1 const currentFrameStamp = seeker + 1
const lengthIndicator = currentFrameStamp + 1 const lengthIndicatorCover = currentFrameStamp + 1
const horizontalScrollbar = lengthIndicator + 1 const lengthIndicatorStrip = lengthIndicatorCover + 1
const horizontalScrollbar = lengthIndicatorStrip + 1
return { return {
scrollableArea, scrollableArea,
@ -59,7 +60,8 @@ export const zIndexes = (() => {
seeker, seeker,
horizontalScrollbar, horizontalScrollbar,
currentFrameStamp, currentFrameStamp,
lengthIndicator, lengthIndicatorCover,
lengthIndicatorStrip,
} }
})() })()