Skip to content

Commit 0faca7a

Browse files
add BeforeAfterImageScope
1 parent 7ea43ef commit 0faca7a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)