diff --git a/src/Components/Editor/Behaviors/Behaviors.ts b/src/Components/Editor/Behaviors/Behaviors.ts index 63018b4..2d96508 100644 --- a/src/Components/Editor/Behaviors/Behaviors.ts +++ b/src/Components/Editor/Behaviors/Behaviors.ts @@ -1,4 +1,5 @@ import { IContainerModel } from '../../../Interfaces/IContainerModel'; +import { APPLY_BEHAVIORS_ON_CHILDREN } from '../../../utils/default'; import { ImposePosition } from './AnchorBehaviors'; import { RecalculatePhysics } from './RigidBodyBehaviors'; @@ -17,5 +18,12 @@ export function ApplyBehaviors(container: IContainerModel): IContainerModel { RecalculatePhysics(container); } + if (APPLY_BEHAVIORS_ON_CHILDREN) { + // Apply DFS by recursion + for (const child of container.children) { + ApplyBehaviors(child); + } + } + return container; } diff --git a/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts b/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts index f0a734c..1ba10a0 100644 --- a/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts +++ b/src/Components/Editor/Behaviors/RigidBodyBehaviors.ts @@ -231,14 +231,15 @@ function getAvailableWidths( const width = container.properties.width; let unallocatedSpaces: ISizePointer[] = [{ x, width }]; - // We will only uses containers that also are rigid or are anchors - const solidBodies = container.children.filter( - (child) => child.properties.isRigidBody || child.properties.isAnchor - ); + for (const child of container.children) { + if (unallocatedSpaces.length < 1) { + return unallocatedSpaces; + } - for (const child of solidBodies) { // Ignore the exception - if (child === exception) { + // And we will also only uses containers that also are rigid or are anchors + if (child === exception || + (!child.properties.isRigidBody && !child.properties.isAnchor)) { continue; } const childX = child.properties.x; diff --git a/src/utils/default.ts b/src/utils/default.ts index bc3cbc7..e2778be 100644 --- a/src/utils/default.ts +++ b/src/utils/default.ts @@ -4,7 +4,7 @@ import { IConfiguration } from '../Interfaces/IConfiguration'; import { IContainerModel } from '../Interfaces/IContainerModel'; import IProperties from '../Interfaces/IProperties'; -/// CONTAINRE DEFAULTS /// +/// CONTAINER DEFAULTS /// export const SHOW_TEXT = true; export const DEFAULTCHILDTYPE_ALLOW_CYCLIC = false; @@ -22,6 +22,7 @@ export const NOTCHES_LENGTH = 4; export const ENABLE_SHORTCUTS = true; export const MAX_HISTORY = 200; +export const APPLY_BEHAVIORS_ON_CHILDREN = true; export const DEFAULT_CONFIG: IConfiguration = { AvailableContainers: [