@@ -28,6 +28,7 @@ import androidx.compose.ui.unit.dp
2828
2929const val WAVEFORM_THUMB_SIZE = 20
3030const val WAVEFORM_SIZE = 30
31+
3132@OptIn(ExperimentalMaterial3Api ::class )
3233@Composable
3334fun ComposeWaveformSeekBar (value : Float , onValueChange : (Float ) -> Unit , modifier : Modifier , waveData : FloatArray ) {
@@ -40,33 +41,37 @@ fun ComposeWaveformSeekBar(value: Float, onValueChange: (Float) -> Unit, modifie
4041 value = value,
4142 onValueChange = onValueChange,
4243 track = {
43- Box (modifier = modifier
44- .drawWithCache {
45- onDrawBehind {
46- val height = this .size.height
47- val midpoint = (this .size.height / 2f )
48- val barGap: Float = (this .size.width - waveData.size * barWidth) / (waveData.size - 1 ).toFloat() + 1
49- for (i in waveData.indices) {
50- val x: Float = i * (barWidth + barGap)
51- val y: Float = waveData[i] * height
52- val isXBeforeThumb = (x / this .size.width) <= value + 0.025
44+ Box (
45+ modifier = modifier
46+ .drawWithCache {
47+ onDrawBehind {
48+ val height = this .size.height
49+ val width = this .size.width
50+ val midpoint = (this .size.height / 2f )
51+
52+ val barGap = (width - waveData.size * barWidth) / (waveData.size - 1 ).toFloat() + 1
53+ for (i in waveData.indices) {
54+ val x: Float = i * (barWidth + barGap)
55+ val y: Float = waveData[i] * height
56+ val isXBeforeThumb = (x / this .size.width) <= value + 0.025
5357
54- drawLine(
55- if (isXBeforeThumb) inversePrimary else onPrimaryContainer,
56- start = Offset (x, midpoint - y),
57- end = Offset (x, midpoint + y),
58- strokeWidth = Stroke .DefaultMiter ,
59- cap = StrokeCap .Round
60- )
58+ drawLine(
59+ if (isXBeforeThumb) inversePrimary else onPrimaryContainer,
60+ start = Offset (x, midpoint - y),
61+ end = Offset (x, midpoint + y),
62+ strokeWidth = Stroke .DefaultMiter ,
63+ cap = StrokeCap .Round
64+ )
65+ }
6166 }
6267 }
63- }
6468 )
6569 },
6670 thumb = {
67- Box (modifier = Modifier
68- .size(thumbSize)
69- .background(inversePrimary, shape = CircleShape )
71+ Box (
72+ modifier = Modifier
73+ .size(thumbSize)
74+ .background(inversePrimary, shape = CircleShape )
7075 )
7176 }
7277 )
0 commit comments