@@ -8,9 +8,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
88import androidx.compose.foundation.verticalScroll
99import androidx.compose.material3.MaterialTheme
1010import androidx.compose.material3.Text
11- import androidx.compose.runtime.Composable
12- import androidx.compose.runtime.getValue
13- import androidx.compose.ui.Alignment
11+ import androidx.compose.runtime.*
1412import androidx.compose.ui.Modifier
1513import androidx.compose.ui.draw.clip
1614import androidx.compose.ui.draw.shadow
@@ -22,10 +20,10 @@ import androidx.compose.ui.res.imageResource
2220import androidx.compose.ui.text.font.FontWeight
2321import androidx.compose.ui.unit.dp
2422import androidx.compose.ui.unit.sp
23+ import com.smarttoolfactory.composeimage.ContentScaleSelectionMenu
2524import com.smarttoolfactory.composeimage.R
2625import com.smarttoolfactory.image.beforeafter.BeforeAfterImage
2726import com.smarttoolfactory.image.beforeafter.ContentOrder
28- import com.smarttoolfactory.image.beforeafter.Label
2927import kotlin.math.roundToInt
3028
3129@Composable
@@ -45,19 +43,19 @@ fun BeforeAfterImageDemo() {
4543 )
4644
4745 val imageBefore2 = ImageBitmap .imageResource(
48- LocalContext .current.resources, R .drawable.image_before_after_elements_a
46+ LocalContext .current.resources, R .drawable.landscape5_before
4947 )
5048
5149 val imageAfter2 = ImageBitmap .imageResource(
52- LocalContext .current.resources, R .drawable.image_before_after_elements_b
50+ LocalContext .current.resources, R .drawable.landscape5
5351 )
5452
5553 val imageBefore3 = ImageBitmap .imageResource(
56- LocalContext .current.resources, R .drawable.landscape5_before
54+ LocalContext .current.resources, R .drawable.image_before_after_elements_a
5755 )
5856
5957 val imageAfter3 = ImageBitmap .imageResource(
60- LocalContext .current.resources, R .drawable.landscape5
58+ LocalContext .current.resources, R .drawable.image_before_after_elements_b
6159 )
6260
6361 Text (
@@ -68,6 +66,12 @@ fun BeforeAfterImageDemo() {
6866 modifier = Modifier .padding(8 .dp)
6967 )
7068
69+ var contentScale by remember { mutableStateOf(ContentScale .FillBounds ) }
70+ ContentScaleSelectionMenu (contentScale = contentScale) {
71+ contentScale = it
72+ }
73+
74+
7175 Text (
7276 text = " Order" ,
7377 fontSize = 16 .sp,
@@ -76,54 +80,28 @@ fun BeforeAfterImageDemo() {
7680 modifier = Modifier .padding(8 .dp)
7781 )
7882
79- Box {
80- BeforeAfterImage (
81- modifier = Modifier
82- .shadow(1 .dp, RoundedCornerShape (10 .dp))
83- .fillMaxWidth()
84- .aspectRatio(4 / 3f ),
85- beforeImage = imageBefore,
86- afterImage = imageAfter,
87- contentScale = ContentScale .FillBounds
88- )
89- Label (
90- text = " BEFORE" ,
91- modifier = Modifier
92- .padding(8 .dp)
93- .align(Alignment .TopStart )
94- )
95- Label (
96- text = " AFTER" , modifier = Modifier
97- .padding(8 .dp)
98- .align(Alignment .TopEnd )
99- )
100- }
83+ BeforeAfterImage (
84+ modifier = Modifier
85+ .shadow(1 .dp, RoundedCornerShape (10 .dp))
86+ .fillMaxWidth()
87+ .aspectRatio(4 / 3f ),
88+ beforeImage = imageBefore,
89+ afterImage = imageAfter,
90+ contentScale = contentScale
91+ )
10192
10293 Spacer (modifier = Modifier .height(40 .dp))
10394
104- Box {
105- BeforeAfterImage (
106- modifier = Modifier
107- .shadow(1 .dp, RoundedCornerShape (10 .dp))
108- .fillMaxWidth()
109- .aspectRatio(4 / 3f ),
110- beforeImage = imageBefore,
111- afterImage = imageAfter,
112- contentOrder = ContentOrder .AfterBefore ,
113- contentScale = ContentScale .FillBounds
114- )
115- Label (
116- text = " AFTER" ,
117- modifier = Modifier
118- .padding(8 .dp)
119- .align(Alignment .TopStart )
120- )
121- Label (
122- text = " BEFORE" , modifier = Modifier
123- .padding(8 .dp)
124- .align(Alignment .TopEnd )
125- )
126- }
95+ BeforeAfterImage (
96+ modifier = Modifier
97+ .shadow(1 .dp, RoundedCornerShape (10 .dp))
98+ .fillMaxWidth()
99+ .aspectRatio(4 / 3f ),
100+ beforeImage = imageBefore,
101+ afterImage = imageAfter,
102+ contentOrder = ContentOrder .AfterBefore ,
103+ contentScale = contentScale
104+ )
127105
128106 Spacer (modifier = Modifier .height(40 .dp))
129107 Text (
@@ -134,29 +112,16 @@ fun BeforeAfterImageDemo() {
134112 modifier = Modifier .padding(8 .dp)
135113 )
136114
137- Box {
138- BeforeAfterImage (
139- modifier = Modifier
140- .shadow(1 .dp, RoundedCornerShape (10 .dp))
141- .fillMaxWidth()
142- .aspectRatio(4 / 3f ),
143- beforeImage = imageBefore3,
144- afterImage = imageAfter3,
145- contentOrder = ContentOrder .AfterBefore ,
146- contentScale = ContentScale .FillBounds
147- )
148- Label (
149- text = " AFTER" ,
150- modifier = Modifier
151- .padding(8 .dp)
152- .align(Alignment .TopStart )
153- )
154- Label (
155- text = " BEFORE" , modifier = Modifier
156- .padding(8 .dp)
157- .align(Alignment .TopEnd )
158- )
159- }
115+ BeforeAfterImage (
116+ modifier = Modifier
117+ .shadow(1 .dp, RoundedCornerShape (10 .dp))
118+ .fillMaxWidth()
119+ .aspectRatio(4 / 3f ),
120+ beforeImage = imageBefore2,
121+ afterImage = imageAfter2,
122+ contentOrder = ContentOrder .AfterBefore ,
123+ contentScale = contentScale
124+ )
160125
161126
162127 Spacer (modifier = Modifier .height(40 .dp))
@@ -189,11 +154,13 @@ fun BeforeAfterImageDemo() {
189154 .border(3 .dp, Color (0xffE91E63 ), RoundedCornerShape (10 .dp))
190155 .fillMaxWidth()
191156 .aspectRatio(4 / 3f ),
192- beforeImage = imageBefore2 ,
193- afterImage = imageAfter2 ,
157+ beforeImage = imageBefore3 ,
158+ afterImage = imageAfter3 ,
194159 progress = progress,
195160 onProgressChange = {},
196- contentScale = ContentScale .FillBounds
161+ contentScale = contentScale,
162+ beforeLabel = {},
163+ afterLabel = {},
197164 ) {
198165 Text (
199166 " ${(progress).roundToInt()} %" ,
0 commit comments