Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks {
this.onLayerTapUp,
this.onImportHistoryStart,
this.onImportHistoryEnd,
this.onLayerInteractionEnd,
this.onHoverRemoveAreaChange,
this.onStateHistoryChange,
this.onImageDecoded,
Expand Down Expand Up @@ -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<Layer>] 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<Layer> layers)? onLayerInteractionEnd;

/// A callback function that is triggered when a sub-editor is opened.
///
/// The [SubEditor] parameter provides information about the opened
Expand Down Expand Up @@ -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<Layer> layers) {
onLayerInteractionEnd?.call(layers);
handleUpdateUI();
}

/// Handles the opening of a sub-editor.
///
/// This method calls the [onOpenSubEditor] callback with the provided
Expand Down Expand Up @@ -480,6 +497,7 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks {
Function()? onImageDecoded,
Future<TextLayer?> Function(TextLayer layer)? onEditTextLayer,
Future<TextLayer?> Function()? onCreateTextLayer,
Function(List<Layer> layers)? onLayerInteractionEnd,
Function(ProImageEditorState state, ImportStateHistory import)?
onImportHistoryStart,
Function(ProImageEditorState state, ImportStateHistory import)?
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/features/main_editor/main_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,10 @@ class ProImageEditorState extends State<ProImageEditor>
/// 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.
Expand Down
Loading