Skip to content

Commit 70a9d3c

Browse files
committed
Fix constraining overflow issue with freeform resizing.
1 parent d19b634 commit 70a9d3c

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

packages/box_transform/lib/src/transformer.dart

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ class BoxTransformer {
345345
required Box initialRect,
346346
required Flip flip,
347347
}) {
348+
final flippedHandle = handle.flip(flip);
348349
Box effectiveInitialRect = flipBox(initialRect, flip, handle);
349350

350351
Box newRect = Box.fromLTRB(
@@ -362,8 +363,8 @@ class BoxTransformer {
362363
newRect.height.clamp(constraints.minHeight, constraints.maxHeight);
363364

364365
newRect = Box.fromHandle(
365-
handle.flip(flip).anchor(effectiveInitialRect),
366-
handle.flip(flip),
366+
flippedHandle.anchor(effectiveInitialRect),
367+
flippedHandle,
367368
constrainedWidth,
368369
constrainedHeight,
369370
);
@@ -373,16 +374,23 @@ class BoxTransformer {
373374
newRect = Box.fromHandle(
374375
handle.anchor(initialRect),
375376
handle,
376-
constrainedWidth,
377-
constrainedHeight,
377+
constraints.minWidth,
378+
constraints.minHeight,
378379
);
379380
}
380381
}
381382

383+
// not used but calculating it for returning correct largest box.
384+
Box area = getAvailableAreaForHandle(
385+
rect: isValid ? effectiveInitialRect : initialRect,
386+
handle: isValid ? flippedHandle : handle,
387+
clampingRect: clampingRect,
388+
);
389+
382390
return InternalResizeResult(
383391
rect: newRect,
384-
largest: effectiveInitialRect,
385-
hasInvalidFlip: isValid,
392+
largest: area,
393+
hasValidFlip: isValid,
386394
);
387395
}
388396

@@ -454,7 +462,7 @@ class BoxTransformer {
454462
final isValid = isValidBox(rect, constraints, clampingRect);
455463

456464
return InternalResizeResult(
457-
rect: rect, largest: largest, hasInvalidFlip: isValid);
465+
rect: rect, largest: largest, hasValidFlip: isValid);
458466
}
459467

460468
/// Handle resizing for the right handle.
@@ -531,7 +539,7 @@ class BoxTransformer {
531539
final isValid = isValidBox(rect, constraints, clampingRect);
532540

533541
return InternalResizeResult(
534-
rect: rect, largest: largest, hasInvalidFlip: isValid);
542+
rect: rect, largest: largest, hasValidFlip: isValid);
535543
}
536544

537545
/// handle resizing for the left handle
@@ -608,7 +616,7 @@ class BoxTransformer {
608616
final isValid = isValidBox(rect, constraints, clampingRect);
609617

610618
return InternalResizeResult(
611-
rect: rect, largest: largest, hasInvalidFlip: isValid);
619+
rect: rect, largest: largest, hasValidFlip: isValid);
612620
}
613621

614622
/// handle resizing for the bottom handle.
@@ -685,7 +693,7 @@ class BoxTransformer {
685693
final isValid = isValidBox(rect, constraints, clampingRect);
686694

687695
return InternalResizeResult(
688-
rect: rect, largest: largest, hasInvalidFlip: isValid);
696+
rect: rect, largest: largest, hasValidFlip: isValid);
689697
}
690698

691699
/// handle resizing for the top handle.
@@ -762,7 +770,7 @@ class BoxTransformer {
762770
final isValid = isValidBox(rect, constraints, clampingRect);
763771

764772
return InternalResizeResult(
765-
rect: rect, largest: largest, hasInvalidFlip: isValid);
773+
rect: rect, largest: largest, hasValidFlip: isValid);
766774
}
767775

768776
/// Handles the symmetric resize mode for corner handles.
@@ -993,7 +1001,7 @@ class BoxTransformer {
9931001
final isValid = isValidBox(rect, constraints, clampingRect);
9941002

9951003
return InternalResizeResult(
996-
rect: rect, largest: largest, hasInvalidFlip: isValid);
1004+
rect: rect, largest: largest, hasValidFlip: isValid);
9971005
}
9981006

9991007
/// Handle resizing for [HandlePosition.bottomLeft] handle
@@ -1064,7 +1072,7 @@ class BoxTransformer {
10641072
final isValid = isValidBox(rect, constraints, clampingRect);
10651073

10661074
return InternalResizeResult(
1067-
rect: rect, largest: largest, hasInvalidFlip: isValid);
1075+
rect: rect, largest: largest, hasValidFlip: isValid);
10681076
}
10691077

10701078
/// Handle resizing for [HandlePosition.topRight] handle
@@ -1135,7 +1143,7 @@ class BoxTransformer {
11351143
final isValid = isValidBox(rect, constraints, clampingRect);
11361144

11371145
return InternalResizeResult(
1138-
rect: rect, largest: largest, hasInvalidFlip: isValid);
1146+
rect: rect, largest: largest, hasValidFlip: isValid);
11391147
}
11401148

11411149
/// Handle resizing for [ResizeMode.symmetric].
@@ -1237,7 +1245,7 @@ class BoxTransformer {
12371245
break;
12381246
}
12391247

1240-
if (!result.hasInvalidFlip) {
1248+
if (!result.hasValidFlip) {
12411249
// Since we can't flip the box, rect (which is a raw rect with delta applied)
12421250
// would be flipped so we can't use that because it would make the size
12431251
// calculations wrong. Instead we use box from the result which is the
@@ -1294,13 +1302,13 @@ class InternalResizeResult {
12941302
final Box largest;
12951303

12961304
/// Whether the resulting rect is valid and adheres to the constraints.
1297-
final bool hasInvalidFlip;
1305+
final bool hasValidFlip;
12981306

12991307
/// The result of a resize operation.
13001308
InternalResizeResult({
13011309
required this.rect,
13021310
required this.largest,
1303-
this.hasInvalidFlip = true,
1311+
this.hasValidFlip = true,
13041312
});
13051313

13061314
@override
@@ -1310,13 +1318,13 @@ class InternalResizeResult {
13101318
runtimeType == other.runtimeType &&
13111319
rect == other.rect &&
13121320
largest == other.largest &&
1313-
hasInvalidFlip == other.hasInvalidFlip;
1321+
hasValidFlip == other.hasValidFlip;
13141322

13151323
@override
1316-
int get hashCode => Object.hash(rect, largest, hasInvalidFlip);
1324+
int get hashCode => Object.hash(rect, largest, hasValidFlip);
13171325

13181326
@override
13191327
String toString() {
1320-
return 'InternalResizeResult(rect: $rect, largest: $largest, isValid: $hasInvalidFlip)';
1328+
return 'InternalResizeResult(rect: $rect, largest: $largest, isValid: $hasValidFlip)';
13211329
}
13221330
}

0 commit comments

Comments
 (0)