CropImageLayer class
Crop / rotate / flip tool layer.
Renders the image inside a crop rectangle with a corner-bracket frame and a rule-of-thirds grid; pan + scale gestures (via CropGestures) reposition the image inside the fixed crop. The host wires rotate-90 / flip / aspect-ratio buttons into the layer's mutators.
The viewport-fitting matrix lives on the host (ComposeEntry); the
layer is told the current camera at paint time and reads its scale
for grid-line widths. User gestures mutate imageTransform / crop,
never the camera.
- Mixed-in types
- Available extensions
Constructors
- CropImageLayer({required Image image})
-
Crops
image, which the caller owns.
Properties
- areaTracking ↔ bool
-
Cross-surface interaction ownership, telegram's mutual gates
(
TGPhotoCropView.shouldBeginChanging/shouldBeginEditing): while one surface tracks the other two must not engage — otherwise a second finger pans the image mid-resize.getter/setter pair - backdropOpacity ↔ double
-
Opacity of the idle backdrop — the dark BLURRED rendition of the
image outside the crop rect. 1 at rest; fades out over 0.16s
when an interaction begins (instantly for handle drags, matching
telegram's
resetBackdropViewsAnimated:falseon area edits) and back in when the confirm countdown lands (TGPhotoCropView.showBackdropViewAnimated).getter/setter pair -
confirmTick
→ ValueEmitter<
int> -
Fires when a confirm lands (1s countdown after an area edit, or
immediately on an aspect snap).
CropScreenanswers by re-fitting the host camera to the new crop rect — telegram's evenlyFill.latefinal - crop ↔ Rect
-
Active crop rectangle in image-space. Defaults to the full image.
getter/setter pair
- cropChangedSinceConfirm ↔ bool
-
Set by the handle overlay on every area edit; consumed by the
confirm countdown — the camera refit only runs when the crop
rect actually changed (telegram's
_cropAreaChanged).getter/setter pair - dialTracking ↔ bool
-
Whether the rotation dial tracks a gesture.
getter/setter pair
- disposed → bool
-
Whether dispose has already run.
no setterinherited
- exportMatrix → Matrix4
-
The source-pixel → output-pixel affine paintExportOf bakes (with
flipDecoration == 0): move the crop origin to the output origin, then apply the centered imageTransform (pan / scale / rotateZ / flipX). The output canvas is exportSize. A pure 2D affine — no perspective, since the card-flip decoration is only a live-edit animation. The video export path hands this same matrix to the native encoder (and the live cropped-video preview paints with it), so the exported frames match the on-screen crop exactly.no setter - exportSize → Size
-
This layer's intrinsic export size — typically the source image's
natural dimensions.
no setteroverride
- fillScale → double
-
totalScale at which the un-rotated image exactly fills crop —
telegram's
minimumZoomScale. Pinching below it rubber-bands.no setter - gridOpacity ↔ double
-
Opacity of the interior thirds lines. 0 at rest; fades to 1 over
0.2s while a gesture is live and back out 1.0s after it ends —
telegram's grid show/hide + confirm-countdown timing
(
TGPhotoCropView.m:542,TGPhotoCropGridView).getter/setter pair - hasAppliedEdits → bool
-
True if the layer has any applied edits beyond the default state
(used by ComposeEntry to decide whether to rasterise on submit).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether there is at least one active listener.
no setterinherited
- image → Image
-
The source image.
final
- imageSize → Size
-
image's size in pixels.
latefinal
- imageTransform → UserTransform
-
User-driven image-space transform: pan offset, scale, rotate, flip.
Data state — tests and gestures observe synchronous changes here.
latefinal
- lockedAspectRatio ↔ double?
-
Aspect lock as height/width (telegram's
aspectRatioshape), or null when the crop is free. Set by the aspect-ratio cycle; the handle overlay constrains resizes against it and shows all four edge highlights while locked.getter/setter pair - maxTotalScale → double
-
Hard pinch ceiling for the current crop.
no setter
- renderRotate → double
-
The angle paint draws at: the data angle at rest, the interpolated
one while
_renderAnimatorruns.no setter - rotationScaleFloor ↔ double
-
The zoom the rotation dial holds as it turns: the user's own last
deliberate zoom, or fillScale when they have not set one.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollTracking ↔ bool
-
Whether the pan and pinch surface tracks a gesture.
getter/setter pair
Methods
-
addDispose(
VoidCallback callback) → void -
Registers a disposal
callback. Ignored if already disposed.inherited -
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object notifies its listeners.
inherited
-
beginInteraction(
{bool instantBackdrop = false}) → void -
Gesture-start hook: kill any in-flight settle spring and pending
grid fade-out, show the thirds grid, drop the idle backdrop.
instantBackdropmirrors telegram's non-animated reset on handle drags vs the 0.16s fade on scroll gestures. -
captureRotationFloor(
) → void - Record the current zoom as the dial's floor, unless the image is already rotated and sitting at bare coverage — that zoom is the dial's own doing, not the user's.
-
coverageScale(
double rotateZ) → double -
Smallest totalScale at which the image, rotated by
rotateZ, can still cover the whole crop rect: the crop rect's bounding box in the image-aligned frame must fit inside the source. -
dispose(
) → void -
Releases whatever this object holds. Calling it twice is an error.
override
-
disposeBy(
Dispose disposer) → void -
Available on Disposable, provided by the DisposableDisposerExtension extension
Adds this object's dispose to another Dispose collector. -
driveSnapshotRevert(
double t) → void - Interactive counterpart of restoreSnapshotAnimated: blends the RENDER transform between the last saveSnapshot (t = 0) and the in-session state (t = 1). The crop screen maps its swipe-back progress here so the image visibly un-zooms with the finger. t back at 1 releases the drive (aborted swipe). Data state is untouched — a completed swipe pops the screen, whose restore path commits the snapshot and animates the remainder.
-
endInteraction(
) → void - Gesture-end hook (all pointers up): spring back to coverage and schedule the grid fade-out + backdrop return.
-
flipHorizontal(
) → void -
Flip the image horizontally. Data flipX snaps; the visible flip
runs as a card flip — Y-axis tilt eased from π → 0 — over
kAnimation. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Notifies all registered listeners.
inherited
-
paintExport(
Canvas canvas, Size size) → void -
Paint into the export canvas.
sizeis the editor-wide export size (max over all exporters), so layers must position themselves accordingly.override -
paintExportOf(
Canvas canvas, Size size, Image source) → void -
Apply this layer's crop transform to a different
sourceimage (instead ofthis.image). Used byComposeEntry._composeLayersto compose tools as a pipeline: the source is first painted with strokes from the draw layer (in source-space), then THAT result is fed here for the geometric clip / rotate / flip. Matches telegram's pipeline (source → paint → crop) — strokes survive re-cropping because they're in source-space. -
paintViewport(
Canvas canvas, Size size, {required Matrix4 camera}) → void -
Paints the layer into a viewport of
sizethroughcamera.override -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that the
object notifies.
inherited
-
resetImage(
) → Future< void> - Returns the image to no pan, zoom, rotation or flip. The data state snaps; the visible transform eases to it, and the future completes when it has.
-
resetRotation(
) → void - Spring the rotation back to 0, re-covering the crop at the zoom the dial holds (rotationScaleFloor) rather than at the widest coverage the rotation passed through. imageTransform snaps; the visible rotation springs there over kTgSpring.
-
restoreBackdropAfterTransition(
) → void - Shows the backdrop again, without animating, once the transition has landed.
-
restoreSnapshot(
) → void - Restore the layer to the last saveSnapshot. No-op if none saved.
-
restoreSnapshotAnimated(
) → Future< void> -
Like restoreSnapshot but smoothly reverses the in-session
transforms instead of snapping them. Data state snaps synchronously
(callers — including the host — see the restored values immediately);
the render-side animator interpolates the visual rotate / pan /
scale back to the snapshot, and a session-flip plays its card-flip
arc in reverse.
CropScreen._cancelfires this unawaited and then pops, so the reverse overlaps with the screen's pop transition. -
rotate90(
) → void -
Rotate the image 90° counter-clockwise (one quarter turn).
imageTransform snaps so callers / tests / gestures see the new
rotation immediately; the visible rotation eases over
kAnimation. -
rotateCovered(
double rotateZ, {required double scaleFloor}) → void -
Set the free rotation angle and re-cover the crop in one commit,
never zooming below
scaleFloor. Takes over a running spin from wherever it had reached, so a dial grab mid-quarter-turn continues under the finger. -
saveSnapshot(
) → void - Capture current state for later restoreSnapshot.
-
setAspectRatio(
double? ratio) → void -
Resize the crop rectangle to the given aspect ratio (width / height),
or pass
nullto free the crop and reset to the full image. -
settleToCoverage(
) → Future< void> - Spring the image back to the nearest crop-covering state — telegram's release fit (POP spring, speed 7 / bounciness 1).
-
snapToCoverage(
) → void -
Instantly snap the image transform to the nearest crop-covering
state — the live fit that runs on every handle-drag update
(telegram's non-animated
fitContentInsideBoundsAllowScale). -
subscribe(
VoidCallback callback) → VoidCallback -
Available on Listenable, provided by the ListenableExtension extension
Addscallbackas listener and returns a function to remove it. -
suspendBackdropForTransition(
) → void -
Tool-entry transition support (telegram keeps the backdrop
hidden until
transitionInFinished): the crop screen suspends it on push and restores it once the push transition lands. -
toString(
) → String -
A string representation of this object.
inherited
-
viewportToSource(
Offset viewport, {required Matrix4 camera}) → Offset -
Inverse of the full viewport-rendering transform —
viewport = camera · sandwich(imageTransform) · source. Used by composed-scene gesture handlers (e.g.DrawGestures) that need to convert pointer-in-viewport coordinates back to source-space so strokes recorded in a crop-overlayed editor still land in the right place on the original source.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited