Keep aspect ratio while resizing
This commit is contained in:
@@ -35,6 +35,7 @@ export default {
|
|||||||
:node-id="nodeId"
|
:node-id="nodeId"
|
||||||
:position="c"
|
:position="c"
|
||||||
:variant="ResizeControlVariant.Line"
|
:variant="ResizeControlVariant.Line"
|
||||||
|
:aspect-ratio="props.aspectRatio"
|
||||||
:color="color"
|
:color="color"
|
||||||
:min-width="minWidth"
|
:min-width="minWidth"
|
||||||
:min-height="minHeight"
|
:min-height="minHeight"
|
||||||
@@ -55,6 +56,7 @@ export default {
|
|||||||
:min-width="minWidth"
|
:min-width="minWidth"
|
||||||
:min-height="minHeight"
|
:min-height="minHeight"
|
||||||
:should-resize="shouldResize"
|
:should-resize="shouldResize"
|
||||||
|
:aspect-ratio="props.aspectRatio"
|
||||||
@resize-start="emits('resizeStart', $event)"
|
@resize-start="emits('resizeStart', $event)"
|
||||||
@resize="emits('resize', $event)"
|
@resize="emits('resize', $event)"
|
||||||
@resize-end="emits('resizeEnd', $event)"
|
@resize-end="emits('resizeEnd', $event)"
|
||||||
|
|||||||
@@ -93,8 +93,22 @@ watchEffect((onCleanup) => {
|
|||||||
const distX = Math.floor(enableX ? xSnapped - startX : 0)
|
const distX = Math.floor(enableX ? xSnapped - startX : 0)
|
||||||
const distY = Math.floor(enableY ? ySnapped - startY : 0)
|
const distY = Math.floor(enableY ? ySnapped - startY : 0)
|
||||||
|
|
||||||
const width = Math.max(startWidth + (invertX ? -distX : distX), props.minWidth)
|
let width = Math.max(startWidth + (invertX ? -distX : distX), props.minWidth)
|
||||||
const height = Math.max(startHeight + (invertY ? -distY : distY), props.minHeight)
|
let height = Math.max(startHeight + (invertY ? -distY : distY), props.minHeight)
|
||||||
|
|
||||||
|
if (props.aspectRatio) {
|
||||||
|
const currentAspectRatio = width / height
|
||||||
|
if (currentAspectRatio !== props.aspectRatio) {
|
||||||
|
const newWidth = height * props.aspectRatio
|
||||||
|
const newHeight = width / props.aspectRatio
|
||||||
|
|
||||||
|
if (newWidth > width) {
|
||||||
|
width = newWidth
|
||||||
|
} else {
|
||||||
|
height = newHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const isWidthChange = width !== prevWidth
|
const isWidthChange = width !== prevWidth
|
||||||
const isHeightChange = height !== prevHeight
|
const isHeightChange = height !== prevHeight
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ export interface NodeResizerProps {
|
|||||||
minWidth?: number
|
minWidth?: number
|
||||||
minHeight?: number
|
minHeight?: number
|
||||||
shouldResize?: ShouldResize
|
shouldResize?: ShouldResize
|
||||||
|
aspectRatio?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NodeResizerEmits {
|
export interface NodeResizerEmits {
|
||||||
@@ -67,6 +68,7 @@ export interface ResizeControlProps {
|
|||||||
position?: ControlPosition
|
position?: ControlPosition
|
||||||
variant?: ResizeControlVariant
|
variant?: ResizeControlVariant
|
||||||
shouldResize?: ShouldResize
|
shouldResize?: ShouldResize
|
||||||
|
aspectRatio? : number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResizeControlLineProps {
|
export interface ResizeControlLineProps {
|
||||||
@@ -76,4 +78,5 @@ export interface ResizeControlLineProps {
|
|||||||
minHeight?: number
|
minHeight?: number
|
||||||
variant?: ResizeControlVariant
|
variant?: ResizeControlVariant
|
||||||
position?: ControlLinePosition
|
position?: ControlLinePosition
|
||||||
|
aspectRatio?: number
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user