Skip to content

Commit

Permalink
handle cornerRadius 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun1012 committed Mar 23, 2023
1 parent 0e1e7b2 commit a94fa35
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import com.smarttoolfactory.composecropper.preferences.CropStyleSelectionMenu
import com.smarttoolfactory.composecropper.preferences.PropertySelectionSheet
import com.smarttoolfactory.composecropper.ui.theme.ComposeCropperTheme
import com.smarttoolfactory.cropper.ImageCropper
import com.smarttoolfactory.cropper.model.CornerRadiusProperties
import com.smarttoolfactory.cropper.model.OutlineType
import com.smarttoolfactory.cropper.model.RectCropShape
import com.smarttoolfactory.cropper.model.RoundedCornerCropShape
import com.smarttoolfactory.cropper.settings.*
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -65,14 +67,16 @@ fun ImageCropDemo() {
)
}

val handleSize: Float = LocalDensity.current.run { 20.dp.toPx() }
val handleSize = LocalDensity.current.run { 14.dp.toPx() }
val cornerSize = LocalDensity.current.run { 8.dp.toPx() }
val corner = CornerRadiusProperties(radius = cornerSize)

var cropProperties by remember {
mutableStateOf(
CropDefaults.properties(
cropOutlineProperty = CropOutlineProperty(
OutlineType.Rect,
RectCropShape(0, "Rect")
outlineType = OutlineType.RoundedRect,
cropOutline = RoundedCornerCropShape(0, "RoundRect", cornerRadius = corner)
),
handleSize = handleSize
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,48 @@ internal fun CutCornerCropShapeEdit(
cutCornerCropShape.cornerRadius
}

var topStartPercent by remember {
var topStart by remember {
mutableStateOf(
cornerRadius.topStartPercent.toFloat()
cornerRadius.topStart
)
}

var topEndPercent by remember {
var topEnd by remember {
mutableStateOf(
cornerRadius.topEndPercent.toFloat()
cornerRadius.topEnd.toFloat()
)
}

var bottomStartPercent by remember {
var bottomStart by remember {
mutableStateOf(
cornerRadius.bottomStartPercent.toFloat()
cornerRadius.bottomStart.toFloat()
)
}

var bottomEndPercent by remember {
var bottomEnd by remember {
mutableStateOf(
cornerRadius.bottomEndPercent.toFloat()
cornerRadius.bottomEnd.toFloat()
)
}

val shape by remember {
derivedStateOf {
CutCornerShape(
topStartPercent = topStartPercent.toInt(),
topEndPercent = topEndPercent.toInt(),
bottomStartPercent = bottomStartPercent.toInt(),
bottomEndPercent = bottomEndPercent.toInt()
topStart = topStart,
topEnd = topEnd,
bottomStart = bottomStart,
bottomEnd = bottomEnd
)
}
}

onChange(
cutCornerCropShape.copy(
cornerRadius = CornerRadiusProperties(
topStartPercent = topStartPercent.toInt(),
topEndPercent = topEndPercent.toInt(),
bottomStartPercent = bottomStartPercent.toInt(),
bottomEndPercent = bottomEndPercent.toInt()
topStart = topStart,
topEnd = topEnd,
bottomStart = bottomStart,
bottomEnd = bottomEnd
),
title = newTitle,
shape = shape
Expand Down Expand Up @@ -105,31 +105,31 @@ internal fun CutCornerCropShapeEdit(
Spacer(modifier = Modifier.height(10.dp))

SliderWithValueSelection(
value = topStartPercent,
value = topStart,
title = "Top Start",
text = "${(topStartPercent * 10f).roundToInt() / 10f}%",
onValueChange = { topStartPercent = it },
text = "${(topStart * 10f).roundToInt() / 10f}%",
onValueChange = { topStart = it },
valueRange = 0f..100f
)
SliderWithValueSelection(
value = topEndPercent,
value = topEnd,
title = "Top End",
text = "${(topEndPercent * 10f).roundToInt() / 10f}%",
onValueChange = { topEndPercent = it },
text = "${(topEnd * 10f).roundToInt() / 10f}%",
onValueChange = { topEnd = it },
valueRange = 0f..100f
)
SliderWithValueSelection(
value = bottomStartPercent,
value = bottomStart,
title = "Bottom Start",
text = "${(bottomStartPercent * 10f).roundToInt() / 10f}%",
onValueChange = { bottomStartPercent = it },
text = "${(bottomStart * 10f).roundToInt() / 10f}%",
onValueChange = { bottomStart = it },
valueRange = 0f..100f
)
SliderWithValueSelection(
value = bottomEndPercent,
value = bottomEnd,
title = "Bottom End",
text = "${(bottomEndPercent * 10f).roundToInt() / 10f}%",
onValueChange = { bottomEndPercent = it },
text = "${(bottomEnd * 10f).roundToInt() / 10f}%",
onValueChange = { bottomEnd = it },
valueRange = 0f..100f
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,48 @@ internal fun RoundedCornerCropShapeEdit(
roundedCornerCropShape.cornerRadius
}

var topStartPercent by remember {
var topStart by remember {
mutableStateOf(
cornerRadius.topStartPercent.toFloat()
cornerRadius.topStart
)
}

var topEndPercent by remember {
var topEnd by remember {
mutableStateOf(
cornerRadius.topEndPercent.toFloat()
cornerRadius.topEnd
)
}

var bottomStartPercent by remember {
var bottomStart by remember {
mutableStateOf(
cornerRadius.bottomStartPercent.toFloat()
cornerRadius.bottomStart
)
}

var bottomEndPercent by remember {
var bottomEnd by remember {
mutableStateOf(
cornerRadius.bottomEndPercent.toFloat()
cornerRadius.bottomEnd
)
}

val shape by remember {
derivedStateOf {
RoundedCornerShape(
topStartPercent = topStartPercent.toInt(),
topEndPercent = topEndPercent.toInt(),
bottomStartPercent = bottomStartPercent.toInt(),
bottomEndPercent = bottomEndPercent.toInt()
topStart = topStart,
topEnd = topEnd,
bottomStart = bottomStart,
bottomEnd = bottomEnd
)
}
}

onChange(
roundedCornerCropShape.copy(
cornerRadius = CornerRadiusProperties(
topStartPercent = topStartPercent.toInt(),
topEndPercent = topEndPercent.toInt(),
bottomStartPercent = bottomStartPercent.toInt(),
bottomEndPercent = bottomEndPercent.toInt()
topStart = topStart,
topEnd = topEnd,
bottomStart = bottomStart,
bottomEnd = bottomEnd
),
title = newTitle,
shape = shape
Expand Down Expand Up @@ -105,31 +105,31 @@ internal fun RoundedCornerCropShapeEdit(
Spacer(modifier=Modifier.height(10.dp))

SliderWithValueSelection(
value = topStartPercent,
value = topStart,
title = "Top Start",
text = "${(topStartPercent * 10f).roundToInt() / 10f}%",
onValueChange = { topStartPercent = it },
text = "${(topStart * 10f).roundToInt() / 10f}%",
onValueChange = { topStart = it },
valueRange = 0f..100f
)
SliderWithValueSelection(
value = topEndPercent,
value = topEnd,
title = "Top End",
text = "${(topEndPercent * 10f).roundToInt() / 10f}%",
onValueChange = { topEndPercent = it },
text = "${(topEnd * 10f).roundToInt() / 10f}%",
onValueChange = { topEnd = it },
valueRange = 0f..100f
)
SliderWithValueSelection(
value = bottomStartPercent,
value = bottomStart,
title = "Bottom Start",
text = "${(bottomStartPercent * 10f).roundToInt() / 10f}%",
onValueChange = { bottomStartPercent = it },
text = "${(bottomStart * 10f).roundToInt() / 10f}%",
onValueChange = { bottomStart = it },
valueRange = 0f..100f
)
SliderWithValueSelection(
value = bottomEndPercent,
value = bottomEnd,
title = "Bottom End",
text = "${(bottomEndPercent * 10f).roundToInt() / 10f}%",
onValueChange = { bottomEndPercent = it },
text = "${(bottomEnd * 10f).roundToInt() / 10f}%",
onValueChange = { bottomEnd = it },
valueRange = 0f..100f
)
}
Expand Down
Loading

0 comments on commit a94fa35

Please sign in to comment.