Skip to content

Commit f860ec8

Browse files
update CropOutlineContainer
1 parent 497289c commit f860ec8

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.smarttoolfactory.cropper.model
22

3-
import androidx.compose.runtime.Immutable
4-
53
/**
64
* Interface for containing multiple [CropOutline]s, currently selected item and index
75
* for displaying on settings UI
@@ -11,67 +9,62 @@ interface CropOutlineContainer<O : CropOutline> {
119
val outlines: List<O>
1210
val selectedItem: O
1311
get() = outlines[selectedIndex]
12+
val size: Int
13+
get() = outlines.size
1414
}
1515

1616
/**
1717
* Container for [RectCropShape]
1818
*/
19-
@Immutable
20-
class RectOutlineContainer(
19+
data class RectOutlineContainer(
2120
override var selectedIndex: Int = 0,
2221
override val outlines: List<RectCropShape>
2322
) : CropOutlineContainer<RectCropShape>
2423

2524
/**
2625
* Container for [RoundedCornerCropShape]s
2726
*/
28-
@Immutable
29-
class RoundedRectOutlineContainer(
27+
data class RoundedRectOutlineContainer(
3028
override var selectedIndex: Int = 0,
3129
override val outlines: List<RoundedCornerCropShape>
3230
) : CropOutlineContainer<RoundedCornerCropShape>
3331

3432
/**
3533
* Container for [CutCornerCropShape]s
3634
*/
37-
@Immutable
38-
class CutCornerRectOutlineContainer(
35+
data class CutCornerRectOutlineContainer(
3936
override var selectedIndex: Int = 0,
4037
override val outlines: List<CutCornerCropShape>
4138
) : CropOutlineContainer<CutCornerCropShape>
4239

4340
/**
4441
* Container for [OvalCropShape]s
4542
*/
46-
@Immutable
47-
class OvalOutlineContainer(
43+
data class OvalOutlineContainer(
4844
override var selectedIndex: Int = 0,
4945
override val outlines: List<OvalCropShape>
5046
) : CropOutlineContainer<OvalCropShape>
5147

5248
/**
5349
* Container for [PolygonCropShape]s
5450
*/
55-
@Immutable
56-
class PolygonOutlineContainer(
51+
data class PolygonOutlineContainer(
5752
override var selectedIndex: Int = 0,
5853
override val outlines: List<PolygonCropShape>
5954
) : CropOutlineContainer<PolygonCropShape>
6055

6156
/**
6257
* Container for [CustomPathOutline]s
6358
*/
64-
@Immutable
65-
class CustomOutlineContainer(
59+
data class CustomOutlineContainer(
6660
override var selectedIndex: Int = 0,
6761
override val outlines: List<CustomPathOutline>
6862
) : CropOutlineContainer<CustomPathOutline>
6963

7064
/**
7165
* Container for [ImageMaskOutline]s
7266
*/
73-
@Immutable
74-
class ImageMaskOutlineContainer(
67+
data class ImageMaskOutlineContainer(
7568
override var selectedIndex: Int = 0,
7669
override val outlines: List<ImageMaskOutline>
7770
) : CropOutlineContainer<ImageMaskOutline>

cropper/src/main/java/com/smarttoolfactory/cropper/settings/frames/edit/PolygonCropShapeEdit.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ internal fun PolygonCropShapeEdit(
4545
)
4646
}
4747

48-
val shape by remember(sides, angle) {
49-
derivedStateOf {
50-
createPolygonShape(sides = sides, angle)
51-
}
48+
var shape by remember {
49+
mutableStateOf(
50+
polygonCropShape.shape
51+
)
5252
}
5353

5454
onChange(
@@ -87,16 +87,20 @@ internal fun PolygonCropShapeEdit(
8787

8888
Slider(
8989
value = sides.toFloat(),
90-
onValueChange = { sides = it.toInt() },
90+
onValueChange = {
91+
sides = it.toInt()
92+
shape = createPolygonShape(sides = sides, angle)
93+
},
9194
valueRange = 3f..15f,
9295
steps = 10
9396
)
9497
Slider(
9598
value = angle,
96-
onValueChange = { angle = it },
99+
onValueChange = {
100+
angle = it
101+
shape = createPolygonShape(sides = sides, degrees = angle)
102+
},
97103
valueRange = 0f..360f
98104
)
99-
100-
101105
}
102106
}

0 commit comments

Comments
 (0)