commonMain.me.saket.telephoto.zoomable.internal.savedState.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zoomable-desktop Show documentation
Show all versions of zoomable-desktop Show documentation
A Modifier for making anything zoomable.
package me.saket.telephoto.zoomable.internal
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.layout.ScaleFactor
import me.saket.telephoto.zoomable.ContentZoom
import me.saket.telephoto.zoomable.RawTransformation
@AndroidParcelize
internal data class ZoomableSavedState(
private val offsetX: Float?,
private val offsetY: Float?,
private val userZoom: Float?
) : AndroidParcelable {
fun gestureTransformation(): RawTransformation? {
return RawTransformation(
offset = Offset(
x = offsetX ?: return null,
y = offsetY ?: return null
),
zoom = ContentZoom(
baseZoom = ScaleFactor(0f, 0f), // Will get recalculated after restoration.
userZoom = userZoom ?: return null
),
lastCentroid = Offset.Zero,
contentSize = Size.Zero, // Will get recalculated after restoration.
)
}
}
internal fun ZoomableSavedState(transformation: RawTransformation?) =
ZoomableSavedState(
offsetX = transformation?.offset?.x,
offsetY = transformation?.offset?.y,
userZoom = transformation?.zoom?.userZoom
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy