mirror of
http://180.163.74.83:13000/zhangzhenghao/MPVN_Android.git
synced 2025-12-12 23:34:28 +00:00
灯光亮度支持触控拖动
This commit is contained in:
parent
f1bf8fd581
commit
a9f61e0663
@ -40,6 +40,7 @@ import android.view.SoundEffectConstants
|
|||||||
import androidx.compose.foundation.horizontalScroll
|
import androidx.compose.foundation.horizontalScroll
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
|
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.foundation.layout.offset
|
import androidx.compose.foundation.layout.offset
|
||||||
import androidx.compose.ui.draw.rotate
|
import androidx.compose.ui.draw.rotate
|
||||||
@ -1342,23 +1343,47 @@ fun LightList(modifier: Modifier = Modifier) {
|
|||||||
@Composable
|
@Composable
|
||||||
fun DotsProgress(percent: Float, onPercentChange: (Float) -> Unit = {}, enabled: Boolean = true) {
|
fun DotsProgress(percent: Float, onPercentChange: (Float) -> Unit = {}, enabled: Boolean = true) {
|
||||||
val total = 12
|
val total = 12
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.pointerInput(enabled) {
|
modifier = Modifier
|
||||||
if (enabled) {
|
.pointerInput(enabled) {
|
||||||
detectTapGestures { offset ->
|
if (enabled) {
|
||||||
// 计算点击的是第几个点
|
val dotWidth = 8.dp.toPx()
|
||||||
val dotWidth = 6.dp.toPx()
|
|
||||||
val spacing = 4.dp.toPx()
|
val spacing = 4.dp.toPx()
|
||||||
val totalWidth = (dotWidth + spacing) * total - spacing
|
val totalWidth = (dotWidth + spacing) * total - spacing
|
||||||
val clickedIndex = ((offset.x / totalWidth) * total).toInt().coerceIn(0, total - 1)
|
|
||||||
// 更新百分比
|
// 支持拖动手势
|
||||||
val newPercent = (clickedIndex + 1).toFloat() / total
|
detectHorizontalDragGestures(
|
||||||
onPercentChange(newPercent)
|
onDragStart = { offset ->
|
||||||
|
// 开始拖动时立即更新
|
||||||
|
val newPercent = (offset.x / totalWidth).coerceIn(0f, 1f)
|
||||||
|
onPercentChange(newPercent)
|
||||||
|
},
|
||||||
|
onDragEnd = { },
|
||||||
|
onDragCancel = { },
|
||||||
|
onHorizontalDrag = { change, _ ->
|
||||||
|
change.consume()
|
||||||
|
val newPercent = (change.position.x / totalWidth).coerceIn(0f, 1f)
|
||||||
|
onPercentChange(newPercent)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pointerInput(enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
val dotWidth = 8.dp.toPx()
|
||||||
|
val spacing = 4.dp.toPx()
|
||||||
|
val totalWidth = (dotWidth + spacing) * total - spacing
|
||||||
|
|
||||||
|
// 也支持点击
|
||||||
|
detectTapGestures { offset ->
|
||||||
|
val newPercent = (offset.x / totalWidth).coerceIn(0f, 1f)
|
||||||
|
onPercentChange(newPercent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
repeat(total) { i ->
|
repeat(total) { i ->
|
||||||
val filled = i < (percent * total).toInt()
|
val filled = i < (percent * total).toInt()
|
||||||
@ -1367,11 +1392,6 @@ fun DotsProgress(percent: Float, onPercentChange: (Float) -> Unit = {}, enabled:
|
|||||||
.size(8.dp)
|
.size(8.dp)
|
||||||
.clip(RoundedCornerShape(4.dp))
|
.clip(RoundedCornerShape(4.dp))
|
||||||
.background(if (filled) Color(0xFFA9F0FF) else Color(0xFF3A3A3A))
|
.background(if (filled) Color(0xFFA9F0FF) else Color(0xFF3A3A3A))
|
||||||
.clickable(enabled = enabled) {
|
|
||||||
// 点击某个点直接设置到该亮度
|
|
||||||
val newPercent = (i + 1).toFloat() / total
|
|
||||||
onPercentChange(newPercent)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user