Skip to content

Commit

Permalink
Merge pull request #45 from dinaraparanid/master
Browse files Browse the repository at this point in the history
Crop with overlay ratio does not scale to full borders
  • Loading branch information
SmartToolFactory authored Jul 12, 2024
2 parents 9658d61 + 6452ce1 commit ac45140
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ fun Modifier.crop(
}
},
onGesture = { centroid, pan, zoom, rotate, mainPointer, pointerList ->

coroutineScope.launch {
cropState.onGesture(
centroid = centroid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import com.smarttoolfactory.cropper.model.AspectRatio
import com.smarttoolfactory.cropper.model.CropData
import com.smarttoolfactory.cropper.settings.CropProperties

internal const val MIN_OVERLAY_RATIO = 0.5F

val CropState.cropData: CropData
get() = CropData(
zoom = animatableZoom.targetValue,
Expand Down Expand Up @@ -293,8 +295,7 @@ abstract class CropState internal constructor(
animate: Boolean,
animationSpec: AnimationSpec<Float> = tween(400)
) {

val zoom = zoom.coerceAtLeast(1f)
val zoom = zoom.coerceAtLeast(MIN_OVERLAY_RATIO)

// Calculate new pan based on overlay
val newDrawAreaRect = calculateValidImageDrawRect(overlayRect, drawAreaRect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.ui.unit.IntSize
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

private const val MAX_ZOOM = 10F

/**
* State of the pan, zoom and rotation. Allows to change zoom, pan via [Animatable]
* objects' [Animatable.animateTo], [Animatable.snapTo].
Expand All @@ -37,8 +39,8 @@ open class TransformState(
val drawAreaSize: IntSize,
initialZoom: Float = 1f,
initialRotation: Float = 0f,
minZoom: Float = 1f,
maxZoom: Float = 10f,
minZoom: Float = MIN_OVERLAY_RATIO,
maxZoom: Float = MAX_ZOOM,
internal var zoomable: Boolean = true,
internal var pannable: Boolean = true,
internal var rotatable: Boolean = true,
Expand All @@ -55,7 +57,7 @@ open class TransformState(
)
)

internal val zoomMin = minZoom.coerceAtLeast(1f)
internal val zoomMin = minZoom.coerceAtLeast(MIN_OVERLAY_RATIO)
internal var zoomMax = maxZoom.coerceAtLeast(1f)
private val zoomInitial = initialZoom.coerceIn(zoomMin, zoomMax)
private val rotationInitial = initialRotation % 360
Expand Down

0 comments on commit ac45140

Please sign in to comment.