diff --git a/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt b/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt index 80431dc..71c3a48 100644 --- a/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt +++ b/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt @@ -80,18 +80,14 @@ class PhotoEditorViewModel( update { it.copy(rotationDegrees = it.rotationDegrees + delta) } } - /** 进入裁剪模式:仅在尚未启用时初始化为默认居中区域,已启用则保留当前框。 */ - fun enterCrop() { + /** 开启/关闭裁剪。开启时使用默认居中 4:3 裁剪框。 */ + fun toggleCrop() { update { - if (it.cropEnabled) it - else it.copy(cropLeft = 0.1f, cropTop = 0.1f, cropRight = 0.9f, cropBottom = 0.9f) - } - } - - /** 退出裁剪模式:清空裁剪框(不应用裁剪)。 */ - fun exitCrop() { - update { - it.copy(cropLeft = null, cropRight = null, cropTop = 0f, cropBottom = 1f) + if (it.cropEnabled) { + it.copy(cropLeft = null, cropRight = null, cropTop = 0f, cropBottom = 1f) + } else { + it.copy(cropLeft = 0.1f, cropTop = 0.1f, cropRight = 0.9f, cropBottom = 0.9f) + } } } diff --git a/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt b/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt index 33fb1a4..a68e8c4 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt @@ -97,14 +97,6 @@ fun PhotoEditorScreen( var activeTab by remember { mutableStateOf(EditTab.ROTATE) } val savedPath = state.savedPath - // 切到裁剪 tab 自动进入裁剪模式;切走则退出(不应用裁剪) - LaunchedEffect(activeTab, state.editorState) { - when (activeTab) { - EditTab.CROP -> viewModel.enterCrop() - else -> viewModel.exitCrop() - } - } - if (savedPath != null) { LaunchedEffect(savedPath) { onSaved(savedPath) } } @@ -167,6 +159,7 @@ fun PhotoEditorScreen( activeTab = activeTab, onTabChange = { activeTab = it }, onRotate = viewModel::rotate, + onCropToggle = viewModel::toggleCrop, onApplyCrop = viewModel::applyCrop, onCropChange = viewModel::updateCrop, onAddPoint = viewModel::addStrokePoint, @@ -191,6 +184,7 @@ private fun EditorBody( activeTab: EditTab, onTabChange: (EditTab) -> Unit, onRotate: (Int) -> Unit, + onCropToggle: () -> Unit, onApplyCrop: () -> Unit, onCropChange: (Float, Float, Float, Float) -> Unit, onAddPoint: (Offset) -> Unit, @@ -255,6 +249,7 @@ private fun EditorBody( mode = activeTab, state = state, onRotate = onRotate, + onCropToggle = onCropToggle, onApplyCrop = onApplyCrop, onUndoStroke = onUndoStroke, onStrokeColorChange = onStrokeColorChange, @@ -522,6 +517,7 @@ private fun ToolBar( mode: EditTab, state: PhotoEditorState, onRotate: (Int) -> Unit, + onCropToggle: () -> Unit, onApplyCrop: () -> Unit, onUndoStroke: () -> Unit, onStrokeColorChange: (Color) -> Unit, @@ -541,10 +537,16 @@ private fun ToolBar( Icon(Icons.Filled.RotateRight, contentDescription = "右转 90°") } } - EditTab.CROP -> { + EditTab.CROP -> if (state.cropEnabled) { + // 已进入裁剪模式:✓ 确认裁剪(烘焙到源图) FilledIconButton(onClick = onApplyCrop) { Icon(Icons.Filled.Done, contentDescription = "确认裁剪") } + } else { + // 未进入:点击进入裁剪模式 + FilledIconButton(onClick = onCropToggle) { + Icon(Icons.Filled.Crop, contentDescription = "进入裁剪") + } } EditTab.HANDWRITE -> { IconButton(onClick = onUndoStroke, enabled = state.strokes.isNotEmpty()) {