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.MorphLayout
21+
22+ @Composable
23+ fun EditSizeDemo () {
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+ MorphLayout (
52+ modifier = Modifier .size(size),
53+ containerModifier = Modifier .zIndex(zIndex1),
54+ enabled = enabled,
55+ onDown = {
56+ zIndex1 = 1f
57+ },
58+ onUp = {
59+ zIndex1 = 0f
60+ }
61+ ) {
62+ Image (
63+ painter = painterResource(id = R .drawable.landscape1),
64+ contentScale = ContentScale .FillBounds ,
65+ contentDescription = " " ,
66+ )
67+ }
68+
69+ MorphLayout (
70+ containerModifier = Modifier .zIndex(zIndex2),
71+ handleRadius = 20 .dp,
72+ enabled = enabled,
73+ handlePlacement = HandlePlacement .Side ,
74+ onDown = {
75+ zIndex2 = 1f
76+ },
77+ onUp = {
78+ zIndex2 = 0f
79+ }
80+ ) {
81+ Image (
82+ painter = painterResource(id = R .drawable.landscape2),
83+ contentScale = ContentScale .FillBounds ,
84+ contentDescription = " "
85+ )
86+ }
87+
88+ MorphLayout (
89+ modifier = Modifier .size(width = 300 .dp, height = 200 .dp),
90+ containerModifier = Modifier .zIndex(zIndex3),
91+ enabled = enabled,
92+ handlePlacement = HandlePlacement .Both ,
93+ onDown = {
94+ zIndex3 = 1f
95+ },
96+ onUp = {
97+ zIndex3 = 0f
98+ }
99+ ) {
100+ Image (
101+ painter = painterResource(id = R .drawable.landscape3),
102+ contentScale = ContentScale .Fit ,
103+ contentDescription = " "
104+ )
105+ }
106+
107+ MorphLayout (
108+ enabled = enabled
109+ ) {
110+ Text (
111+ text = " Hello World" ,
112+ modifier = Modifier
113+ .background(
114+ Color .Red ,
115+ RoundedCornerShape (25 )
116+ )
117+ .padding(2 .dp),
118+ fontSize = 20 .sp,
119+ color = Color .White
120+ )
121+ }
122+
123+
124+ Spacer (modifier = Modifier .weight(1f ))
125+
126+ ElevatedButton (
127+ modifier = Modifier
128+ .fillMaxWidth()
129+ .padding(8 .dp),
130+ onClick = { enabled = ! enabled }
131+ ) {
132+ Text (if (enabled) " Disable" else " Enable" )
133+ }
134+ Spacer (modifier = Modifier .height(50 .dp))
135+ }
136+ }
0 commit comments