@@ -34,6 +34,27 @@ import com.smarttoolfactory.image.getParentSize
3434import com.smarttoolfactory.image.getScaledBitmapRect
3535import com.smarttoolfactory.image.util.scale
3636
37+ /* *
38+ * A composable that lays out and draws a given [beforeImage] and [afterImage] at given [order]
39+ * with specified [contentScale] and returns draw area and section of drawn bitmap.
40+ *
41+ * [BeforeAfterImageScope] extends [ImageScope] that returns draw area dimensions and image draw rect
42+ * and touch position of user on screen.
43+ *
44+ * @param beforeImage image that show initial progress
45+ * @param afterImage image that show final progress
46+ * @param enableProgressWithTouch flag to enable drag and change progress with touch
47+ * @param enableZoom when enabled images are zoomable and pannable
48+ * @param order order of images to be drawn
49+ * @param alignment determines where image will be aligned inside [BoxWithConstraints]
50+ * This is observable when bitmap image/width ratio differs from [Canvas] that draws [ImageBitmap]
51+ * @param contentDescription text used by accessibility services to describe what this image
52+ * represents. This should always be provided unless this image is used for decorative purposes,
53+ * and does not represent a meaningful action that a user can take. This text should be
54+ * localized, such as by using [androidx.compose.ui.res.stringResource] or similar
55+ * @param contentScale how image should be scaled inside Canvas to match parent dimensions.
56+ * [ContentScale.Fit] for instance maintains src ratio and scales image to fit inside the parent.
57+ */
3758@Composable
3859fun BeforeAfterImage (
3960 modifier : Modifier = Modifier ,
@@ -73,10 +94,6 @@ fun BeforeAfterImage(
7394 val thumbRadius = (thumbSize / 2 )
7495
7596 posY = ((imageHeight * thumbPosition / 100f - thumbRadius) - imageHeight / 2 )
76- // .coerceIn(
77- // thumbRadius,
78- // imageHeight - thumbRadius
79- // )
8097 .roundToPx()
8198
8299 imageWidth.toPx() / 2
@@ -110,6 +127,36 @@ fun BeforeAfterImage(
110127 }
111128}
112129
130+ /* *
131+ * A composable that lays out and draws a given [beforeImage] and [afterImage] at given [order]
132+ * with specified [contentScale] and returns draw area and section of drawn bitmap.
133+ *
134+ * [BeforeAfterImageScope] extends [ImageScope] that returns draw area dimensions and image draw rect
135+ * and touch position of user on screen.
136+ *
137+ * @param beforeImage image that show initial progress
138+ * @param afterImage image that show final progress
139+ * @param enableProgressWithTouch flag to enable drag and change progress with touch
140+ * @param enableZoom when enabled images are zoomable and pannable
141+ * @param order order of images to be drawn
142+ * @param alignment determines where image will be aligned inside [BoxWithConstraints]
143+ * This is observable when bitmap image/width ratio differs from [Canvas] that draws [ImageBitmap]
144+ * @param contentDescription text used by accessibility services to describe what this image
145+ * represents. This should always be provided unless this image is used for decorative purposes,
146+ * and does not represent a meaningful action that a user can take. This text should be
147+ * localized, such as by using [androidx.compose.ui.res.stringResource] or similar
148+ * @param contentScale how image should be scaled inside Canvas to match parent dimensions.
149+ * [ContentScale.Fit] for instance maintains src ratio and scales image to fit inside the parent.
150+ * @param alpha Opacity to be applied to [beforeImage] from 0.0f to 1.0f representing
151+ * fully transparent to fully opaque respectively
152+ * @param colorFilter ColorFilter to apply to the [beforeImage] when drawn into the destination
153+ * @param filterQuality Sampling algorithm applied to the [beforeImage] when it is scaled and drawn
154+ * into the destination. The default is [FilterQuality.Low] which scales using a bilinear
155+ * sampling algorithm
156+ * @param content is a Composable that can be matched at exact position where [beforeImage] is drawn.
157+ * This is useful for drawing thumbs, cropping or another layout that should match position
158+ * with the image that is scaled is drawn
159+ */
113160@Composable
114161fun BeforeAfterImage (
115162 modifier : Modifier = Modifier ,
@@ -150,20 +197,19 @@ fun BeforeAfterImage(
150197}
151198
152199/* *
153- * A composable that lays out and draws a given [ImageBitmap]. This will attempt to
154- * size the composable according to the [ImageBitmap]'s given width and height. However, an
155- * optional [Modifier] parameter can be provided to adjust sizing or draw additional content (ex.
156- * background). Any unspecified dimension will leverage the [ImageBitmap]'s size as a minimum
157- * constraint.
158- *
159- * [ImageScope] returns constraints, width and height of the drawing area based on [contentScale]
160- * and rectangle of [beforeImage] drawn. When a bitmap is displayed scaled to fit area of Composable
161- * space used for drawing image is represented with [ImageScope.imageWidth] and
162- * [ImageScope.imageHeight].
163- *
164- * When we display a bitmap 1000x1000px with [ContentScale.Crop] if it's cropped to 500x500px
165- * [ImageScope.rect] returns `IntRect(250,250,750,750)`.
200+ * A composable that lays out and draws a given [beforeImage] and [afterImage] at given [order]
201+ * with specified [contentScale] and returns draw area and section of drawn bitmap.
202+ *
203+ * [BeforeAfterImageScope] extends [ImageScope] that returns draw area dimensions and image draw rect
204+ * and touch position of user on screen.
166205 *
206+ * @param beforeImage image that show initial progress
207+ * @param afterImage image that show final progress
208+ * @param progress current before/after or after/before image display ratio between [0f-100f]
209+ * @param onProgressChange callback to notify use about [progress] has changed
210+ * @param enableProgressWithTouch flag to enable drag and change progress with touch
211+ * @param enableZoom when enabled images are zoomable and pannable
212+ * @param order order of images to be drawn
167213 * @param alignment determines where image will be aligned inside [BoxWithConstraints]
168214 * This is observable when bitmap image/width ratio differs from [Canvas] that draws [ImageBitmap]
169215 * @param contentDescription text used by accessibility services to describe what this image
@@ -200,7 +246,6 @@ fun BeforeAfterImage(
200246 filterQuality : FilterQuality = DrawScope .DefaultFilterQuality ,
201247 content : @Composable BeforeAfterImageScope .() -> Unit = {}
202248) {
203-
204249 val semantics = if (contentDescription != null ) {
205250 Modifier .semantics {
206251 this .contentDescription = contentDescription
0 commit comments