From c1391f5b13dfca5b917d75c354a75f171b1d2138 Mon Sep 17 00:00:00 2001 From: peterkogo Date: Tue, 30 Jan 2024 11:19:28 +0100 Subject: [PATCH] keepAspectRatio and children with parent=extent and expandParent restrict the resizing of the parent --- packages/system/src/xyresizer/utils.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/system/src/xyresizer/utils.ts b/packages/system/src/xyresizer/utils.ts index f284c4e7..db37d76c 100644 --- a/packages/system/src/xyresizer/utils.ts +++ b/packages/system/src/xyresizer/utils.ts @@ -187,7 +187,17 @@ export function getDimensionsAfterResize( clampX = Math.max(clampX, aspectExtentClamp); } - // TODO: Check if the child extent is restricting the resize + // Check if the child extent is restricting the resize + if (childExtent) { + let aspectExtentClamp = 0; + if ((!affectsX && !affectsY) || (affectsX && !affectsY && isDiagonal)) { + aspectExtentClamp = getLowerExtentClamp(startY + newWidth / aspectRatio, childExtent[1][1]) * aspectRatio; + } else { + aspectExtentClamp = + getUpperExtentClamp(startY + (affectsX ? distX : -distX) / aspectRatio, childExtent[0][1]) * aspectRatio; + } + clampX = Math.max(clampX, aspectExtentClamp); + } } // Do the same thing for vertical resizing @@ -206,7 +216,16 @@ export function getDimensionsAfterResize( clampY = Math.max(clampY, aspectExtentClamp); } - // TODO: Check if the child extent is restricting the resize + if (childExtent) { + let aspectExtentClamp = 0; + if ((!affectsX && !affectsY) || (affectsY && !affectsX && isDiagonal)) { + aspectExtentClamp = getLowerExtentClamp(startX + newHeight * aspectRatio, childExtent[1][0]) / aspectRatio; + } else { + aspectExtentClamp = + getUpperExtentClamp(startX + (affectsY ? distY : -distY) * aspectRatio, childExtent[0][0]) / aspectRatio; + } + clampY = Math.max(clampY, aspectExtentClamp); + } } }