Apply common sense constraints to window drag and resize (#309)
* Apply common sense constraints to window drag and resize * Also apply the constraints to FocusRangeZone's panelMoveGestureHandlers
This commit is contained in:
parent
3ec8c20fa6
commit
25cf1d7fe8
4 changed files with 41 additions and 8 deletions
|
@ -7,6 +7,8 @@ import React, {useMemo, useRef} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import {panelDimsToPanelPosition, usePanel} from './BasePanel'
|
import {panelDimsToPanelPosition, usePanel} from './BasePanel'
|
||||||
import {useCssCursorLock} from '@theatre/studio/uiComponents/PointerEventsHandler'
|
import {useCssCursorLock} from '@theatre/studio/uiComponents/PointerEventsHandler'
|
||||||
|
import {clamp} from 'lodash-es'
|
||||||
|
import {visibleSize} from './common'
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
cursor: move;
|
cursor: move;
|
||||||
|
@ -35,8 +37,16 @@ const PanelDragZone: React.FC<
|
||||||
onDrag(dx, dy) {
|
onDrag(dx, dy) {
|
||||||
const newDims: typeof panelStuff['dims'] = {
|
const newDims: typeof panelStuff['dims'] = {
|
||||||
...stuffBeforeDrag.dims,
|
...stuffBeforeDrag.dims,
|
||||||
top: stuffBeforeDrag.dims.top + dy,
|
top: clamp(
|
||||||
left: stuffBeforeDrag.dims.left + dx,
|
stuffBeforeDrag.dims.top + dy,
|
||||||
|
0,
|
||||||
|
window.innerHeight - visibleSize,
|
||||||
|
),
|
||||||
|
left: clamp(
|
||||||
|
stuffBeforeDrag.dims.left + dx,
|
||||||
|
-stuffBeforeDrag.dims.width + visibleSize,
|
||||||
|
window.innerWidth - visibleSize,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
const position = panelDimsToPanelPosition(newDims, {
|
const position = panelDimsToPanelPosition(newDims, {
|
||||||
width: window.innerWidth,
|
width: window.innerWidth,
|
||||||
|
|
|
@ -8,6 +8,8 @@ import React, {useMemo, useRef} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import {panelDimsToPanelPosition, usePanel} from './BasePanel'
|
import {panelDimsToPanelPosition, usePanel} from './BasePanel'
|
||||||
import {pointerEventsAutoInNormalMode} from '@theatre/studio/css'
|
import {pointerEventsAutoInNormalMode} from '@theatre/studio/css'
|
||||||
|
import {clamp} from 'lodash-es'
|
||||||
|
import {visibleSize} from './common'
|
||||||
|
|
||||||
const Base = styled.div`
|
const Base = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -167,9 +169,13 @@ const PanelResizeHandle: React.FC<{
|
||||||
)
|
)
|
||||||
} else if (which.startsWith('Top')) {
|
} else if (which.startsWith('Top')) {
|
||||||
const bottom = newDims.top + newDims.height
|
const bottom = newDims.top + newDims.height
|
||||||
const top = Math.min(
|
const top = clamp(
|
||||||
bottom - stuffBeforeDrag.minDims.height,
|
|
||||||
newDims.top + dy,
|
newDims.top + dy,
|
||||||
|
0,
|
||||||
|
Math.min(
|
||||||
|
bottom - stuffBeforeDrag.minDims.height,
|
||||||
|
window.innerHeight - visibleSize,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
const height = bottom - top
|
const height = bottom - top
|
||||||
|
|
||||||
|
@ -179,8 +185,11 @@ const PanelResizeHandle: React.FC<{
|
||||||
if (which.endsWith('Left')) {
|
if (which.endsWith('Left')) {
|
||||||
const right = newDims.left + newDims.width
|
const right = newDims.left + newDims.width
|
||||||
const left = Math.min(
|
const left = Math.min(
|
||||||
right - stuffBeforeDrag.minDims.width,
|
|
||||||
newDims.left + dx,
|
newDims.left + dx,
|
||||||
|
Math.min(
|
||||||
|
right - stuffBeforeDrag.minDims.width,
|
||||||
|
window.innerWidth - visibleSize,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
const width = right - left
|
const width = right - left
|
||||||
|
|
||||||
|
@ -189,7 +198,10 @@ const PanelResizeHandle: React.FC<{
|
||||||
} else if (which.endsWith('Right')) {
|
} else if (which.endsWith('Right')) {
|
||||||
newDims.width = Math.max(
|
newDims.width = Math.max(
|
||||||
newDims.width + dx,
|
newDims.width + dx,
|
||||||
stuffBeforeDrag.minDims.width,
|
Math.max(
|
||||||
|
stuffBeforeDrag.minDims.width,
|
||||||
|
visibleSize - stuffBeforeDrag.dims.left,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,3 +59,5 @@ export const TitleBar = styled.div`
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
export const visibleSize = 100
|
||||||
|
|
|
@ -20,6 +20,7 @@ import React, {useEffect, useMemo, useRef, useState} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import FocusRangeStrip, {focusRangeStripTheme} from './FocusRangeStrip'
|
import FocusRangeStrip, {focusRangeStripTheme} from './FocusRangeStrip'
|
||||||
import FocusRangeThumb from './FocusRangeThumb'
|
import FocusRangeThumb from './FocusRangeThumb'
|
||||||
|
import {visibleSize} from '@theatre/studio/panels/BasePanel/common'
|
||||||
|
|
||||||
const Container = styled.div<{isShiftDown: boolean}>`
|
const Container = styled.div<{isShiftDown: boolean}>`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -186,8 +187,16 @@ function usePanelDragZoneGestureHandlers(
|
||||||
onDrag(dx, dy) {
|
onDrag(dx, dy) {
|
||||||
const newDims: typeof panelStuffRef.current['dims'] = {
|
const newDims: typeof panelStuffRef.current['dims'] = {
|
||||||
...stuffBeforeDrag.dims,
|
...stuffBeforeDrag.dims,
|
||||||
top: stuffBeforeDrag.dims.top + dy,
|
top: clamp(
|
||||||
left: stuffBeforeDrag.dims.left + dx,
|
stuffBeforeDrag.dims.top + dy,
|
||||||
|
0,
|
||||||
|
window.innerHeight - visibleSize,
|
||||||
|
),
|
||||||
|
left: clamp(
|
||||||
|
stuffBeforeDrag.dims.left + dx,
|
||||||
|
-stuffBeforeDrag.dims.width + visibleSize,
|
||||||
|
window.innerWidth - visibleSize,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
const position = panelDimsToPanelPosition(newDims, {
|
const position = panelDimsToPanelPosition(newDims, {
|
||||||
width: window.innerWidth,
|
width: window.innerWidth,
|
||||||
|
|
Loading…
Reference in a new issue