resizeSelectedFromHandle method
Resizes the selected object from a visible selection handle.
Implementation
bool resizeSelectedFromHandle(
CanvasSelectionHandle handle,
double dx,
double dy,
) {
if (_selectedObjectIds.isEmpty) return false;
if (_selectedObjectIds.length == 1) {
final id = selectedObjectId;
final object = selectedObject;
if (id == null || object == null) return false;
if (object.locked) return false;
_remember();
final resized = _constrainObject(
object,
_resizeObjectFromHandle(
object,
handle,
dx,
dy,
constraints: constraints,
),
);
final index = _objects.indexWhere((item) => item.id == id);
if (index < 0) return false;
_objects[index] = resized;
render();
onResize?.call(List.unmodifiable([resized]));
_emitChange();
return true;
}
final bounds = selectedBounds;
if (bounds == null) return false;
final nextBounds = _boundsFromHandle(bounds, handle, dx, dy);
final scaleX = bounds.width == 0 ? 1.0 : nextBounds.width / bounds.width;
final scaleY = bounds.height == 0 ? 1.0 : nextBounds.height / bounds.height;
_remember();
final changed = <CanvasObject>[];
for (final id in _selectedObjectIds) {
final index = _objects.indexWhere((object) => object.id == id);
if (index < 0) continue;
if (_objects[index].locked) continue;
final resized = _constrainObject(
_objects[index],
_scaleObjectInBounds(
_objects[index],
bounds,
nextBounds,
scaleX,
scaleY,
constraints: constraints,
),
);
_objects[index] = resized;
changed.add(resized);
}
if (changed.isEmpty) return false;
render();
onResize?.call(List.unmodifiable(changed));
_emitChange();
return true;
}