1+ package com.smarttoolfactory.composeimage.demo
2+
3+ import androidx.compose.foundation.Image
4+ import androidx.compose.foundation.background
5+ import androidx.compose.foundation.layout.*
6+ import androidx.compose.foundation.shape.RoundedCornerShape
7+ import androidx.compose.material.Text
8+ import androidx.compose.material3.ElevatedButton
9+ import androidx.compose.runtime.*
10+ import androidx.compose.ui.Modifier
11+ import androidx.compose.ui.graphics.Color
12+ import androidx.compose.ui.layout.ContentScale
13+ import androidx.compose.ui.platform.LocalDensity
14+ import androidx.compose.ui.res.painterResource
15+ import androidx.compose.ui.unit.dp
16+ import androidx.compose.ui.unit.sp
17+ import androidx.compose.ui.zIndex
18+ import com.smarttoolfactory.composeimage.R
19+ import com.smarttoolfactory.image.transform.HandlePlacement
20+ import com.smarttoolfactory.image.transform.TransformLayout
21+
22+ @Composable
23+ fun EditScaleDemo () {
24+ Column (
25+ modifier = Modifier
26+ .background(Color (0xff424242 ))
27+ .fillMaxSize()
28+ .padding(8 .dp)
29+ ) {
30+
31+ var enabled by remember { mutableStateOf(true ) }
32+
33+ Spacer (modifier = Modifier .height(40 .dp))
34+
35+ var zIndex1 by remember {
36+ mutableStateOf(0f )
37+ }
38+
39+ var zIndex2 by remember {
40+ mutableStateOf(0f )
41+ }
42+
43+ var zIndex3 by remember {
44+ mutableStateOf(0f )
45+ }
46+
47+
48+ val density = LocalDensity .current
49+ val size = (500 / density.density).dp
50+
51+ TransformLayout (
52+ modifier = Modifier
53+ .size(size)
54+ .zIndex(zIndex1),
55+ enabled = enabled,
56+ onDown = {
57+ zIndex1 = 1f
58+ },
59+ onUp = {
60+ zIndex1 = 0f
61+ }
62+ ) {
63+ Image (
64+ painter = painterResource(id = R .drawable.landscape1),
65+ contentScale = ContentScale .FillBounds ,
66+ contentDescription = " " ,
67+ )
68+ }
69+
70+ TransformLayout (
71+ modifier = Modifier .zIndex(zIndex2),
72+ handleRadius = 20 .dp,
73+ enabled = enabled,
74+ handlePlacement = HandlePlacement .Side ,
75+ onDown = {
76+ zIndex2 = 1f
77+ },
78+ onUp = {
79+ zIndex2 = 0f
80+ }
81+ ) {
82+ Image (
83+ painter = painterResource(id = R .drawable.landscape2),
84+ contentScale = ContentScale .FillBounds ,
85+ contentDescription = " "
86+ )
87+ }
88+
89+ TransformLayout (
90+ modifier = Modifier
91+ .size(width = 300 .dp, height = 200 .dp)
92+ .zIndex(zIndex3),
93+ enabled = enabled,
94+ handlePlacement = HandlePlacement .Both ,
95+ onDown = {
96+ zIndex3 = 1f
97+ },
98+ onUp = {
99+ zIndex3 = 0f
100+ }
101+ ) {
102+ Image (
103+ painter = painterResource(id = R .drawable.landscape3),
104+ contentScale = ContentScale .Fit ,
105+ contentDescription = " "
106+ )
107+ }
108+
109+ TransformLayout (
110+ enabled = enabled
111+ ) {
112+ Text (
113+ text = " Hello World" ,
114+ modifier = Modifier
115+ .background(
116+ Color .Red ,
117+ RoundedCornerShape (25 )
118+ )
119+ .padding(2 .dp),
120+ fontSize = 20 .sp,
121+ color = Color .White
122+ )
123+ }
124+
125+
126+ Spacer (modifier = Modifier .weight(1f ))
127+
128+ ElevatedButton (
129+ modifier = Modifier
130+ .fillMaxWidth()
131+ .padding(8 .dp),
132+ onClick = { enabled = ! enabled }
133+ ) {
134+ Text (if (enabled) " Disable" else " Enable" )
135+ }
136+ Spacer (modifier = Modifier .height(50 .dp))
137+ }
138+ }
0 commit comments