Skip to content

Commit 78ce247

Browse files
committed
Fix side handles not resizing with scalable resize mode.
1 parent 7ec71ad commit 78ce247

File tree

1 file changed

+68
-12
lines changed

1 file changed

+68
-12
lines changed

packages/box_transform/lib/src/transformer.dart

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,34 @@ class BoxTransformer {
118118
height: newHeight,
119119
);
120120
} else {
121-
Box rect = Box.fromLTWH(
122-
handle.influencesLeft ? initialBox.right - newWidth : initialBox.left,
123-
handle.influencesTop ? initialBox.bottom - newHeight : initialBox.top,
124-
newWidth,
125-
newHeight,
126-
);
121+
double left;
122+
double top;
123+
124+
/// If the handle is a side handle and its a scalable resizing, then
125+
/// the resizing should be w.r.t. the opposite side of the handle.
126+
/// This is needs to be handled separately because the anchor point in
127+
/// this case is the center of the handle on the opposite side.
128+
if (resizeMode.isScalable && handle.isSide) {
129+
if (handle.isHorizontal) {
130+
left = handle.influencesLeft
131+
? initialBox.right - newWidth
132+
: initialBox.left;
133+
top = initialBox.center.y - newHeight / 2;
134+
} else {
135+
top = handle.influencesTop
136+
? initialBox.bottom - newHeight
137+
: initialBox.top;
138+
left = initialBox.center.x - newWidth / 2;
139+
}
140+
} else {
141+
left = handle.influencesLeft
142+
? initialBox.right - newWidth
143+
: initialBox.left;
144+
top = handle.influencesTop
145+
? initialBox.bottom - newHeight
146+
: initialBox.top;
147+
}
148+
Box rect = Box.fromLTWH(left, top, newWidth, newHeight);
127149

128150
// Flip the rect only if flipRect is true.
129151
newRect = flipRect ? flipBox(rect, currentFlip, handle) : rect;
@@ -257,12 +279,46 @@ class BoxTransformer {
257279

258280
initialBox = flipBox(initialBox, flip, handle);
259281
Box rect;
260-
rect = Box.fromLTRB(
261-
initialBox.left + (handle.influencesLeft ? delta.x : 0),
262-
initialBox.top + (handle.influencesTop ? delta.y : 0),
263-
initialBox.right + (handle.influencesRight ? delta.x : 0),
264-
initialBox.bottom + (handle.influencesBottom ? delta.y : 0),
265-
);
282+
283+
/// If the handle is a side handle and its a scalable resizing, then
284+
/// the resizing should be w.r.t. the opposite side of the handle.
285+
/// This is needs to be handled separately because the anchor point in
286+
/// this case is the center of the handle on the opposite side.
287+
if (handle.isSide && resizeMode.isScalable) {
288+
double left;
289+
double top;
290+
double right;
291+
double bottom;
292+
293+
if (handle.isHorizontal) {
294+
left =
295+
handle.influencesLeft ? initialBox.left + delta.x : initialBox.left;
296+
right = handle.influencesRight
297+
? initialBox.right + delta.x
298+
: initialBox.right;
299+
final width = right - left;
300+
final height = width / aspectRatio;
301+
top = initialBox.centerLeft.y - height / 2;
302+
bottom = initialBox.centerLeft.y + height / 2;
303+
} else {
304+
top = handle.influencesTop ? initialBox.top + delta.y : initialBox.top;
305+
bottom = handle.influencesBottom
306+
? initialBox.bottom + delta.y
307+
: initialBox.bottom;
308+
final height = bottom - top;
309+
final width = height * aspectRatio;
310+
left = initialBox.centerLeft.x - width / 2;
311+
right = initialBox.centerLeft.x + width / 2;
312+
}
313+
rect = Box.fromLTRB(left, top, right, bottom);
314+
} else {
315+
rect = Box.fromLTRB(
316+
initialBox.left + (handle.influencesLeft ? delta.x : 0),
317+
initialBox.top + (handle.influencesTop ? delta.y : 0),
318+
initialBox.right + (handle.influencesRight ? delta.x : 0),
319+
initialBox.bottom + (handle.influencesBottom ? delta.y : 0),
320+
);
321+
}
266322
if (resizeMode.hasSymmetry) {
267323
final widthDelta = (initialBox.width - rect.width) / 2;
268324
final heightDelta = (initialBox.height - rect.height) / 2;

0 commit comments

Comments
 (0)