From 4bf4f01dc2615cd4509c82a40deddd9af49807c3 Mon Sep 17 00:00:00 2001 From: Eric NGUYEN Date: Wed, 17 Aug 2022 16:52:36 +0200 Subject: [PATCH] Implemented logic for minWidth and rigidBody --- .../Editor/Behaviors/RigidBodyBehaviors.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts b/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts index e96da4a..eab0970 100644 --- a/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts +++ b/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts @@ -152,7 +152,7 @@ export function constraintBodyInsideUnallocatedWidth( // Check if the container actually fit inside // It will usually fit if it was alrady fitting const availableWidthFound = availableWidths.find((width) => - isFitting(container, width) + isFitting(container.properties.width, width) ); if (availableWidthFound === undefined) { @@ -163,12 +163,21 @@ export function constraintBodyInsideUnallocatedWidth( // We want the container to fit automatically inside the available space // even if it means to resize the container - // The end goal is that the code never show the error message no matter what action is done - // TODO: Actually give an option to not fit and show the error message shown below - const availableWidth = availableWidths[0]; + const availableWidth: ISizePointer | undefined = availableWidths.find((width) => { + if (container.properties.minWidth === undefined) { + return true; + } + return isFitting(container.properties.minWidth, width); + }); + + if (availableWidth === undefined) { + console.warn(`Container ${container.properties.id} cannot fit in any space due to its minimum width being to large. Consequently, its rigid body property is disabled.`); + container.properties.isRigidBody = false; + return container; + } + container.properties.x = availableWidth.x; container.properties.width = availableWidth.width; - // throw new Error('[constraintBodyInsideUnallocatedWidth] BIGERR: No available space found on the parent container, even though there is some.'); return container; } @@ -188,9 +197,9 @@ export function constraintBodyInsideUnallocatedWidth( * @returns */ const isFitting = ( - container: IContainerModel, + containerWidth: number, sizePointer: ISizePointer -): boolean => container.properties.width <= sizePointer.width; +): boolean => containerWidth <= sizePointer.width; /** * Get the unallocated widths inside a container