diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/ColorGradingPanel.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/ColorGradingPanel.kt index 262da152..b989d001 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/ColorGradingPanel.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/ColorGradingPanel.kt @@ -7,12 +7,15 @@ import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Text @@ -38,6 +41,7 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.hinnka.mycamera.R @@ -152,69 +156,88 @@ fun ColorGradingPanel( ) } - GradingColorWheel( - hue = selected.hue, - amount = selected.amount, - contentDescription = selectedLabel, - onSelectionChange = { hue, amount -> - onParamsChange(currentParams.withSelection(selectedRange, hue, amount)) - }, - onReset = { - onParamsChange(currentParams.withSelection(selectedRange, 0f, 0f)) - }, - modifier = Modifier.size(184.dp), - ) + BoxWithConstraints(Modifier.fillMaxWidth()) { + val wheelWidth = minOf(maxWidth * 0.44f, 160.dp) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(16.dp), + verticalAlignment = Alignment.Top, + ) { + Column( + modifier = Modifier.width(wheelWidth), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(7.dp), + ) { + GradingColorWheel( + hue = selected.hue, + amount = selected.amount, + contentDescription = selectedLabel, + onSelectionChange = { hue, amount -> + onParamsChange(currentParams.withSelection(selectedRange, hue, amount)) + }, + onReset = { + onParamsChange(currentParams.withSelection(selectedRange, 0f, 0f)) + }, + modifier = Modifier.fillMaxWidth().aspectRatio(1f), + ) - Text( - text = String.format( - java.util.Locale.getDefault(), - "%.1f · %.1f", - selected.hue.coerceIn(0f, 1f) * 10f, - selected.amount.coerceIn(0f, 1f) * 10f, - ), - color = if (selected.amount > 0.001f) selectedColor else Color.White.copy(alpha = 0.48f), - fontSize = 11.sp, - fontWeight = FontWeight.SemiBold, - fontFamily = FontFamily.Monospace, - ) + Text( + text = String.format( + java.util.Locale.getDefault(), + "%.1f · %.1f", + selected.hue.coerceIn(0f, 1f) * 10f, + selected.amount.coerceIn(0f, 1f) * 10f, + ), + color = if (selected.amount > 0.001f) selectedColor else Color.White.copy(alpha = 0.48f), + fontSize = 11.sp, + fontWeight = FontWeight.SemiBold, + fontFamily = FontFamily.Monospace, + ) + } + Column( + modifier = Modifier.weight(1f), + verticalArrangement = Arrangement.spacedBy(7.dp), + ) { + GradingSliderControl( + label = stringResource(R.string.recipe_grading_luminance), + value = selected.luminance * 10f, + valueRange = -10f..10f, + defaultValue = 0f, + valueText = formatSignedValue(selected.luminance * 10f), + onValueChange = { + onParamsChange( + currentParams.withLuminance(selectedRange, (it / 10f).coerceIn(-1f, 1f)) + ) + }, + ) - GradingSliderRow( - label = stringResource(R.string.recipe_grading_luminance), - value = selected.luminance * 10f, - valueRange = -10f..10f, - defaultValue = 0f, - valueText = formatSignedValue(selected.luminance * 10f), - onValueChange = { - onParamsChange( - currentParams.withLuminance(selectedRange, (it / 10f).coerceIn(-1f, 1f)) - ) - }, - ) - - GradingSliderRow( - label = stringResource(R.string.recipe_grading_balance), - value = currentParams.gradingBalance * 10f, - valueRange = -10f..10f, - defaultValue = 0f, - valueText = formatSignedValue(currentParams.gradingBalance * 10f), - onValueChange = { - onParamsChange(currentParams.copy(gradingBalance = (it / 10f).coerceIn(-1f, 1f))) - }, - ) - GradingSliderRow( - label = stringResource(R.string.recipe_grading_blending), - value = currentParams.gradingBlending * 10f, - valueRange = 0f..10f, - defaultValue = 5f, - valueText = String.format( - java.util.Locale.getDefault(), - "%.1f", - currentParams.gradingBlending.coerceIn(0f, 1f) * 10f, - ), - onValueChange = { - onParamsChange(currentParams.copy(gradingBlending = (it / 10f).coerceIn(0f, 1f))) - }, - ) + GradingSliderControl( + label = stringResource(R.string.recipe_grading_balance), + value = currentParams.gradingBalance * 10f, + valueRange = -10f..10f, + defaultValue = 0f, + valueText = formatSignedValue(currentParams.gradingBalance * 10f), + onValueChange = { + onParamsChange(currentParams.copy(gradingBalance = (it / 10f).coerceIn(-1f, 1f))) + }, + ) + GradingSliderControl( + label = stringResource(R.string.recipe_grading_blending), + value = currentParams.gradingBlending * 10f, + valueRange = 0f..10f, + defaultValue = 5f, + valueText = String.format( + java.util.Locale.getDefault(), + "%.1f", + currentParams.gradingBlending.coerceIn(0f, 1f) * 10f, + ), + onValueChange = { + onParamsChange(currentParams.copy(gradingBlending = (it / 10f).coerceIn(0f, 1f))) + }, + ) + } + } + } } } @@ -248,7 +271,8 @@ private fun GradingColorWheel( center.x + cos(markerAngle) * currentAmount * radius, center.y + sin(markerAngle) * currentAmount * radius, ) - if ((position - markerCenter).getDistance() <= 24.dp.toPx()) { + val markerHitRadius = minOf(24.dp.toPx(), minOf(size.width, size.height) * (24f / 184f)) + if ((position - markerCenter).getDistance() <= markerHitRadius) { return } val dx = position.x - center.x @@ -283,9 +307,8 @@ private fun GradingColorWheel( sin(angle) * currentAmount * radius, ) val pointerSelection = position - center - selectionStart = if ( - (pointerSelection - currentSelection).getDistance() <= 24.dp.toPx() - ) { + val markerHitRadius = minOf(24.dp.toPx(), minOf(size.width, size.height) * (24f / 184f)) + selectionStart = if ((pointerSelection - currentSelection).getDistance() <= markerHitRadius) { currentSelection } else { pointerSelection @@ -317,6 +340,7 @@ private fun GradingColorWheel( ) { val inset = 8.dp.toPx() val diameter = minOf(size.width, size.height) - inset * 2f + if (diameter <= 0f) return@Canvas val center = Offset(size.width / 2f, size.height / 2f) val radius = diameter / 2f val wheelTopLeft = Offset(center.x - radius, center.y - radius) @@ -453,7 +477,7 @@ private fun GradingTonePreview( } @Composable -private fun GradingSliderRow( +private fun GradingSliderControl( label: String, value: Float, valueRange: ClosedFloatingPointRange, @@ -461,21 +485,35 @@ private fun GradingSliderRow( valueText: String, onValueChange: (Float) -> Unit, ) { - Row( + Column( modifier = Modifier .fillMaxWidth() - .height(36.dp) .background(Color.White.copy(alpha = 0.02f), RoundedCornerShape(6.dp)) - .padding(horizontal = 8.dp), - verticalAlignment = Alignment.CenterVertically, + .padding(horizontal = 8.dp, vertical = 4.dp), + verticalArrangement = Arrangement.spacedBy(2.dp), ) { - Text( - text = label, - color = Color.White.copy(alpha = 0.66f), - fontSize = 11.sp, - modifier = Modifier.size(width = 58.dp, height = 20.dp), - maxLines = 1, - ) + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = label, + color = Color.White.copy(alpha = 0.66f), + fontSize = 11.sp, + modifier = Modifier.weight(1f), + overflow = TextOverflow.Ellipsis, + maxLines = 1, + ) + Text( + text = valueText, + color = Color.White.copy(alpha = 0.72f), + fontSize = 10.sp, + fontWeight = FontWeight.Medium, + textAlign = TextAlign.End, + fontFamily = FontFamily.Monospace, + maxLines = 1, + ) + } CustomSlider( value = value, onValueChange = onValueChange, @@ -485,19 +523,6 @@ private fun GradingSliderRow( inactiveTrackColor = Color.White.copy(alpha = 0.14f), thumbColor = Color.White, thumbRadius = 7.dp, - modifier = Modifier - .weight(1f) - .padding(horizontal = 8.dp), - ) - Text( - text = valueText, - color = Color.White.copy(alpha = 0.72f), - fontSize = 10.sp, - fontWeight = FontWeight.Medium, - textAlign = TextAlign.End, - fontFamily = FontFamily.Monospace, - modifier = Modifier.size(width = 42.dp, height = 20.dp), - maxLines = 1, ) } } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt index e354a989..8ec832c1 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt @@ -132,6 +132,7 @@ fun ColorRecipePanel( onEffectsChange: ((EffectParams) -> Unit)? = null, headerControls: (@Composable () -> Unit)? = null, containerShape: Shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), + containerColor: Color = Color(0xF2121316), onResetAll: (() -> Unit)? = null, modifier: Modifier = Modifier ) { @@ -385,13 +386,10 @@ fun ColorRecipePanel( modifier = Modifier .fillMaxWidth() .clip(containerShape) - .background( - if (isCurveDragging) Color.Transparent - else Color(0xF9121316).copy(alpha = 0.95f) - ) + .background(if (isCurveDragging) Color.Transparent else containerColor) .border( 0.5.dp, - Color.White.copy(alpha = if (isCurveDragging) 0f else 0.08f), + Color.White.copy(alpha = if (isCurveDragging || containerColor == Color.Transparent) 0f else 0.08f), containerShape ) .padding(start = 14.dp, top = 12.dp, end = 14.dp, bottom = 12.dp), @@ -504,8 +502,6 @@ fun ColorRecipePanel( onTabReset = ::resetTab, ) - Spacer(modifier = Modifier.height(4.dp)) - when (selectedTab) { RecipePanelTab.CURVE -> { CurveEditorPanel( @@ -523,7 +519,6 @@ fun ColorRecipePanel( selectedSection = selectedColorSection, onSectionSelected = { selectedColorSection = it } ) - Spacer(modifier = Modifier.height(4.dp)) when (selectedColorSection) { ColorPanelSection.CALIBRATION -> { ColorRingTabs( @@ -539,7 +534,6 @@ fun ColorRecipePanel( } } ) - Spacer(modifier = Modifier.height(4.dp)) Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { calibrationGroups[selectedCalibrationTabIndex].second.forEach { param -> RecipeIntegerParamItem( @@ -564,7 +558,6 @@ fun ColorRecipePanel( onTabSelected = { selectedLchTabIndex = it }, getColor = { getLchTabColor(it) } ) - Spacer(modifier = Modifier.height(4.dp)) Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { lchGroups[selectedLchTabIndex].second.forEach { param -> RecipeIntegerParamItem( diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/CurveEditorPanel.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/CurveEditorPanel.kt index 7bf4e6d4..81bf5831 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/CurveEditorPanel.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/CurveEditorPanel.kt @@ -54,27 +54,50 @@ fun CurveEditorPanel( onCurveChange: (CurveChannel, FloatArray?) -> Unit, imageHistogram: ImageHistogram? = null, onDragStateChange: (Boolean) -> Unit = {}, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { var activeChannel by remember { mutableStateOf(CurveChannel.MASTER) } var visibleChannels by remember { mutableStateOf(CurveChannel.entries.toSet()) } - Column( + val currentPoints = currentParams.getCurvePoints(activeChannel) + val inactiveCurves = visibleChannels + .asSequence() + .filter { it != activeChannel } + .map { channel -> + DisplayCurve( + points = currentParams.getCurvePoints(channel) ?: identityPoints(), + color = channel.color, + ) + } + .toList() + + Row( modifier = modifier.fillMaxWidth(), - verticalArrangement = Arrangement.spacedBy(6.dp), - horizontalAlignment = Alignment.CenterHorizontally, + horizontalArrangement = Arrangement.Absolute.spacedBy(6.dp, Alignment.CenterHorizontally), + verticalAlignment = Alignment.CenterVertically, ) { - val currentPoints = currentParams.getCurvePoints(activeChannel) - val inactiveCurves = visibleChannels - .asSequence() - .filter { it != activeChannel } - .map { channel -> - DisplayCurve( - points = currentParams.getCurvePoints(channel) ?: identityPoints(), - color = channel.color, + Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { + CurveChannel.entries.forEach { channel -> + CurveChannelButton( + channel = channel, + isVisible = channel in visibleChannels, + isActive = activeChannel == channel, + onClick = { + when { + channel !in visibleChannels -> { + visibleChannels = visibleChannels + channel + activeChannel = channel + } + activeChannel != channel -> activeChannel = channel + visibleChannels.size > 1 -> { + visibleChannels = visibleChannels - channel + activeChannel = visibleChannels.first() + } + } + }, ) } - .toList() + } key(activeChannel) { CurveCanvas( @@ -93,60 +116,41 @@ fun CurveEditorPanel( } onCurveChange(activeChannel, arr) }, - modifier = Modifier.fillMaxWidth(), + modifier = Modifier + .widthIn(max = 288.dp) + .fillMaxWidth(), ) } + } +} - // 参考移动端修图应用,通道放到大画布下方,不再挤占横向编辑空间。 - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 24.dp), - horizontalArrangement = Arrangement.SpaceEvenly, - verticalAlignment = Alignment.CenterVertically, - ) { - CurveChannel.entries.forEach { channel -> - val isVisible = channel in visibleChannels - val isActive = activeChannel == channel - Box( - modifier = Modifier - .size(40.dp) - .clip(RoundedCornerShape(8.dp)) - .background( - when { - isActive -> channel.color.copy(alpha = 0.28f) - isVisible -> channel.color.copy(alpha = 0.12f) - else -> Color.Transparent - } - ) - .clickable { - when { - !isVisible -> { - visibleChannels = visibleChannels + channel - activeChannel = channel - } - !isActive -> activeChannel = channel - visibleChannels.size > 1 -> { - visibleChannels = visibleChannels - channel - activeChannel = visibleChannels.first() - } - } - }, - contentAlignment = Alignment.Center, - ) { - Text( - text = channel.label, - color = if (isVisible) { - channel.color - } else { - channel.color.copy(alpha = 0.45f) - }, - fontSize = 12.sp, - fontWeight = if (isActive) FontWeight.Bold else FontWeight.Normal, - ) +@Composable +private fun CurveChannelButton( + channel: CurveChannel, + isVisible: Boolean, + isActive: Boolean, + onClick: () -> Unit, +) { + Box( + modifier = Modifier + .size(40.dp) + .clip(RoundedCornerShape(8.dp)) + .background( + when { + isActive -> channel.color.copy(alpha = 0.28f) + isVisible -> channel.color.copy(alpha = 0.12f) + else -> Color.Transparent } - } - } + ) + .clickable(onClick = onClick), + contentAlignment = Alignment.Center, + ) { + Text( + text = channel.label, + color = if (isVisible) channel.color else channel.color.copy(alpha = 0.45f), + fontSize = 12.sp, + fontWeight = if (isActive) FontWeight.Bold else FontWeight.Normal, + ) } } @@ -167,7 +171,7 @@ private fun CurveCanvas( ) { val density = LocalDensity.current val hitThresholdPx = with(density) { 30.dp.toPx() } - val graphInsetPx = with(density) { 16.dp.toPx() } + val graphInsetPx = with(density) { 10.dp.toPx() } // 内部拖动状态;pointerInput key 使用 state 对象引用(稳定) val controlPointsState = remember { mutableStateOf(parsePoints(points)) } @@ -202,7 +206,7 @@ private fun CurveCanvas( var lastTapTime by remember { mutableLongStateOf(0L) } var lastTapIndex by remember { mutableIntStateOf(-1) } - Box(modifier = modifier.padding(vertical = 4.dp)) { + Box(modifier = modifier) { Canvas( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/LiquidGlass.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/LiquidGlass.kt index ed3f8464..aff2b6d6 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/LiquidGlass.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/LiquidGlass.kt @@ -58,7 +58,7 @@ import kotlin.math.floor * glass node is only re-rendered when its backdrop or geometry changes, not when panel content does. * * Capability tiers: API 33+ full lens + highlight; API 31-32 vibrancy with a flat rim; - * API 30 an opaque fallback color without backdrop capture. + * API 30 a fallback tint without backdrop capture. */ @Immutable data class LiquidGlassStyle( @@ -148,14 +148,14 @@ fun LiquidGlassSurface( val backdropPosition = backdrop.positionInRoot val backdropSize = backdrop.size - if (!BACKDROP_SUPPORTED) { + if (!BACKDROP_SUPPORTED || !positionInRoot.isSpecified || !backdropPosition.isSpecified || + backdropSize == IntSize.Zero + ) { return@drawWithCache onDrawBehind { clipRect { drawPath(outline, style.fallbackColor) } } } - if (!positionInRoot.isSpecified || !backdropPosition.isSpecified || - backdropSize == IntSize.Zero || width <= 0f || height <= 0f - ) { + if (width <= 0f || height <= 0f) { return@drawWithCache onDrawBehind {} } @@ -172,7 +172,9 @@ fun LiquidGlassSurface( ceil(captureRect.bottom).toInt() - layerOffset.y, ) if (layerSize.width <= 0 || layerSize.height <= 0) { - return@drawWithCache onDrawBehind {} + return@drawWithCache onDrawBehind { + clipRect { drawPath(outline, style.fallbackColor) } + } } val glassLayer = obtainGraphicsLayer().apply { @@ -249,7 +251,9 @@ private fun glassEffect( } else { vibrancy } - if (shaders == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return blur + if (refractionAmount == 0f || refractionHeight == 0f || shaders == null || + Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU + ) return blur return shaders.lensEffect(blur, shapeOffset, shapeWidth, shapeHeight, radius, bottomRadius, refractionHeight, refractionAmount) } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt index 986d1736..0a343732 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt @@ -198,6 +198,7 @@ fun LutSelector( presetThumbnailInput: com.hinnka.mycamera.lut.PresetThumbnailInput? = null, onEditPreset: ((String) -> Unit)? = null, presetLookActive: Boolean = false, + showHorizontalHeader: Boolean = true, ) { val favoriteText = stringResource(R.string.favorite) val uncategorizedText = stringResource(R.string.uncategorized) @@ -522,112 +523,114 @@ fun LutSelector( verticalArrangement = Arrangement.spacedBy(8.dp) ) { headerContent?.invoke() - // 顶栏第 1 行:当前项名称(居左)+ 操作按钮(编辑 / 新建)与设置图标(居右) - Row( - modifier = Modifier - .fillMaxWidth() - .heightIn(min = 28.dp) - .padding(horizontal = 10.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - when (actualMode) { - LutSelectorMode.Style -> { - val currentLut = availableLuts.find { it.id == activeLutId } - val currentName = if (activeLutId == null || activeLutId == "none") { - stringResource(R.string.none) - } else { - currentLut?.getName() ?: "" - } - Text( - text = currentName, - color = Color.White, - fontSize = 13.sp, - fontWeight = FontWeight.Bold, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.weight(1f).padding(end = 8.dp).basicMarquee(), - style = LocalTextStyle.current.copy(shadow = ViewfinderTextShadow) - ) - - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(6.dp) - ) { - if (editActiveLut != null) { - LutEditButton(onClick = editActiveLut) + if (showHorizontalHeader) { + // 顶栏第 1 行:当前项名称(居左)+ 操作按钮(编辑 / 新建)与设置图标(居右) + Row( + modifier = Modifier + .fillMaxWidth() + .heightIn(min = 28.dp) + .padding(horizontal = 10.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + when (actualMode) { + LutSelectorMode.Style -> { + val currentLut = availableLuts.find { it.id == activeLutId } + val currentName = if (activeLutId == null || activeLutId == "none") { + stringResource(R.string.none) + } else { + currentLut?.getName() ?: "" } + Text( + text = currentName, + color = Color.White, + fontSize = 13.sp, + fontWeight = FontWeight.Bold, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f).padding(end = 8.dp).basicMarquee(), + style = LocalTextStyle.current.copy(shadow = ViewfinderTextShadow) + ) - if (onManageClick != null) { - var lastClickTime by remember { mutableLongStateOf(0L) } + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(6.dp) + ) { + if (editActiveLut != null) { + LutEditButton(onClick = editActiveLut) + } + + if (onManageClick != null) { + var lastClickTime by remember { mutableLongStateOf(0L) } + LutPanelIconButton( + imageVector = Icons.Default.Settings, + contentDescription = stringResource(R.string.settings_filter_management), + onClick = { + val currentTime = System.currentTimeMillis() + if (currentTime - lastClickTime > 1000) { + lastClickTime = currentTime + onManageClick(activeLutId ?: "") + } + } + ) + } + } + } + LutSelectorMode.Frame -> { + val currentFrame = availableFrames.find { it.id == currentFrameId } + val currentName = if (currentFrameId == null) stringResource(R.string.none) else (currentFrame?.name ?: "") + Text( + text = currentName, + color = Color.White, + fontSize = 13.sp, + fontWeight = FontWeight.Bold, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f).padding(end = 8.dp).basicMarquee(), + style = LocalTextStyle.current.copy(shadow = ViewfinderTextShadow) + ) + + if (onFrameManagementClick != null) { LutPanelIconButton( imageVector = Icons.Default.Settings, - contentDescription = stringResource(R.string.settings_filter_management), - onClick = { - val currentTime = System.currentTimeMillis() - if (currentTime - lastClickTime > 1000) { - lastClickTime = currentTime - onManageClick(activeLutId ?: "") - } - } + contentDescription = stringResource(R.string.settings_frame_management), + onClick = onFrameManagementClick ) } } - } - LutSelectorMode.Frame -> { - val currentFrame = availableFrames.find { it.id == currentFrameId } - val currentName = if (currentFrameId == null) stringResource(R.string.none) else (currentFrame?.name ?: "") - Text( - text = currentName, - color = Color.White, - fontSize = 13.sp, - fontWeight = FontWeight.Bold, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.weight(1f).padding(end = 8.dp).basicMarquee(), - style = LocalTextStyle.current.copy(shadow = ViewfinderTextShadow) - ) - - if (onFrameManagementClick != null) { - LutPanelIconButton( - imageVector = Icons.Default.Settings, - contentDescription = stringResource(R.string.settings_frame_management), - onClick = onFrameManagementClick - ) - } - } - LutSelectorMode.Presets -> { - val currentPreset = activePreset - val currentName = currentPreset?.let { presetDisplayName(it) }.orEmpty() - Text( - text = if (currentPreset != null && activePresetModified) { - "$currentName*" - } else { - currentName - }, - color = Color.White, - fontSize = 13.sp, - fontWeight = FontWeight.Bold, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.weight(1f).padding(end = 8.dp).basicMarquee(), - style = LocalTextStyle.current.copy(shadow = ViewfinderTextShadow) - ) - - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(6.dp) - ) { - LutPanelPresetActionButton( - text = stringResource(if (activePresetModified) R.string.preset_save_as else R.string.preset_new), - onClick = onCreatePresetClick + LutSelectorMode.Presets -> { + val currentPreset = activePreset + val currentName = currentPreset?.let { presetDisplayName(it) }.orEmpty() + Text( + text = if (currentPreset != null && activePresetModified) { + "$currentName*" + } else { + currentName + }, + color = Color.White, + fontSize = 13.sp, + fontWeight = FontWeight.Bold, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f).padding(end = 8.dp).basicMarquee(), + style = LocalTextStyle.current.copy(shadow = ViewfinderTextShadow) ) - LutPanelIconButton( - imageVector = Icons.Default.Settings, - contentDescription = stringResource(R.string.settings_preset_management), - onClick = onPresetManagementClick - ) + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(6.dp) + ) { + LutPanelPresetActionButton( + text = stringResource(if (activePresetModified) R.string.preset_save_as else R.string.preset_new), + onClick = onCreatePresetClick + ) + + LutPanelIconButton( + imageVector = Icons.Default.Settings, + contentDescription = stringResource(R.string.settings_preset_management), + onClick = onPresetManagementClick + ) + } } } } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/RawEditPanel.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/RawEditPanel.kt index 64fdd5ae..c6e179cf 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/RawEditPanel.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/RawEditPanel.kt @@ -52,7 +52,6 @@ import com.hinnka.mycamera.raw.SpectralFilmSelection import com.hinnka.mycamera.raw.SpectralFilmUiInfo import com.hinnka.mycamera.raw.fotufilm.FotufilmDocument import kotlin.math.roundToInt -import com.hinnka.mycamera.ui.settings.DropdownSettingItem import com.hinnka.mycamera.ui.icons.AppIcons enum class RawEditPanelContentMode { @@ -150,6 +149,7 @@ fun RawEditPanel( contentMode: RawEditPanelContentMode = RawEditPanelContentMode.FULL, hncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, onHncsFilmCurveModeChange: (HncsFilmCurveMode) -> Unit = {}, + compactLayout: Boolean = false, modifier: Modifier = Modifier ) { Column( @@ -207,62 +207,85 @@ fun RawEditPanel( ) if (contentMode == RawEditPanelContentMode.FULL) { - SliderSettingItem( - title = stringResource(R.string.settings_raw_exposure_compensation), - value = rawExposureCompensation, - valueRange = MeteringSystem.RAW_EXPOSURE_MIN_EV..MeteringSystem.RAW_EXPOSURE_MAX_EV, - resetValue = 0f, - onResetValue = onRawExposureCompensationReset, - onValueChange = { - onAdjustmentStart() - onRawExposureCompensationChange(it) - }, - onValueChangeFinished = onAdjustmentEnd - ) - SliderSettingItem( - title = stringResource(R.string.settings_raw_highlights_adjustment), - value = rawHighlightsAdjustment, - valueRange = -1f..1f, - resetValue = 0f, - onValueChange = { - onAdjustmentStart() - onRawHighlightsAdjustmentChange(it) - }, - onValueChangeFinished = onAdjustmentEnd - ) - SliderSettingItem( - title = stringResource(R.string.settings_raw_shadows_adjustment), - value = rawShadowsAdjustment, - valueRange = -1f..1f, - resetValue = 0f, - onValueChange = { - onAdjustmentStart() - onRawShadowsAdjustmentChange(it) - }, - onValueChangeFinished = onAdjustmentEnd - ) - SliderSettingItem( - title = stringResource(R.string.settings_raw_blacks_adjustment), - value = rawBlackPointCorrection, - valueRange = -1f..1f, - resetValue = 0f, - onValueChange = { - onAdjustmentStart() - onRawBlackPointCorrectionChange(it) - }, - onValueChangeFinished = onAdjustmentEnd - ) - SliderSettingItem( - title = stringResource(R.string.settings_raw_whites_adjustment), - value = rawWhitePointCorrection, - valueRange = -1f..1f, - resetValue = 0f, - onValueChange = { - onAdjustmentStart() - onRawWhitePointCorrectionChange(it) - }, - onValueChangeFinished = onAdjustmentEnd - ) + var lightAdjustmentsExpanded by remember { mutableStateOf(false) } + if (compactLayout) { + Row( + modifier = Modifier + .fillMaxWidth() + .heightIn(min = 48.dp) + .clickable(role = Role.Button) { + lightAdjustmentsExpanded = !lightAdjustmentsExpanded + } + .padding(vertical = 8.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text(stringResource(R.string.recipe_tab_light), color = Color.White, fontSize = 16.sp) + Icon( + imageVector = if (lightAdjustmentsExpanded) AppIcons.ExpandLess else AppIcons.ExpandMore, + contentDescription = null, + tint = Color.White.copy(alpha = 0.6f), + ) + } + } + if (!compactLayout || lightAdjustmentsExpanded) { + SliderSettingItem( + title = stringResource(R.string.settings_raw_exposure_compensation), + value = rawExposureCompensation, + valueRange = MeteringSystem.RAW_EXPOSURE_MIN_EV..MeteringSystem.RAW_EXPOSURE_MAX_EV, + resetValue = 0f, + onResetValue = onRawExposureCompensationReset, + onValueChange = { + onAdjustmentStart() + onRawExposureCompensationChange(it) + }, + onValueChangeFinished = onAdjustmentEnd + ) + SliderSettingItem( + title = stringResource(R.string.settings_raw_highlights_adjustment), + value = rawHighlightsAdjustment, + valueRange = -1f..1f, + resetValue = 0f, + onValueChange = { + onAdjustmentStart() + onRawHighlightsAdjustmentChange(it) + }, + onValueChangeFinished = onAdjustmentEnd + ) + SliderSettingItem( + title = stringResource(R.string.settings_raw_shadows_adjustment), + value = rawShadowsAdjustment, + valueRange = -1f..1f, + resetValue = 0f, + onValueChange = { + onAdjustmentStart() + onRawShadowsAdjustmentChange(it) + }, + onValueChangeFinished = onAdjustmentEnd + ) + SliderSettingItem( + title = stringResource(R.string.settings_raw_blacks_adjustment), + value = rawBlackPointCorrection, + valueRange = -1f..1f, + resetValue = 0f, + onValueChange = { + onAdjustmentStart() + onRawBlackPointCorrectionChange(it) + }, + onValueChangeFinished = onAdjustmentEnd + ) + SliderSettingItem( + title = stringResource(R.string.settings_raw_whites_adjustment), + value = rawWhitePointCorrection, + valueRange = -1f..1f, + resetValue = 0f, + onValueChange = { + onAdjustmentStart() + onRawWhitePointCorrectionChange(it) + }, + onValueChangeFinished = onAdjustmentEnd + ) + } if (showDngMetadataControls) { RawDngMetadataCorrectionSettings( rawBlackLevelMode = rawBlackLevelMode, @@ -274,7 +297,8 @@ fun RawEditPanel( onRawCustomBlackLevelChange = onRawCustomBlackLevelChange, onRawWhiteLevelModeChange = onRawWhiteLevelModeChange, onRawCustomWhiteLevelChange = onRawCustomWhiteLevelChange, - onRawCfaCorrectionModeChange = onRawCfaCorrectionModeChange + onRawCfaCorrectionModeChange = onRawCfaCorrectionModeChange, + useDropdowns = compactLayout, ) } } @@ -542,6 +566,7 @@ fun RawDngMetadataCorrectionSettings( onRawWhiteLevelModeChange: (String) -> Unit, onRawCustomWhiteLevelChange: (Float) -> Unit, onRawCfaCorrectionModeChange: (String) -> Unit, + useDropdowns: Boolean = false, modifier: Modifier = Modifier ) { Column(modifier = modifier.fillMaxWidth()) { @@ -558,7 +583,8 @@ fun RawDngMetadataCorrectionSettings( "Custom" to stringResource(R.string.settings_black_level_custom) ), currentLevel = rawBlackLevelMode, - onLevelSelected = onRawBlackLevelModeChange + onLevelSelected = onRawBlackLevelModeChange, + useDropdown = useDropdowns, ) if (rawBlackLevelMode == "Custom") { RawNumberInputSetting( @@ -579,7 +605,8 @@ fun RawDngMetadataCorrectionSettings( RawWhiteLevelCorrection.MODE_CUSTOM to stringResource(R.string.settings_white_level_custom) ), currentLevel = rawWhiteLevelMode, - onLevelSelected = onRawWhiteLevelModeChange + onLevelSelected = onRawWhiteLevelModeChange, + useDropdown = useDropdowns, ) if (rawWhiteLevelMode == RawWhiteLevelCorrection.MODE_CUSTOM) { RawNumberInputSetting( @@ -607,7 +634,8 @@ fun RawDngMetadataCorrectionSettings( RawCfaCorrection.MODE_8X8_BGGR to stringResource(R.string.settings_cfa_correction_8x8_bggr) ), currentLevel = rawCfaCorrectionMode, - onLevelSelected = onRawCfaCorrectionModeChange + onLevelSelected = onRawCfaCorrectionModeChange, + useDropdown = useDropdowns, ) } } @@ -810,8 +838,13 @@ private fun RawChoiceSetting( levels: List>, currentLevel: String, onLevelSelected: (String) -> Unit, + useDropdown: Boolean = false, modifier: Modifier = Modifier ) { + if (useDropdown) { + RawChoiceDropdown(title, description, levels, currentLevel, onLevelSelected, modifier) + return + } Column( modifier = modifier .fillMaxWidth() @@ -860,6 +893,55 @@ private fun RawChoiceSetting( } } +@Composable +private fun RawChoiceDropdown( + title: String, + description: String, + levels: List>, + currentLevel: String, + onLevelSelected: (String) -> Unit, + modifier: Modifier = Modifier, +) { + var expanded by remember { mutableStateOf(false) } + Row( + modifier = modifier + .fillMaxWidth() + .clickable(role = Role.Button) { expanded = true } + .padding(vertical = 8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) { + Text(title, color = Color.White, fontSize = 16.sp) + Text(description, color = Color.White.copy(alpha = 0.6f), fontSize = 13.sp, lineHeight = 18.sp) + Text( + text = levels.firstOrNull { (level, _) -> level == currentLevel }?.second ?: currentLevel, + color = AccentColor, + fontSize = 14.sp, + ) + } + Spacer(Modifier.width(16.dp)) + Box { + Icon(AppIcons.ExpandMore, contentDescription = null, tint = Color.White.copy(alpha = 0.6f)) + DropdownMenu( + expanded = expanded, + onDismissRequest = { expanded = false }, + modifier = Modifier.heightIn(max = 320.dp), + containerColor = Color(0xFF2C2C2E), + ) { + levels.forEach { (level, label) -> + DropdownMenuItem( + text = { Text(label, color = if (level == currentLevel) AccentColor else Color.White) }, + onClick = { + expanded = false + onLevelSelected(level) + }, + ) + } + } + } + } +} + @Composable private fun RawNumberInputSetting( title: String, @@ -2109,13 +2191,11 @@ fun RawBaselineColorCorrectionBottomSheet( availableLuts: List, thumbnail: Bitmap?, title: String = stringResource(R.string.settings_baseline_raw_title), - containerColor: Color? = null, onSelectLut: (String?) -> Unit, onEditRecipe: ((String) -> Unit)? = null, onDismiss: () -> Unit ) { AppModalBottomSheet( - containerColor = containerColor, style = AppSheetStyle.Translucent, onDismissRequest = onDismiss, dragHandle = { BottomSheetDefaults.DragHandle(color = Color.White.copy(alpha = 0.2f)) } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt index 35859683..b76437c2 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/gallery/GalleryEditScreen.kt @@ -105,6 +105,7 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.first import kotlinx.coroutines.withContext import kotlinx.coroutines.delay import me.saket.telephoto.zoomable.ZoomSpec @@ -123,6 +124,8 @@ import com.hinnka.mycamera.video.VideoLogProfile import com.hinnka.mycamera.ui.camera.autoRotate import com.hinnka.mycamera.ui.components.RawEditPanelContentMode import me.saket.telephoto.zoomable.DoubleClickToZoomListener +import me.saket.telephoto.zoomable.ZoomableContentTransformation +import me.saket.telephoto.zoomable.ZoomableState import com.hinnka.mycamera.ui.icons.AppIcons import kotlin.math.abs import kotlin.math.max @@ -136,6 +139,19 @@ private const val EDIT_TAB_DETAIL = 3 private const val EDIT_TAB_RAW = 4 private const val EDIT_TAB_CROP = 5 private const val DEFAULT_COMPUTATIONAL_APERTURE = 1.4f +private const val EDIT_PREVIEW_MIN_ZOOM = 0.25f +private const val EDIT_PREVIEW_DOUBLE_TAP_ZOOM = 3f +private val EditPanelMaxHeight = 544.dp +private val EditPanelCornerRadius = 24.dp +private val EditPanelShape = RoundedCornerShape(topStart = EditPanelCornerRadius, topEnd = EditPanelCornerRadius) +private val EditPanelGlassStyle = LiquidGlassStyle( + blurRadius = 36.dp, + refractionAmount = 0.dp, + saturation = 1f, + tint = AppPanelMaterial.Tint.copy(alpha = 0.15f), + highlightAlpha = 0.3f, + fallbackColor = AppPanelMaterial.Tint.copy(alpha = 0.55f), +) private data class EmbeddedDngProfileUiState( val options: List = emptyList(), @@ -399,7 +415,8 @@ fun GalleryEditScreen( // 编辑标签页状态 var editTab by remember { mutableIntStateOf(EDIT_TAB_LUT) } var areEditControlsHidden by remember { mutableStateOf(false) } - var isZoomed by remember { mutableStateOf(false) } + val previewZoom = remember { mutableFloatStateOf(1f) } + val isZoomed by remember { derivedStateOf { previewZoom.floatValue > 1.01f } } val editTabsScrollState = rememberScrollState() val editPanelScrollState = rememberScrollState() var viewportSize by remember { mutableStateOf(IntSize.Zero) } @@ -663,39 +680,21 @@ fun GalleryEditScreen( 0 } val visibleTopBarHeightPx = if (areEditControlsHidden) 0 else topBarHeightPx - val targetPreviewOffsetYPx = if ( - viewportSize != IntSize.Zero && - previewSourceWidth != null && - previewSourceHeight != null - ) { - val viewportWidth = viewportSize.width.toFloat() - val viewportHeight = viewportSize.height.toFloat() + val allowZoomOutBelowFit = shouldShowEditPanel && !areEditControlsHidden && editTab != EDIT_TAB_CROP + val viewportHeight = viewportSize.height.toFloat() + val previewHeightAtFit = if (previewSourceWidth != null && previewSourceHeight != null) { val sourceAspectRatio = previewSourceWidth.toFloat() / previewSourceHeight.toFloat() - val viewportAspectRatio = viewportWidth / viewportHeight - val displayedPhotoHeight = if (sourceAspectRatio > viewportAspectRatio) { - viewportWidth / sourceAspectRatio - } else { - viewportHeight - } - val remainingTop = visibleTopBarHeightPx.toFloat() - .coerceIn(0f, viewportHeight) - val remainingBottom = (viewportHeight - visibleEditPanelHeightPx.toFloat()) - .coerceIn(remainingTop, viewportHeight) - val remainingHeight = remainingBottom - remainingTop - val targetPhotoTop = if (displayedPhotoHeight <= remainingHeight) { - remainingTop + (remainingHeight - displayedPhotoHeight) / 2f - } else { - (remainingBottom - displayedPhotoHeight).coerceAtLeast(0f) - } - val fullScreenCenteredPhotoTop = (viewportHeight - displayedPhotoHeight) / 2f - targetPhotoTop - fullScreenCenteredPhotoTop + (viewportSize.width / sourceAspectRatio).coerceAtMost(viewportHeight) } else { 0f } - val previewOffsetYPx by animateFloatAsState( - targetValue = targetPreviewOffsetYPx, - label = "editPreviewVerticalPosition" + val targetPreviewTop = visibleTopBarHeightPx.toFloat().coerceAtMost(viewportHeight) + val previewTopPx by animateFloatAsState(targetPreviewTop, label = "editPreviewTop") + val previewBottomPx by animateFloatAsState( + targetValue = (viewportHeight - visibleEditPanelHeightPx).coerceAtLeast(targetPreviewTop), + label = "editPreviewBottom", ) + val previewBackdrop = rememberLiquidGlassBackdrop() var pendingRawPreviewRefresh by remember(currentEditSourcePhoto.id) { mutableStateOf(false) } var pendingPhotonPgtmRegeneration by remember(currentEditSourcePhoto.id) { mutableStateOf(false) } @@ -760,6 +759,7 @@ fun GalleryEditScreen( modifier = Modifier .fillMaxSize() .onSizeChanged { viewportSize = it } + .padding(it) .animateContentSize() ) { // Draggable Floating Reference Photo @@ -1071,11 +1071,27 @@ fun GalleryEditScreen( ) { val previewMediaModifier = Modifier .fillMaxSize() + .liquidGlassBackdropSource(previewBackdrop) + .background(Color.Black) .offset { - IntOffset( - x = 0, - y = previewOffsetYPx.roundToInt() - ) + if (previewHeightAtFit == 0f) return@offset IntOffset.Zero + + val previewScale = if (currentPhoto.isVideo || editTab == EDIT_TAB_CROP) { + 1f + } else { + minOf(previewZoom.floatValue, 1f) + } + val photoHeight = previewHeightAtFit * previewScale + val top = previewTopPx.coerceIn(0f, viewportHeight) + val bottom = previewBottomPx.coerceIn(top, viewportHeight) + val availableHeight = bottom - top + val photoTop = if (photoHeight <= availableHeight) { + top + (availableHeight - photoHeight) / 2f + } else { + (bottom - photoHeight).coerceAtLeast(0f) + } + val centeredPhotoTop = (viewportHeight - photoHeight) / 2f + IntOffset(0, (photoTop - centeredPhotoTop).roundToInt()) } // 显示预览 @@ -1158,10 +1174,9 @@ fun GalleryEditScreen( ZoomableEditImage( previewBitmap = previewBitmap, isLutEditing = editTab == EDIT_TAB_ADJUSTMENTS || isBaselineLutEditSheetVisible, + allowZoomOutBelowFit = allowZoomOutBelowFit, contentDescription = stringResource(R.string.edit), - onZoomChange = { - isZoomed = it - }, + onZoomChange = { previewZoom.floatValue = it }, modifier = previewMediaModifier ) } @@ -1439,676 +1454,604 @@ fun GalleryEditScreen( exit = slideOutVertically(targetOffsetY = { it }) + shrinkVertically(shrinkTowards = Alignment.Bottom) + fadeOut(), modifier = Modifier.align(Alignment.BottomCenter) ) { - Surface( - color = Color.Transparent, - shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp), + LiquidGlassSurface( + backdrop = previewBackdrop, + cornerRadius = EditPanelCornerRadius, + openBottomEdge = true, + style = EditPanelGlassStyle, modifier = Modifier .fillMaxWidth() + .heightIn(max = EditPanelMaxHeight) .onSizeChanged { editPanelHeightPx = it.height } + .clip(EditPanelShape) ) { Column( modifier = Modifier .navigationBarsPadding() .padding(bottom = if (areEditControlsHidden) 4.dp else 16.dp) ) { - val editPanelToggleDescription = stringResource( - if (areEditControlsHidden) { - R.string.edit_panel_expand - } else { - R.string.edit_panel_minimize - } - ) - Box( - modifier = Modifier - .fillMaxWidth() - .height(44.dp) - .clickable( - onClickLabel = editPanelToggleDescription - ) { - toggleEditControls() + EditPanelHeader( + collapsed = areEditControlsHidden, + selectedTab = editTab, + isVideo = currentPhoto.isVideo, + isRaw = isRaw, + scrollState = editTabsScrollState, + onTabSelected = { tab -> + if (tab == EDIT_TAB_CROP && editTab != EDIT_TAB_CROP) { + cropPreviewBitmap = null } - .padding(horizontal = 16.dp) - ) { - if (areEditControlsHidden) { - Text( - text = stringResource(R.string.edit_panel_title), - color = Color.White.copy(alpha = 0.82f), - fontSize = 14.sp, - modifier = Modifier - .align(Alignment.CenterStart) - .padding(start = 4.dp) - ) - } - Icon( - imageVector = if (areEditControlsHidden) { - AppIcons.ExpandLess - } else { - AppIcons.ExpandMore - }, - contentDescription = editPanelToggleDescription, - tint = Color.White.copy(alpha = 0.82f), - modifier = Modifier - .align(Alignment.CenterEnd) - .padding(end = 4.dp) - .size(24.dp) - ) - } + editTab = tab + }, + onToggle = ::toggleEditControls, + ) AnimatedVisibility( visible = !areEditControlsHidden, enter = expandVertically(expandFrom = Alignment.Top) + fadeIn(), exit = shrinkVertically(shrinkTowards = Alignment.Top) + fadeOut() ) { - Column { - // 标签页切换 - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .horizontalScroll(editTabsScrollState), - horizontalArrangement = Arrangement.spacedBy(24.dp) - ) { - TabItem( - title = stringResource(R.string.filter), - isSelected = editTab == EDIT_TAB_LUT, - onClick = { editTab = EDIT_TAB_LUT } - ) - if (!currentPhoto.isVideo) { - TabItem( - title = stringResource(R.string.frame), - isSelected = editTab == EDIT_TAB_FRAME, - onClick = { editTab = EDIT_TAB_FRAME } - ) - } - TabItem( - title = stringResource(R.string.edit), - isSelected = editTab == EDIT_TAB_ADJUSTMENTS, - onClick = { editTab = EDIT_TAB_ADJUSTMENTS } - ) - TabItem( - title = stringResource(R.string.recipe_tab_post), - isSelected = editTab == EDIT_TAB_DETAIL, - onClick = { editTab = EDIT_TAB_DETAIL } - ) - if (isRaw) { - TabItem( - title = "RAW", - isSelected = editTab == EDIT_TAB_RAW, - onClick = { editTab = EDIT_TAB_RAW } - ) - } - if (!currentPhoto.isVideo) { - TabItem( - title = stringResource(R.string.crop), - isSelected = editTab == EDIT_TAB_CROP, - onClick = { - cropPreviewBitmap = null - editTab = EDIT_TAB_CROP + Column( + modifier = Modifier + .padding( + horizontal = if (editTab == EDIT_TAB_ADJUSTMENTS) { + 0.dp + } else { + 16.dp } - ) - } - } - Column( - modifier = Modifier - .heightIn(max = 550.dp) - .padding( - horizontal = if (editTab == EDIT_TAB_ADJUSTMENTS) { - 0.dp - } else { - 16.dp - } - ) - .verticalScroll(editPanelScrollState) - ) { - when (editTab) { - EDIT_TAB_LUT -> { - Spacer(modifier = Modifier.height(16.dp)) - if (currentPhoto.isVideo && videoSourceProfile != null) { - VideoSourceLogSelector( - profile = videoSourceProfile, - detectedFromFile = viewModel.editVideoProfileDetected, - onProfileSelected = viewModel::selectEditVideoSourceProfile, - ) - } - LutSelector( - availableLuts = availableLuts, - currentLutId = editLutId ?: "none", - thumbnail = thumbnailBitmap.takeUnless { videoSourceProfile?.isEnabled == true }, - onLutSelected = { viewModel.setEditLut(it) }, - onManageClick = { onFilterManagementClick(it) }, - categoryOrder = categoryOrder, - modifier = Modifier.fillMaxWidth() + ) + .verticalScroll(editPanelScrollState) + ) { + when (editTab) { + EDIT_TAB_LUT -> { + Spacer(modifier = Modifier.height(4.dp)) + if (currentPhoto.isVideo && videoSourceProfile != null) { + VideoSourceLogSelector( + profile = videoSourceProfile, + detectedFromFile = viewModel.editVideoProfileDetected, + onProfileSelected = viewModel::selectEditVideoSourceProfile, ) - if (!currentPhoto.isVideo) { - Spacer(modifier = Modifier.height(8.dp)) - AiColorMatchRow( - active = PhotoColorMatch.isId(editLutId), - activeReferenceId = activeColorMatchReferenceId - .takeIf { PhotoColorMatch.isId(editLutId) }, - references = colorMatchReferences, - enabled = !isAiColorMatching, - onAddReference = { - if (viewModel.requireEditPurchase()) { - colorMatchReferenceLauncher.launch( - PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly) - ) - } - }, - onReuseReference = { - if (viewModel.requireEditPurchase()) { - pendingColorMatchReference = - ColorMatchReferenceStore.Source.Saved(it) - } - }, - onDeleteReference = { colorMatchReferenceToDelete = it }, - onRemove = { viewModel.setEditLut(null) }, - ) - } - + } + LutSelector( + availableLuts = availableLuts, + currentLutId = editLutId ?: "none", + thumbnail = thumbnailBitmap.takeUnless { videoSourceProfile?.isEnabled == true }, + onLutSelected = { viewModel.setEditLut(it) }, + onManageClick = { onFilterManagementClick(it) }, + categoryOrder = categoryOrder, + showHorizontalHeader = false, + modifier = Modifier.fillMaxWidth() + ) + if (!currentPhoto.isVideo) { Spacer(modifier = Modifier.height(8.dp)) - LutIntensitySlider( - intensity = effectiveRecipe.lutIntensity, - onIntensityChange = { intensity -> - viewModel.updatePhotoRecipeParams { current -> - RecipeParam.LUT_INTENSITY.setValue(current, intensity) + AiColorMatchRow( + active = PhotoColorMatch.isId(editLutId), + activeReferenceId = activeColorMatchReferenceId + .takeIf { PhotoColorMatch.isId(editLutId) }, + references = colorMatchReferences, + enabled = !isAiColorMatching, + onAddReference = { + if (viewModel.requireEditPurchase()) { + colorMatchReferenceLauncher.launch( + PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly) + ) } }, - enabled = editLutId != null, - modifier = Modifier.fillMaxWidth() + onReuseReference = { + if (viewModel.requireEditPurchase()) { + pendingColorMatchReference = + ColorMatchReferenceStore.Source.Saved(it) + } + }, + onDeleteReference = { colorMatchReferenceToDelete = it }, + onRemove = { viewModel.setEditLut(null) }, ) } - EDIT_TAB_FRAME -> { - Spacer(modifier = Modifier.height(16.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = stringResource(R.string.frame), - color = Color.White, - fontSize = 16.sp - ) - - val currentFrame = availableFrames.find { - it.id == editFrameId - } - if (currentFrame?.isEditable == true) { - Row( - modifier = Modifier - .height(28.dp) - .clip(RoundedCornerShape(14.dp)) - .background(Color.White.copy(alpha = 0.1f)) - .clickable { - onOpenFrameEditor(currentFrame.id) - } - .padding(horizontal = 9.dp), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(4.dp) - ) { - Icon( - imageVector = AppIcons.Tune, - contentDescription = null, - tint = AccentColor, - modifier = Modifier.size(14.dp) - ) - Text( - text = stringResource(R.string.edit), - color = Color.White, - fontSize = 10.sp - ) - } - } - } - - Spacer(modifier = Modifier.height(8.dp)) - LazyRow( - horizontalArrangement = Arrangement.spacedBy(12.dp), - state = frameScrollState - ) { - item { - FrameOption( - name = stringResource(R.string.none), - isSelected = editFrameId == null, - onClick = { viewModel.setEditFrame(null) } - ) - } - items(availableFrames) { frame -> - FrameOption( - name = frame.name, - isSelected = editFrameId == frame.id, - isCustom = !frame.isBuiltIn, - isEditable = frame.isEditable, - onClick = { - if (editFrameId == frame.id) { - if (frame.isEditable) { - onOpenFrameEditor(frame.id) - } - } else { - viewModel.setEditFrame(frame.id) - } - } - ) - } - } - } - EDIT_TAB_ADJUSTMENTS -> { - Spacer(modifier = Modifier.height(6.dp)) - val applyEffectsToVideo by viewModel.editApplyEffectsToVideo.collectAsState() - val canSyncAdjustmentsToLut = editLutId != null && !PhotoColorMatch.isId(editLutId) - - ColorRecipePanel( - currentParams = effectiveRecipe, - onParamChange = { param, value -> - viewModel.updatePhotoRecipeParams { current -> - param.setValue(current, value) - } - }, - onParamsChange = { params -> - viewModel.updatePhotoRecipeParams(displayed = effectiveRecipe, params = params) - }, - onRemarksChange = { remarks -> - viewModel.updatePhotoRecipeParams { current -> - current.copy(remarks = remarks) - } - }, - onCurveChange = { channel, points -> - viewModel.updatePhotoRecipeParams { current -> - when (channel) { - CurveChannel.MASTER -> current.copy(masterCurvePoints = points) - CurveChannel.RED -> current.copy(redCurvePoints = points) - CurveChannel.GREEN -> current.copy(greenCurvePoints = points) - CurveChannel.BLUE -> current.copy(blueCurvePoints = points) - } - } - }, - onResetAll = viewModel::resetPhotoRecipeParams, - imageHistogram = imageHistogram, - currentEffects = effectiveRecipe.toEffectParams(), - onEffectsChange = { effects -> - viewModel.updatePhotoRecipeParams( - displayed = effectiveRecipe, - params = effects.applyTo(effectiveRecipe) - ) - }, - headerControls = if ( - canSyncAdjustmentsToLut || currentPhoto.isMotionPhoto - ) { - { - Row( - horizontalArrangement = Arrangement.spacedBy(6.dp), - verticalAlignment = Alignment.CenterVertically - ) { - if (canSyncAdjustmentsToLut) { - CompactToggleChip( - title = stringResource( - R.string.edit_sync_lut_recipe - ), - checked = syncAdjustmentsToLut, - onCheckedChange = viewModel::setSyncAdjustmentsToLut - ) - } - - if (currentPhoto.isMotionPhoto) { - CompactToggleChip( - title = stringResource( - R.string.settings_use_live_photo - ), - checked = applyEffectsToVideo, - onCheckedChange = { - viewModel.setApplyEffectsToVideo(it) - } - ) - } - } - } - } else { - null - }, - modifier = Modifier.fillMaxWidth() - ) - } - EDIT_TAB_DETAIL -> { - Spacer(modifier = Modifier.height(16.dp)) - if (!currentPhoto.isVideo) { - val isAiDenoising by viewModel.isAiDenoising.collectAsState() - val aiDenoiseProgress by viewModel.aiDenoiseProgress.collectAsState() - - SwitchSettingItem( - title = stringResource(R.string.ai_denoise_title), - description = if (isAiDenoising) stringResource( - R.string.ai_denoise_processing, - aiDenoiseProgress * 100 - ) else stringResource(R.string.ai_denoise_description), - checked = editAiDenoiseEnabled, - isVip = true, - onCheckedChange = { enabled -> - if (isAiDenoising) return@SwitchSettingItem - if (enabled && !viewModel.requireEditPurchase()) { - return@SwitchSettingItem - } - viewModel.setAiDenoiseEnabled(enabled) - if (enabled) { - if (AiDenoiseModelManager.isInstalled(context)) { - startAiDenoise() - } else { - pendingAiDenoise = true - } - } else { - viewModel.resetAiDenoise(photo = currentEditSourcePhoto) { success -> - if (!success) { - viewModel.revertAiDenoiseEnabled() - showAiDenoiseFailure() - } - } - } - } - ) Spacer(modifier = Modifier.height(8.dp)) - // 细节处理调整 (锐化, 降噪, 杂色降噪) - val aperture = editComputationalAperture - val bokehEnabled = aperture != null && aperture > 0f - val canAdjustBokeh = isPurchased && isDepthModelInstalled && bokehEnabled - ApertureScaleSettingItem( - title = stringResource( - R.string.gallery_large_aperture_blur_title - ), - description = stringResource( - R.string.gallery_large_aperture_blur_description - ), - value = aperture ?: DEFAULT_COMPUTATIONAL_APERTURE, - onValueChange = viewModel::setComputationalAperture, - toggleValue = bokehEnabled, - enabled = canAdjustBokeh, - isVip = true, - onToggleChange = { checked -> - if (checked) { - if (!viewModel.requireEditPurchase()) { - return@ApertureScaleSettingItem - } - val requestedAperture = aperture - ?.takeIf { it > 0f } - ?: DEFAULT_COMPUTATIONAL_APERTURE - if (isDepthModelInstalled) { - viewModel.setComputationalAperture(requestedAperture) - } else { - pendingVirtualAperture = requestedAperture - } - } else { - viewModel.setComputationalAperture(null) + LutIntensitySlider( + intensity = effectiveRecipe.lutIntensity, + onIntensityChange = { intensity -> + viewModel.updatePhotoRecipeParams { current -> + RecipeParam.LUT_INTENSITY.setValue(current, intensity) + } + }, + enabled = editLutId != null, + modifier = Modifier.fillMaxWidth() + ) + } + EDIT_TAB_FRAME -> { + Spacer(modifier = Modifier.height(16.dp)) + + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = stringResource(R.string.frame), + color = Color.White, + fontSize = 16.sp + ) + + val currentFrame = availableFrames.find { + it.id == editFrameId + } + if (currentFrame?.isEditable == true) { + Row( + modifier = Modifier + .height(28.dp) + .clip(RoundedCornerShape(14.dp)) + .background(Color.White.copy(alpha = 0.1f)) + .clickable { + onOpenFrameEditor(currentFrame.id) + } + .padding(horizontal = 9.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(4.dp) + ) { + Icon( + imageVector = AppIcons.Tune, + contentDescription = null, + tint = AccentColor, + modifier = Modifier.size(14.dp) + ) + Text( + text = stringResource(R.string.edit), + color = Color.White, + fontSize = 10.sp + ) } } - ) - if (canAdjustBokeh) { - BokehStyleSelector( - selectedStyle = editBokehStyle, - onStyleSelected = viewModel::setBokehStyle, - ) + } + + Spacer(modifier = Modifier.height(8.dp)) + LazyRow( + horizontalArrangement = Arrangement.spacedBy(12.dp), + state = frameScrollState + ) { + item { + FrameOption( + name = stringResource(R.string.none), + isSelected = editFrameId == null, + onClick = { viewModel.setEditFrame(null) } + ) + } + items(availableFrames) { frame -> + FrameOption( + name = frame.name, + isSelected = editFrameId == frame.id, + isCustom = !frame.isBuiltIn, + isEditable = frame.isEditable, + onClick = { + if (editFrameId == frame.id) { + if (frame.isEditable) { + onOpenFrameEditor(frame.id) + } + } else { + viewModel.setEditFrame(frame.id) + } + } + ) + } } } - SliderSettingItem( - title = stringResource(R.string.settings_noise_reduction), - value = editNoiseReduction, - valueRange = DenoiseStrength.valueRange, - resetValue = 0f, - onValueChange = { viewModel.setNoiseReduction(it) }, - onValueChangeFinished = { - if (viewModel.hasAppliedAiDenoise()) { - // Luma noise reduction runs on the AI output. - if (isRaw) { + EDIT_TAB_ADJUSTMENTS -> { + Spacer(modifier = Modifier.height(6.dp)) + val applyEffectsToVideo by viewModel.editApplyEffectsToVideo.collectAsState() + val canSyncAdjustmentsToLut = editLutId != null && !PhotoColorMatch.isId(editLutId) + + ColorRecipePanel( + currentParams = effectiveRecipe, + onParamChange = { param, value -> + viewModel.updatePhotoRecipeParams { current -> + param.setValue(current, value) + } + }, + onParamsChange = { params -> + viewModel.updatePhotoRecipeParams(displayed = effectiveRecipe, params = params) + }, + onRemarksChange = { remarks -> + viewModel.updatePhotoRecipeParams { current -> + current.copy(remarks = remarks) + } + }, + onCurveChange = { channel, points -> + viewModel.updatePhotoRecipeParams { current -> + when (channel) { + CurveChannel.MASTER -> current.copy(masterCurvePoints = points) + CurveChannel.RED -> current.copy(redCurvePoints = points) + CurveChannel.GREEN -> current.copy(greenCurvePoints = points) + CurveChannel.BLUE -> current.copy(blueCurvePoints = points) + } + } + }, + onResetAll = viewModel::resetPhotoRecipeParams, + imageHistogram = imageHistogram, + currentEffects = effectiveRecipe.toEffectParams(), + onEffectsChange = { effects -> + viewModel.updatePhotoRecipeParams( + displayed = effectiveRecipe, + params = effects.applyTo(effectiveRecipe) + ) + }, + headerControls = if ( + canSyncAdjustmentsToLut || currentPhoto.isMotionPhoto + ) { + { + Row( + horizontalArrangement = Arrangement.spacedBy(6.dp), + verticalAlignment = Alignment.CenterVertically + ) { + if (canSyncAdjustmentsToLut) { + CompactToggleChip( + title = stringResource( + R.string.edit_sync_lut_recipe + ), + checked = syncAdjustmentsToLut, + onCheckedChange = viewModel::setSyncAdjustmentsToLut + ) + } + + if (currentPhoto.isMotionPhoto) { + CompactToggleChip( + title = stringResource( + R.string.settings_use_live_photo + ), + checked = applyEffectsToVideo, + onCheckedChange = { + viewModel.setApplyEffectsToVideo(it) + } + ) + } + } + } + } else { + null + }, + containerColor = Color.Transparent, + modifier = Modifier.fillMaxWidth() + ) + } + EDIT_TAB_DETAIL -> { + Spacer(modifier = Modifier.height(16.dp)) + if (!currentPhoto.isVideo) { + val isAiDenoising by viewModel.isAiDenoising.collectAsState() + val aiDenoiseProgress by viewModel.aiDenoiseProgress.collectAsState() + + SwitchSettingItem( + title = stringResource(R.string.ai_denoise_title), + description = if (isAiDenoising) stringResource( + R.string.ai_denoise_processing, + aiDenoiseProgress * 100 + ) else stringResource(R.string.ai_denoise_description), + checked = editAiDenoiseEnabled, + isVip = true, + onCheckedChange = { enabled -> + if (isAiDenoising) return@SwitchSettingItem + if (enabled && !viewModel.requireEditPurchase()) { + return@SwitchSettingItem + } + viewModel.setAiDenoiseEnabled(enabled) + if (enabled) { + if (AiDenoiseModelManager.isInstalled(context)) { + startAiDenoise() + } else { + pendingAiDenoise = true + } + } else { + viewModel.resetAiDenoise(photo = currentEditSourcePhoto) { success -> + if (!success) { + viewModel.revertAiDenoiseEnabled() + showAiDenoiseFailure() + } + } + } + } + ) + Spacer(modifier = Modifier.height(8.dp)) + // 细节处理调整 (锐化, 降噪, 杂色降噪) + val aperture = editComputationalAperture + val bokehEnabled = aperture != null && aperture > 0f + val canAdjustBokeh = isPurchased && isDepthModelInstalled && bokehEnabled + ApertureScaleSettingItem( + title = stringResource( + R.string.gallery_large_aperture_blur_title + ), + description = stringResource( + R.string.gallery_large_aperture_blur_description + ), + value = aperture ?: DEFAULT_COMPUTATIONAL_APERTURE, + onValueChange = viewModel::setComputationalAperture, + toggleValue = bokehEnabled, + enabled = canAdjustBokeh, + isVip = true, + onToggleChange = { checked -> + if (checked) { + if (!viewModel.requireEditPurchase()) { + return@ApertureScaleSettingItem + } + val requestedAperture = aperture + ?.takeIf { it > 0f } + ?: DEFAULT_COMPUTATIONAL_APERTURE + if (isDepthModelInstalled) { + viewModel.setComputationalAperture(requestedAperture) + } else { + pendingVirtualAperture = requestedAperture + } + } else { + viewModel.setComputationalAperture(null) + } + } + ) + if (canAdjustBokeh) { + BokehStyleSelector( + selectedStyle = editBokehStyle, + onStyleSelected = viewModel::setBokehStyle, + ) + } + } + SliderSettingItem( + title = stringResource(R.string.settings_noise_reduction), + value = editNoiseReduction, + valueRange = DenoiseStrength.valueRange, + resetValue = 0f, + onValueChange = { viewModel.setNoiseReduction(it) }, + onValueChangeFinished = { + if (viewModel.hasAppliedAiDenoise()) { + // Luma noise reduction runs on the AI output. + if (isRaw) { + viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success -> + if (success) viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) + } + } else { + viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) + } + } else if (isRaw) { viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success -> - if (success) viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) + if (success) requestRawPreviewRefresh() } } else { viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) } - } else if (isRaw) { - viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success -> - if (success) requestRawPreviewRefresh() - } - } else { - viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) } - } - ) - SliderSettingItem( - title = stringResource(R.string.settings_chroma_noise_reduction), - value = editChromaNoiseReduction, - valueRange = DenoiseStrength.valueRange, - resetValue = 0f, - enabled = isPurchased || !editAiDenoiseEnabled, - onValueChange = { viewModel.setChromaNoiseReduction(it) }, - onValueChangeFinished = { - if (viewModel.hasAppliedAiDenoise()) { - if (!viewModel.requireEditPurchase()) return@SliderSettingItem - // Color noise is reduced before AI denoise: run AI denoise again. - if (isRaw) { + ) + SliderSettingItem( + title = stringResource(R.string.settings_chroma_noise_reduction), + value = editChromaNoiseReduction, + valueRange = DenoiseStrength.valueRange, + resetValue = 0f, + enabled = isPurchased || !editAiDenoiseEnabled, + onValueChange = { viewModel.setChromaNoiseReduction(it) }, + onValueChangeFinished = { + if (viewModel.hasAppliedAiDenoise()) { + if (!viewModel.requireEditPurchase()) return@SliderSettingItem + // Color noise is reduced before AI denoise: run AI denoise again. + if (isRaw) { + viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success -> + if (success) startAiDenoise() + } + } else { + startAiDenoise() + } + } else if (isRaw) { viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success -> - if (success) startAiDenoise() + if (success) requestRawPreviewRefresh() } } else { - startAiDenoise() - } - } else if (isRaw) { - viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success -> - if (success) requestRawPreviewRefresh() - } - } else { - viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) - } - } - ) - } - EDIT_TAB_RAW -> { - RawEditPanel( - selectedDcpId = editRawDcpId, - availableDcps = availableDcps, - selectedBaselineLutId = editRawBaselineLutId, - onSelectBaselineLut = { lutId -> - viewModel.saveRawBaselineLutSelection(currentEditSourcePhoto, lutId) { - requestRawPreviewRefresh() - } - }, - onEditBaselineRecipe = { lutId -> - baselineLutEditId = lutId - showBaselineLutEditSheet = true - }, - availableLuts = availableLuts, - thumbnail = previewBitmap, - rawExposureCompensation = editRawExposureCompensation, - rawAdaptiveExposureMode = RawAdaptiveExposureMode.resolve( - usePhotonHdr = - editRawToneMappingParameters.usePhotonHdr, - useLegacyAutoExposure = editRawAutoExposure, - ), - rawHighlightsAdjustment = editRawHighlightsAdjustment, - rawShadowsAdjustment = editRawShadowsAdjustment, - rawBlackPointCorrection = editRawBlackPointCorrection, - rawWhitePointCorrection = editRawWhitePointCorrection, - rawBlackLevelMode = editRawBlackLevelMode, - rawCustomBlackLevel = editRawCustomBlackLevel, - rawWhiteLevelMode = editRawWhiteLevelMode, - rawCustomWhiteLevel = editRawCustomWhiteLevel, - rawCfaCorrectionMode = editRawCfaCorrectionMode, - rawRenderingEngine = editRawColorEngine, - rawToneMappingParameters = editRawToneMappingParameters, - spectralFilmSelection = editRawSpectralFilmStock?.let { stock -> - SpectralFilmSelection( - id = stock, - tuning = editRawSpectralFilmTuning - ) - }, - spectralFilmPrint = editRawSpectralFilmPrint, - onSelectDcp = { dcpId -> - viewModel.saveRawDcpSelection(currentEditSourcePhoto, dcpId) { - requestRawPreviewRefresh() - } - }, - onImportDcp = { - rawDcpLauncher.launch(arrayOf("*/*")) - }, - onDeleteDcp = { dcp -> - val isDeletingSelectedDcp = editRawDcpId == dcp.id - viewModel.deleteRawDcp(currentEditSourcePhoto, dcp.id) { success -> - Toast.makeText( - context, - if (success) R.string.raw_dcp_delete_success else R.string.raw_dcp_delete_failed, - Toast.LENGTH_SHORT - ).show() - if (success && isDeletingSelectedDcp) { - requestRawPreviewRefresh() + viewModel.refreshPhotonDenoiseBase(currentEditSourcePhoto) } } - }, - hncsFilmCurveMode = editRawHncsFilmCurveMode, - onHncsFilmCurveModeChange = { mode -> - viewModel.saveRawHncsFilmCurveMode( - currentEditSourcePhoto, - mode - ) { - requestRawPreviewRefresh() - } - }, - onRawExposureCompensationChange = { - viewModel.saveRawExposureCompensationValue(currentEditSourcePhoto, it) - }, - onRawExposureCompensationReset = { - viewModel.resetRawExposureCompensationValue(currentEditSourcePhoto) { success -> - if (success) requestRawPreviewRefresh() - } - }, - onRawAdaptiveExposureModeChange = { mode -> - viewModel.selectRawAdaptiveExposureModeForEdit(mode) - viewModel.persistCurrentRawEditMetadata( - currentEditSourcePhoto - ) { success -> - if (success) { - requestRawPreviewRefresh() - } - } - }, - onRawHighlightsAdjustmentChange = { - viewModel.saveRawHighlightsAdjustmentValue(currentEditSourcePhoto, it) - }, - onRawShadowsAdjustmentChange = { - viewModel.saveRawShadowsAdjustmentValue(currentEditSourcePhoto, it) - }, - onRawBlackPointCorrectionChange = { - viewModel.saveRawBlackPointCorrectionValue(currentEditSourcePhoto, it) - }, - onRawWhitePointCorrectionChange = { - viewModel.saveRawWhitePointCorrectionValue(currentEditSourcePhoto, it) - }, - onRawBlackLevelModeChange = { - viewModel.saveRawBlackLevelMode(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onRawCustomBlackLevelChange = { - viewModel.saveRawCustomBlackLevel(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onRawWhiteLevelModeChange = { - viewModel.saveRawWhiteLevelMode(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onRawCustomWhiteLevelChange = { - viewModel.saveRawCustomWhiteLevel(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onRawCfaCorrectionModeChange = { - viewModel.saveRawCfaCorrectionMode(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onRawColorEngineChange = { - viewModel.saveRawColorEngine(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onRawToneMappingParametersChange = { - viewModel.saveRawToneMappingParameters(currentEditSourcePhoto, it) - }, - embeddedDngProfiles = embeddedDngProfileUiState.options, - selectedEmbeddedDngProfileId = activeEmbeddedDngProfileId, - onSelectEmbeddedDngProfile = { profile -> - viewModel.selectRawEmbeddedDngProfileForEdit( - profileId = profile.id, - hasProfileGainTableMap = - profile.hasProfileGainTableMap, - ) - }, - onSpectralFilmSelectionChange = { - viewModel.saveRawSpectralFilmSelection(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - onSpectralFilmPrintChange = { - viewModel.saveRawSpectralFilmPrint(currentEditSourcePhoto, it) { - requestRawPreviewRefresh() - } - }, - // The panel ends every Fotufilm change with onAdjustmentEnd, which persists it. - fotufilmDocument = editRawFotufilmDocument, - onFotufilmDocumentChange = { viewModel.editRawFotufilmDocument.value = it }, - onAdjustmentStart = { }, - onAdjustmentEnd = { - viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { - requestRawPreviewRefresh() - } - }, - onOpenBaselineLutSheet = { - showRawBaselineLutSelectorSheet = true - }, - showAdaptiveExposureControl = isImportedRaw, - showDngMetadataControls = true, - contentMode = RawEditPanelContentMode.FULL, - modifier = Modifier.fillMaxWidth() - ) - SwitchSettingItem( - title = stringResource(R.string.settings_raw_lens_shading_correction), - description = stringResource(R.string.settings_raw_lens_shading_correction_description), - checked = editRawLensShadingCorrectionEnabled, - onCheckedChange = { enabled -> - viewModel.saveRawLensShadingCorrectionEnabled( - currentEditSourcePhoto, - enabled - ) { success -> - if (success) requestRawPreviewRefresh() - } - } - ) - } - EDIT_TAB_CROP -> { - if (!currentPhoto.isVideo) { - // 裁剪编辑 - val availablePhotoAspectRatios by cameraViewModel.availablePhotoAspectRatios.collectAsState() - CropEditPanel( - selectedOption = editCropAspectOption, - onOptionSelected = { viewModel.setCropAspectOption(it) }, - straightenDegrees = editStraightenDegrees, - onStraightenDegreesChanged = { - viewModel.setStraightenDegrees(it) - }, - isHorizontallyMirrored = editMirrorHorizontal, - onRotate = { - cropPreviewBitmap = null - viewModel.rotateEditClockwise() - }, - onMirrorHorizontal = { - cropPreviewBitmap = null - viewModel.toggleEditHorizontalMirror() - }, - availableRatios = availablePhotoAspectRatios, - imageWidth = cropPreviewBitmap?.width ?: 1, - imageHeight = cropPreviewBitmap?.height ?: 1 ) } - } + EDIT_TAB_RAW -> { + RawEditPanel( + selectedDcpId = editRawDcpId, + availableDcps = availableDcps, + selectedBaselineLutId = editRawBaselineLutId, + onSelectBaselineLut = { lutId -> + viewModel.saveRawBaselineLutSelection(currentEditSourcePhoto, lutId) { + requestRawPreviewRefresh() + } + }, + onEditBaselineRecipe = { lutId -> + baselineLutEditId = lutId + showBaselineLutEditSheet = true + }, + availableLuts = availableLuts, + thumbnail = previewBitmap, + rawExposureCompensation = editRawExposureCompensation, + rawAdaptiveExposureMode = RawAdaptiveExposureMode.resolve( + usePhotonHdr = + editRawToneMappingParameters.usePhotonHdr, + useLegacyAutoExposure = editRawAutoExposure, + ), + rawHighlightsAdjustment = editRawHighlightsAdjustment, + rawShadowsAdjustment = editRawShadowsAdjustment, + rawBlackPointCorrection = editRawBlackPointCorrection, + rawWhitePointCorrection = editRawWhitePointCorrection, + rawBlackLevelMode = editRawBlackLevelMode, + rawCustomBlackLevel = editRawCustomBlackLevel, + rawWhiteLevelMode = editRawWhiteLevelMode, + rawCustomWhiteLevel = editRawCustomWhiteLevel, + rawCfaCorrectionMode = editRawCfaCorrectionMode, + rawRenderingEngine = editRawColorEngine, + rawToneMappingParameters = editRawToneMappingParameters, + spectralFilmSelection = editRawSpectralFilmStock?.let { stock -> + SpectralFilmSelection( + id = stock, + tuning = editRawSpectralFilmTuning + ) + }, + spectralFilmPrint = editRawSpectralFilmPrint, + onSelectDcp = { dcpId -> + viewModel.saveRawDcpSelection(currentEditSourcePhoto, dcpId) { + requestRawPreviewRefresh() + } + }, + onImportDcp = { + rawDcpLauncher.launch(arrayOf("*/*")) + }, + onDeleteDcp = { dcp -> + val isDeletingSelectedDcp = editRawDcpId == dcp.id + viewModel.deleteRawDcp(currentEditSourcePhoto, dcp.id) { success -> + Toast.makeText( + context, + if (success) R.string.raw_dcp_delete_success else R.string.raw_dcp_delete_failed, + Toast.LENGTH_SHORT + ).show() + if (success && isDeletingSelectedDcp) { + requestRawPreviewRefresh() + } + } + }, + hncsFilmCurveMode = editRawHncsFilmCurveMode, + onHncsFilmCurveModeChange = { mode -> + viewModel.saveRawHncsFilmCurveMode( + currentEditSourcePhoto, + mode + ) { + requestRawPreviewRefresh() + } + }, + onRawExposureCompensationChange = { + viewModel.saveRawExposureCompensationValue(currentEditSourcePhoto, it) + }, + onRawExposureCompensationReset = { + viewModel.resetRawExposureCompensationValue(currentEditSourcePhoto) { success -> + if (success) requestRawPreviewRefresh() + } + }, + onRawAdaptiveExposureModeChange = { mode -> + viewModel.selectRawAdaptiveExposureModeForEdit(mode) + viewModel.persistCurrentRawEditMetadata( + currentEditSourcePhoto + ) { success -> + if (success) { + requestRawPreviewRefresh() + } + } + }, + onRawHighlightsAdjustmentChange = { + viewModel.saveRawHighlightsAdjustmentValue(currentEditSourcePhoto, it) + }, + onRawShadowsAdjustmentChange = { + viewModel.saveRawShadowsAdjustmentValue(currentEditSourcePhoto, it) + }, + onRawBlackPointCorrectionChange = { + viewModel.saveRawBlackPointCorrectionValue(currentEditSourcePhoto, it) + }, + onRawWhitePointCorrectionChange = { + viewModel.saveRawWhitePointCorrectionValue(currentEditSourcePhoto, it) + }, + onRawBlackLevelModeChange = { + viewModel.saveRawBlackLevelMode(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onRawCustomBlackLevelChange = { + viewModel.saveRawCustomBlackLevel(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onRawWhiteLevelModeChange = { + viewModel.saveRawWhiteLevelMode(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onRawCustomWhiteLevelChange = { + viewModel.saveRawCustomWhiteLevel(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onRawCfaCorrectionModeChange = { + viewModel.saveRawCfaCorrectionMode(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onRawColorEngineChange = { + viewModel.saveRawColorEngine(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onRawToneMappingParametersChange = { + viewModel.saveRawToneMappingParameters(currentEditSourcePhoto, it) + }, + embeddedDngProfiles = embeddedDngProfileUiState.options, + selectedEmbeddedDngProfileId = activeEmbeddedDngProfileId, + onSelectEmbeddedDngProfile = { profile -> + viewModel.selectRawEmbeddedDngProfileForEdit( + profileId = profile.id, + hasProfileGainTableMap = + profile.hasProfileGainTableMap, + ) + }, + onSpectralFilmSelectionChange = { + viewModel.saveRawSpectralFilmSelection(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + onSpectralFilmPrintChange = { + viewModel.saveRawSpectralFilmPrint(currentEditSourcePhoto, it) { + requestRawPreviewRefresh() + } + }, + // The panel ends every Fotufilm change with onAdjustmentEnd, which persists it. + fotufilmDocument = editRawFotufilmDocument, + onFotufilmDocumentChange = { viewModel.editRawFotufilmDocument.value = it }, + onAdjustmentStart = { }, + onAdjustmentEnd = { + viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { + requestRawPreviewRefresh() + } + }, + onOpenBaselineLutSheet = { + showRawBaselineLutSelectorSheet = true + }, + showAdaptiveExposureControl = isImportedRaw, + showDngMetadataControls = true, + contentMode = RawEditPanelContentMode.FULL, + compactLayout = true, + modifier = Modifier.fillMaxWidth() + ) + SwitchSettingItem( + title = stringResource(R.string.settings_raw_lens_shading_correction), + description = stringResource(R.string.settings_raw_lens_shading_correction_description), + checked = editRawLensShadingCorrectionEnabled, + onCheckedChange = { enabled -> + viewModel.saveRawLensShadingCorrectionEnabled( + currentEditSourcePhoto, + enabled + ) { success -> + if (success) requestRawPreviewRefresh() + } + } + ) + } + EDIT_TAB_CROP -> { + if (!currentPhoto.isVideo) { + // 裁剪编辑 + val availablePhotoAspectRatios by cameraViewModel.availablePhotoAspectRatios.collectAsState() + CropEditPanel( + selectedOption = editCropAspectOption, + onOptionSelected = { viewModel.setCropAspectOption(it) }, + straightenDegrees = editStraightenDegrees, + onStraightenDegreesChanged = { + viewModel.setStraightenDegrees(it) + }, + isHorizontallyMirrored = editMirrorHorizontal, + onRotate = { + cropPreviewBitmap = null + viewModel.rotateEditClockwise() + }, + onMirrorHorizontal = { + cropPreviewBitmap = null + viewModel.toggleEditHorizontalMirror() + }, + availableRatios = availablePhotoAspectRatios, + imageWidth = cropPreviewBitmap?.width ?: 1, + imageHeight = cropPreviewBitmap?.height ?: 1 + ) + } } } } @@ -2136,7 +2079,6 @@ fun GalleryEditScreen( selectedLutId = editRawBaselineLutId, availableLuts = availableLuts, thumbnail = thumbnailBitmap, - containerColor = Color(0x151A1A1A), onSelectLut = { lutId -> viewModel.saveRawBaselineLutSelection(currentEditSourcePhoto, lutId) }, @@ -2407,6 +2349,83 @@ private fun CompactToggleChip( } } +@Composable +private fun EditPanelHeader( + collapsed: Boolean, + selectedTab: Int, + isVideo: Boolean, + isRaw: Boolean, + scrollState: ScrollState, + onTabSelected: (Int) -> Unit, + onToggle: () -> Unit, +) { + val headerModifier = Modifier.fillMaxWidth().height(48.dp) + val iconColor = Color.White.copy(alpha = 0.82f) + if (collapsed) { + Row( + modifier = headerModifier + .clickable( + onClickLabel = stringResource(R.string.edit_panel_expand), + role = Role.Button, + onClick = onToggle, + ) + .padding(start = 20.dp, end = 12.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = stringResource(R.string.edit_panel_title), + color = iconColor, + fontSize = 14.sp, + modifier = Modifier.weight(1f), + ) + Icon(AppIcons.ExpandLess, contentDescription = null, tint = iconColor) + } + } else { + Row(modifier = headerModifier, verticalAlignment = Alignment.CenterVertically) { + Row( + modifier = Modifier + .weight(1f) + .horizontalScroll(scrollState) + .padding(start = 16.dp, end = 8.dp), + horizontalArrangement = Arrangement.spacedBy(24.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + TabItem(stringResource(R.string.filter), selectedTab == EDIT_TAB_LUT) { + onTabSelected(EDIT_TAB_LUT) + } + if (!isVideo) { + TabItem(stringResource(R.string.frame), selectedTab == EDIT_TAB_FRAME) { + onTabSelected(EDIT_TAB_FRAME) + } + } + TabItem(stringResource(R.string.edit), selectedTab == EDIT_TAB_ADJUSTMENTS) { + onTabSelected(EDIT_TAB_ADJUSTMENTS) + } + TabItem(stringResource(R.string.recipe_tab_post), selectedTab == EDIT_TAB_DETAIL) { + onTabSelected(EDIT_TAB_DETAIL) + } + if (isRaw) { + TabItem(stringResource(R.string.gallery_raw_badge), selectedTab == EDIT_TAB_RAW) { + onTabSelected(EDIT_TAB_RAW) + } + } + if (!isVideo) { + TabItem(stringResource(R.string.crop), selectedTab == EDIT_TAB_CROP) { + onTabSelected(EDIT_TAB_CROP) + } + } + } + IconButton(onClick = onToggle) { + Icon( + AppIcons.ExpandMore, + contentDescription = stringResource(R.string.edit_panel_minimize), + tint = iconColor, + ) + } + } + } +} + /** * 标签页项 */ @@ -2575,23 +2594,41 @@ private fun FrameOption( private fun ZoomableEditImage( previewBitmap: Bitmap?, isLutEditing: Boolean, + allowZoomOutBelowFit: Boolean, contentDescription: String, - onZoomChange: (isZoomed: Boolean) -> Unit = {}, + onZoomChange: (Float) -> Unit, modifier: Modifier = Modifier ) { val context = LocalContext.current - val maxZoom = previewBitmap?.let { max(it.width, it.height) / 500f } ?: 1f - val zoomableState = rememberZoomableImageState( - zoomableState = rememberZoomableState(zoomSpec = ZoomSpec(maxZoomFactor = maxZoom)) + val maxZoom = previewBitmap?.let { (max(it.width, it.height) / 500f).coerceAtLeast(1f) } ?: 1f + val zoomState = rememberZoomableState( + zoomSpec = ZoomSpec( + maxZoomFactor = maxZoom, + minZoomFactor = if (allowZoomOutBelowFit) EDIT_PREVIEW_MIN_ZOOM else 1f, + ) ) + val imageState = rememberZoomableImageState(zoomableState = zoomState) + val currentOnZoomChange by rememberUpdatedState(onZoomChange) - LaunchedEffect(zoomableState.zoomableState.zoomFraction) { - onZoomChange((zoomableState.zoomableState.zoomFraction ?: 0f) > 0.01f) + LaunchedEffect(zoomState) { + snapshotFlow { + val transformation = zoomState.contentTransformation + if (transformation.isSpecified) transformation.scaleMetadata.userZoom else 1f + }.collect { currentOnZoomChange(it) } } - LaunchedEffect(isLutEditing) { + LaunchedEffect(zoomState, isLutEditing) { if (isLutEditing) { - zoomableState.zoomableState.resetZoom() + zoomState.zoomTo(zoomState.awaitContentTransformation().scaleMetadata.initialScale.scaleX) + } + } + + LaunchedEffect(zoomState, allowZoomOutBelowFit) { + if (!allowZoomOutBelowFit) { + val scale = zoomState.awaitContentTransformation().scaleMetadata + if (scale.userZoom < 1f) { + zoomState.zoomTo(scale.initialScale.scaleX, animationSpec = snap()) + } } } @@ -2608,13 +2645,30 @@ private fun ZoomableEditImage( model = model, contentDescription = contentDescription, contentScale = ContentScale.Fit, - state = zoomableState, - onDoubleClick = DoubleClickToZoomListener.cycle(maxZoomFactor = 3f), + state = imageState, + onDoubleClick = EditPreviewDoubleClick, modifier = Modifier.fillMaxSize() ) } } +private suspend fun ZoomableState.awaitContentTransformation(): ZoomableContentTransformation = + snapshotFlow { contentTransformation }.first { it.isSpecified } + +private val EditPreviewDoubleClick = DoubleClickToZoomListener { state, centroid -> + val transformation = state.contentTransformation + if (transformation.isSpecified) { + val scale = transformation.scaleMetadata + val fitScale = scale.initialScale.scaleX + val zoomedScale = minOf(EDIT_PREVIEW_DOUBLE_TAP_ZOOM, state.zoomSpec.maximum.factor).coerceAtLeast(fitScale) + if (scale.userZoom < 1f || transformation.scale.scaleX >= zoomedScale - 0.05f) { + state.zoomTo(fitScale) + } else { + state.zoomTo(zoomedScale, centroid) + } + } +} + @Composable private fun SegmentedControl(