diff --git a/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart b/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart index f40a4e97d..84a6f4ab3 100644 --- a/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart +++ b/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart @@ -41,6 +41,7 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { this.onLayerTapUp, this.onImportHistoryStart, this.onImportHistoryEnd, + this.onLayerInteractionEnd, this.onHoverRemoveAreaChange, this.onStateHistoryChange, this.onImageDecoded, @@ -79,6 +80,13 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { /// The [Layer] parameter provides information about the removed layer. final Function(Layer layer)? onRemoveLayer; + /// A callback triggered when a layer interaction (drag/scale/rotate) ends. + /// + /// The [List] parameter provides the layers that were being + /// interacted with. This is useful for applying final adjustments like + /// snap-to-grid on release. + final Function(List layers)? onLayerInteractionEnd; + /// A callback function that is triggered when a sub-editor is opened. /// /// The [SubEditor] parameter provides information about the opened @@ -383,6 +391,15 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { handleUpdateUI(); } + /// Handles the end of a layer interaction (drag/scale/rotate). + /// + /// This method calls the [onLayerInteractionEnd] callback with the + /// provided [layers] and then calls [handleUpdateUI]. + void handleLayerInteractionEnd(List layers) { + onLayerInteractionEnd?.call(layers); + handleUpdateUI(); + } + /// Handles the opening of a sub-editor. /// /// This method calls the [onOpenSubEditor] callback with the provided @@ -480,6 +497,7 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { Function()? onImageDecoded, Future Function(TextLayer layer)? onEditTextLayer, Future Function()? onCreateTextLayer, + Function(List layers)? onLayerInteractionEnd, Function(ProImageEditorState state, ImportStateHistory import)? onImportHistoryStart, Function(ProImageEditorState state, ImportStateHistory import)? @@ -530,6 +548,8 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { onCreateTextLayer: onCreateTextLayer ?? this.onCreateTextLayer, onImportHistoryStart: onImportHistoryStart ?? this.onImportHistoryStart, onImportHistoryEnd: onImportHistoryEnd ?? this.onImportHistoryEnd, + onLayerInteractionEnd: + onLayerInteractionEnd ?? this.onLayerInteractionEnd, onHoverRemoveAreaChange: onHoverRemoveAreaChange ?? this.onHoverRemoveAreaChange, onStateHistoryChange: onStateHistoryChange ?? this.onStateHistoryChange, diff --git a/lib/features/main_editor/main_editor.dart b/lib/features/main_editor/main_editor.dart index cc702d0fe..5699a78b5 100644 --- a/lib/features/main_editor/main_editor.dart +++ b/lib/features/main_editor/main_editor.dart @@ -1340,6 +1340,9 @@ class ProImageEditorState extends State /// lines and flags. void _onScaleEnd(ScaleEndDetails details) async { mainEditorCallbacks?.handleScaleEnd(details); + if (selectedLayers.isNotEmpty) { + mainEditorCallbacks?.handleLayerInteractionEnd(List.of(selectedLayers)); + } layerInteractionManager.activeInteractionLayer = null; /// Check if layers should be removed.