feat: add macro camera support to zoom control bar

This commit is contained in:
zhoubinjia committed 2026-05-11 19:12:22 +08:00
1 parent d5543b2792
commit b54fc8de3e
2 files changed
+105 -23

No files matched your search

@@ -11,6 +11,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.FilterVintage
import androidx.compose.material.icons.filled.Palette
import androidx.compose.material.icons.filled.SwapHoriz
import androidx.compose.material3.Icon
@@ -93,6 +94,10 @@ fun ZoomControlBar(
}
val zoomStops = viewModel.allZoomStops(lensZoomStops, mainCamera, currentCamera, customFocalLengths, hiddenFocalLengths)
val macroCameras = remember(availableCameras) {
availableCameras.filter { it.lensType == LensType.BACK_MACRO }
}
val cameraState by viewModel.state.collectAsState()
val minZoom = remember(cameraState.availableCameras) {
cameraState.availableCameras.filter { it.lensType != LensType.FRONT }.minOfOrNull { it.minZoom * it.intrinsicZoomRatio } ?: 1f
@@ -293,6 +298,8 @@ fun ZoomControlBar(
lensStops = lensZoomStops,
customLensStops = customLensZoomStops,
stops = effectiveStops,
macroCameras = macroCameras,
currentCameraId = currentCameraIdState,
mainCamera = mainCamera,
displayMode = displayMode,
onZoomChange = { stop ->
@@ -305,6 +312,7 @@ fun ZoomControlBar(
customZoomStop = null
replacedStopIndex = -1
},
onLensSwitch = onLensSwitch,
modifier = Modifier.fillMaxHeight()
)
}
@@ -335,9 +343,12 @@ fun ZoomRuler(
lensStops: List<Float>,
customLensStops: List<Float>,
stops: List<Float>,
macroCameras: List<CameraInfo>,
currentCameraId: String,
mainCamera: CameraInfo?,
displayMode: ZoomDisplayMode,
onZoomChange: (Float) -> Unit,
onLensSwitch: (String) -> Unit,
modifier: Modifier = Modifier
) {
val activeColor = Color(0xFFFFD700)
@@ -347,19 +358,13 @@ fun ZoomRuler(
Row(
modifier = modifier
.background(Color.Black.copy(alpha = 0.3f), RoundedCornerShape(16.dp))
.pointerInput(Unit) {
detectTapGestures { offset ->
val width = size.width
val stepWidth = width / stopsState.size
val index = (offset.x / stepWidth).toInt().coerceIn(0, stopsState.lastIndex)
onZoomChange(stopsState[index])
}
},
.background(Color.Black.copy(alpha = 0.3f), RoundedCornerShape(16.dp)),
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.CenterVertically
) {
val selectedStopIndex = stops.indices.minByOrNull { abs(stops[it] - zoomRatio) }
val isCurrentMacro = macroCameras.any { it.cameraId == currentCameraId }
val selectedStopIndex = if (isCurrentMacro) -1 else stops.indices.minByOrNull { abs(stops[it] - zoomRatio) }
stops.forEachIndexed { index, stop ->
val isSelected = index == selectedStopIndex && abs(stop - zoomRatio) <= 0.01f
val isCustomLensStop = customLensStops.any { abs(it - stop) <= 0.01f }
@@ -382,10 +387,46 @@ fun ZoomRuler(
textDecoration = if (lensStops.contains(stop)) TextDecoration.Underline else TextDecoration.None
)
Box(modifier = Modifier.size(32.dp).autoRotate(), contentAlignment = Alignment.Center) {
Box(
modifier = Modifier
.size(32.dp)
.autoRotate()
.pointerInput(stop) {
detectTapGestures { onZoomChange(stop) }
},
contentAlignment = Alignment.Center
) {
Text(text, style = style)
}
}
if (macroCameras.isNotEmpty()) {
Box(
modifier = Modifier
.width(1.dp)
.height(12.dp)
.background(Color.White.copy(alpha = 0.2f))
)
macroCameras.forEach { macroCam ->
val isSelected = macroCam.cameraId == currentCameraId
Box(
modifier = Modifier
.size(32.dp)
.autoRotate()
.pointerInput(macroCam.cameraId) {
detectTapGestures { onLensSwitch(macroCam.cameraId) }
},
contentAlignment = Alignment.Center
) {
Icon(
imageVector = Icons.Default.FilterVintage,
contentDescription = "Macro",
tint = if (isSelected) activeColor else inactiveColor,
modifier = Modifier.size(if (isSelected) 16.dp else 14.dp)
)
}
}
}
}
}
@@ -10,6 +10,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.FilterVintage
import androidx.compose.material.icons.filled.SwapHoriz
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@@ -83,6 +84,10 @@ fun ZoomControlBarVerticel(
}
val zoomStops = viewModel.allZoomStops(lensZoomStops, mainCamera, currentCamera, customFocalLengths, hiddenFocalLengths)
val macroCameras = remember(availableCameras) {
availableCameras.filter { it.lensType == LensType.BACK_MACRO }
}
val cameraState by viewModel.state.collectAsState()
val minZoom = remember(cameraState.availableCameras) {
cameraState.availableCameras.filter { it.lensType != LensType.FRONT }.minOfOrNull { it.minZoom * it.intrinsicZoomRatio } ?: 1f
@@ -277,6 +282,8 @@ fun ZoomControlBarVerticel(
lensStops = lensZoomStops,
customLensStops = customLensZoomStops,
stops = effectiveStops,
macroCameras = macroCameras,
currentCameraId = currentCameraIdState,
mainCamera = mainCamera,
displayMode = displayMode,
onZoomChange = { stop ->
@@ -289,6 +296,7 @@ fun ZoomControlBarVerticel(
customZoomStop = null
replacedStopIndex = -1
},
onLensSwitch = onLensSwitch,
modifier = Modifier.fillMaxWidth()
)
}
@@ -319,9 +327,12 @@ fun ZoomRulerVertical(
lensStops: List<Float>,
customLensStops: List<Float>,
stops: List<Float>,
macroCameras: List<CameraInfo>,
currentCameraId: String,
mainCamera: CameraInfo?,
displayMode: ZoomDisplayMode,
onZoomChange: (Float) -> Unit,
onLensSwitch: (String) -> Unit,
modifier: Modifier = Modifier
) {
val activeColor = Color(0xFFFFD700)
@@ -331,20 +342,14 @@ fun ZoomRulerVertical(
Column(
modifier = modifier
.background(Color.Black.copy(alpha = 0.3f), RoundedCornerShape(16.dp))
.pointerInput(Unit) {
detectTapGestures { offset ->
val height = size.height
val stepHeight = height / stopsState.size
val index = (offset.y / stepHeight).toInt().coerceIn(0, stopsState.lastIndex)
onZoomChange(stopsState[index])
}
},
.background(Color.Black.copy(alpha = 0.3f), RoundedCornerShape(16.dp)),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
val selectedStopIndex = stops.indices.minByOrNull { abs(stops[it] - zoomRatio) }
stops.forEachIndexed { index, stop ->
val isCurrentMacro = macroCameras.any { it.cameraId == currentCameraId }
val selectedStopIndex = if (isCurrentMacro) -1 else stopsState.indices.minByOrNull { abs(stopsState[it] - zoomRatio) }
stopsState.forEachIndexed { index, stop ->
val isSelected = index == selectedStopIndex && abs(stop - zoomRatio) <= 0.01f
val isCustomLensStop = customLensStops.any { abs(it - stop) <= 0.01f }
@@ -366,10 +371,46 @@ fun ZoomRulerVertical(
textDecoration = if (lensStops.contains(stop)) TextDecoration.Underline else TextDecoration.None
)
Box(modifier = Modifier.size(32.dp).autoRotate(), contentAlignment = Alignment.Center) {
Box(
modifier = Modifier
.size(32.dp)
.autoRotate()
.pointerInput(stop) {
detectTapGestures { onZoomChange(stop) }
},
contentAlignment = Alignment.Center
) {
Text(text, style = style)
}
}
if (macroCameras.isNotEmpty()) {
Box(
modifier = Modifier
.width(12.dp)
.height(1.dp)
.background(Color.White.copy(alpha = 0.2f))
)
macroCameras.forEach { macroCam ->
val isSelected = macroCam.cameraId == currentCameraId
Box(
modifier = Modifier
.size(32.dp)
.autoRotate()
.pointerInput(macroCam.cameraId) {
detectTapGestures { onLensSwitch(macroCam.cameraId) }
},
contentAlignment = Alignment.Center
) {
Icon(
imageVector = Icons.Default.FilterVintage,
contentDescription = "Macro",
tint = if (isSelected) activeColor else inactiveColor,
modifier = Modifier.size(if (isSelected) 16.dp else 14.dp)
)
}
}
}
}
}