|
| 1 | +package com.smarttoolfactory.image.beforeafter |
| 2 | + |
| 3 | +import androidx.compose.ui.geometry.Offset |
| 4 | +import androidx.compose.ui.unit.Constraints |
| 5 | +import androidx.compose.ui.unit.Density |
| 6 | +import androidx.compose.ui.unit.Dp |
| 7 | +import androidx.compose.ui.unit.IntRect |
| 8 | +import com.smarttoolfactory.image.ImageScope |
| 9 | + |
| 10 | +/** |
| 11 | + * Scope for before-after images that returns touch position on Composable |
| 12 | + */ |
| 13 | +interface BeforeAfterImageScope : ImageScope { |
| 14 | + var touchPosition: Offset |
| 15 | +} |
| 16 | + |
| 17 | +class BeforeAfterImageScopeImpl( |
| 18 | + private val density: Density, |
| 19 | + override val constraints: Constraints, |
| 20 | + override val imageWidth: Dp, |
| 21 | + override val imageHeight: Dp, |
| 22 | + override val rect: IntRect, |
| 23 | + override var touchPosition: Offset, |
| 24 | +) : BeforeAfterImageScope { |
| 25 | + |
| 26 | + override val minWidth: Dp get() = with(density) { constraints.minWidth.toDp() } |
| 27 | + |
| 28 | + override val maxWidth: Dp |
| 29 | + get() = with(density) { |
| 30 | + if (constraints.hasBoundedWidth) constraints.maxWidth.toDp() else Dp.Infinity |
| 31 | + } |
| 32 | + |
| 33 | + override val minHeight: Dp get() = with(density) { constraints.minHeight.toDp() } |
| 34 | + |
| 35 | + override val maxHeight: Dp |
| 36 | + get() = with(density) { |
| 37 | + if (constraints.hasBoundedHeight) constraints.maxHeight.toDp() else Dp.Infinity |
| 38 | + } |
| 39 | +} |
0 commit comments