@@ -22,8 +22,11 @@ import androidx.compose.ui.text.font.FontWeight
2222import androidx.compose.ui.unit.IntSize
2323import androidx.compose.ui.unit.dp
2424import androidx.compose.ui.unit.sp
25+ import com.smarttoolfactory.composeimage.ContentScaleSelectionMenu
2526import com.smarttoolfactory.composeimage.R
27+ import com.smarttoolfactory.composeimage.TitleMedium
2628import com.smarttoolfactory.image.zoom.EnhancedZoomData
29+ import com.smarttoolfactory.image.zoom.EnhancedZoomableImage
2730import com.smarttoolfactory.image.zoom.enhancedZoom
2831import com.smarttoolfactory.image.zoom.rememberEnhancedZoomState
2932
@@ -42,11 +45,100 @@ fun EnhancedZoomDemo() {
4245 R .drawable.landscape1
4346 )
4447
48+ var contentScale by remember { mutableStateOf(ContentScale .Fit ) }
49+
50+ ContentScaleSelectionMenu (contentScale = contentScale) {
51+ contentScale = it
52+ }
53+
54+ EnhancedZoomableImageSample (imageBitmap = imageBitmapLarge, contentScale)
4555 EnhancedZoomModifierSample (imageBitmap = imageBitmapLarge)
4656 CallbackAndCropSample (imageBitmap = imageBitmapLarge)
4757 }
4858}
4959
60+ @Composable
61+ private fun EnhancedZoomableImageSample (imageBitmap : ImageBitmap , contentScale : ContentScale ) {
62+
63+ TitleMedium (text = " EnhancedZoomableImage" )
64+
65+ TitleMedium (text = " clipTransformToContentScale false" )
66+ EnhancedZoomableImage (
67+ modifier = Modifier
68+ .background(Color .LightGray )
69+ .fillMaxWidth()
70+ .aspectRatio(4 / 3f ),
71+ imageBitmap = imageBitmap,
72+ contentScale = contentScale,
73+ clipTransformToContentScale = false
74+ )
75+
76+ Spacer (modifier = Modifier .height(40 .dp))
77+
78+ TitleMedium (
79+ text = " clip = true\n " +
80+ " limitPan = false\n " +
81+ " moveToBounds = true\n " +
82+ " clipTransformToContentScale = true"
83+ )
84+
85+ EnhancedZoomableImage (
86+ modifier = Modifier
87+ .background(Color .LightGray )
88+ .fillMaxWidth()
89+ .aspectRatio(4 / 3f ),
90+ imageBitmap = imageBitmap,
91+ contentScale = contentScale,
92+ limitPan = false ,
93+ moveToBounds = true ,
94+ clipTransformToContentScale = true
95+ )
96+
97+ Spacer (modifier = Modifier .height(40 .dp))
98+
99+ TitleMedium (
100+ text = " clip = true\n " +
101+ " limitPan = false\n " +
102+ " moveToBounds = true\n " +
103+ " fling = true"
104+ )
105+ EnhancedZoomableImage (
106+ modifier = Modifier
107+ .background(Color .LightGray )
108+ .fillMaxWidth()
109+ .aspectRatio(4 / 3f ),
110+ imageBitmap = imageBitmap,
111+ contentScale = contentScale,
112+ limitPan = false ,
113+ moveToBounds = true ,
114+ fling = true
115+ )
116+
117+
118+ TitleMedium (
119+ text = " clip = false\n " +
120+ " limitPan = false\n " +
121+ " rotatable = true\n " +
122+ " moveToBounds = false\n " +
123+ " fling = true"
124+ )
125+ EnhancedZoomableImage (
126+ modifier = Modifier
127+ .background(Color .LightGray )
128+ .fillMaxWidth()
129+ .aspectRatio(4 / 3f ),
130+ imageBitmap = imageBitmap,
131+ contentScale = contentScale,
132+ clip = false ,
133+ limitPan = false ,
134+ rotatable = true ,
135+ moveToBounds = false ,
136+ fling = true
137+ )
138+
139+ Spacer (modifier = Modifier .height(40 .dp))
140+ }
141+
50142@Composable
51143private fun EnhancedZoomModifierSample (imageBitmap : ImageBitmap ) {
52144 Column (
@@ -64,14 +156,10 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
64156 modifier = Modifier .padding(8 .dp)
65157 )
66158
67- Text (
159+ TitleMedium (
68160 text = " clip = true\n " +
69161 " limitPan = false\n " +
70- " moveToBoundsEnabled = true" ,
71- fontSize = 16 .sp,
72- fontWeight = FontWeight .Bold ,
73- color = MaterialTheme .colorScheme.primary,
74- modifier = Modifier .padding(8 .dp)
162+ " moveToBounds = true"
75163 )
76164 Image (
77165 modifier = Modifier
@@ -85,7 +173,7 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
85173 minZoom = .5f ,
86174 imageSize = IntSize (width, height),
87175 limitPan = false ,
88- moveToBoundsEnabled = true
176+ moveToBounds = true
89177 )
90178 ),
91179 bitmap = imageBitmap,
@@ -94,14 +182,10 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
94182 )
95183
96184 Spacer (modifier = Modifier .height(40 .dp))
97- Text (
185+ TitleMedium (
98186 text = " clip = true\n " +
99187 " limitPan = true\n " +
100- " moveToBoundsEnabled = true" ,
101- fontSize = 16 .sp,
102- fontWeight = FontWeight .Bold ,
103- color = MaterialTheme .colorScheme.primary,
104- modifier = Modifier .padding(8 .dp)
188+ " moveToBounds = true"
105189 )
106190 Image (
107191 modifier = Modifier
@@ -115,7 +199,7 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
115199 minZoom = .5f ,
116200 imageSize = IntSize (width, height),
117201 limitPan = true ,
118- moveToBoundsEnabled = true
202+ moveToBounds = true
119203 )
120204 ),
121205 bitmap = imageBitmap,
@@ -124,15 +208,11 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
124208 )
125209
126210 Spacer (modifier = Modifier .height(40 .dp))
127- Text (
211+ TitleMedium (
128212 text = " clip = true\n " +
129213 " limitPan = true\n " +
130- " moveToBoundsEnabled = true\n " +
131- " flingGestureEnabled = true" ,
132- fontSize = 16 .sp,
133- fontWeight = FontWeight .Bold ,
134- color = MaterialTheme .colorScheme.primary,
135- modifier = Modifier .padding(8 .dp)
214+ " moveToBounds = true\n " +
215+ " fling = true"
136216 )
137217 Image (
138218 modifier = Modifier
@@ -145,8 +225,8 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
145225 enhancedZoomState = rememberEnhancedZoomState(
146226 imageSize = IntSize (width, height),
147227 limitPan = false ,
148- moveToBoundsEnabled = true ,
149- flingGestureEnabled = true
228+ moveToBounds = false ,
229+ fling = true
150230 )
151231 ),
152232 bitmap = imageBitmap,
@@ -155,15 +235,11 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
155235 )
156236
157237 Spacer (modifier = Modifier .height(40 .dp))
158- Text (
238+ TitleMedium (
159239 text = " clip = true\n " +
160240 " rotate = true\n " +
161- " moveToBoundsEnabled = false\n " +
162- " flingGestureEnabled = true" ,
163- fontSize = 16 .sp,
164- fontWeight = FontWeight .Bold ,
165- color = MaterialTheme .colorScheme.primary,
166- modifier = Modifier .padding(8 .dp)
241+ " moveToBounds = false\n " +
242+ " fling = true"
167243 )
168244 Image (
169245 modifier = Modifier
@@ -177,9 +253,9 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
177253 imageSize = IntSize (width, height),
178254 minZoom = .5f ,
179255 limitPan = true ,
180- rotationEnabled = true ,
181- moveToBoundsEnabled = false ,
182- flingGestureEnabled = true
256+ rotatable = true ,
257+ moveToBounds = false ,
258+ fling = true
183259 )
184260 ),
185261 bitmap = imageBitmap,
@@ -195,13 +271,7 @@ private fun CallbackAndCropSample(imageBitmap: ImageBitmap) {
195271
196272 // ⚠️ getting Rect and creating bitmap on each frame is for demonstration only
197273 // get rect on up motion and when gesture finished running
198- Text (
199- text = " Callback and Crop" ,
200- fontSize = 16 .sp,
201- fontWeight = FontWeight .Bold ,
202- color = MaterialTheme .colorScheme.primary,
203- modifier = Modifier .padding(8 .dp)
204- )
274+ TitleMedium (text = " Callback and Crop" )
205275
206276 var rectCrop by remember {
207277 mutableStateOf(
@@ -239,7 +309,7 @@ private fun CallbackAndCropSample(imageBitmap: ImageBitmap) {
239309
240310 val zoomState = rememberEnhancedZoomState(
241311 minZoom = .5f ,
242- flingGestureEnabled = true ,
312+ fling = true ,
243313 imageSize = IntSize (imageBitmap.width, imageBitmap.height)
244314 )
245315
@@ -275,15 +345,18 @@ private fun CallbackAndCropSample(imageBitmap: ImageBitmap) {
275345 rect = rectDraw
276346 )
277347
278-
279- Text (
280- " isAnimating: ${zoomState.isAnimationRunning} , " +
281- " isPanAnimating: ${zoomState.isPanning} , " +
282- " isZooming: ${zoomState.isZooming} \n " +
283- " rectDraw: $rectDraw \n " +
284- " rectCrop: $rectCrop " ,
285- color = Color .Cyan
286- )
348+ Column {
349+ Text (
350+ text = " isAnimating: ${zoomState.isAnimationRunning} , " +
351+ " isPanAnimating: ${zoomState.isPanning} , " +
352+ " isZooming: ${zoomState.isZooming} " ,
353+ color = if (zoomState.isAnimationRunning) Color .Red else Color .Green
354+ )
355+ Text (
356+ text = " rectDraw: $rectDraw \n " +
357+ " rectCrop: $rectCrop " , color = Color .Cyan
358+ )
359+ }
287360 }
288361 }
289362
0 commit comments