add auto-scroll to center current measure if partition scrollState max !0
This commit is contained in:
parent
01d44d6b42
commit
7c1f920ae8
3 changed files with 37 additions and 5 deletions
|
|
@ -34,6 +34,7 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
|
|
@ -64,6 +65,7 @@ object ScreenSolfa : Screen {
|
|||
val gridTUOData = GridTUOData(measure, tuoList, stanza)
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val scrollState = rememberScrollState()
|
||||
var viewportHeight by remember { mutableStateOf(0) }
|
||||
|
||||
var isScanning by remember { mutableStateOf(false) }
|
||||
var qrCodeResult by remember { mutableStateOf("Aucun code scanné") }
|
||||
|
|
@ -75,7 +77,8 @@ object ScreenSolfa : Screen {
|
|||
qrCodeResult = qrCodeResult,
|
||||
onScannerButtonClick = {
|
||||
isScanning = true
|
||||
}
|
||||
},
|
||||
solfaScrollState = scrollState
|
||||
) { paddingValues ->
|
||||
Box(
|
||||
Modifier.fillMaxSize().padding(paddingValues)
|
||||
|
|
@ -91,6 +94,9 @@ object ScreenSolfa : Screen {
|
|||
showContextualMenu = true
|
||||
}
|
||||
)
|
||||
}
|
||||
.onGloballyPositioned { coordinates ->
|
||||
viewportHeight = coordinates.size.height
|
||||
},
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
|
|
@ -192,7 +198,7 @@ object ScreenSolfa : Screen {
|
|||
}
|
||||
Row (
|
||||
modifier = Modifier
|
||||
.height(199.dp)
|
||||
.height(75.dp)
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ fun MainScreenWithDrawer(
|
|||
sharedScreenModel: SharedScreenModel,
|
||||
qrCodeResult: String,
|
||||
onScannerButtonClick: () -> Unit,
|
||||
solfaScrollState: ScrollState,
|
||||
content: @Composable (PaddingValues) -> Unit,
|
||||
) {
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
|
|
@ -79,7 +80,7 @@ val isPos by sharedScreenModel.isPos.collectAsState()
|
|||
var isDragging = sharedScreenModel.isDragging
|
||||
val currentPos by sharedScreenModel.currentPos.collectAsState()
|
||||
val duration by sharedScreenModel.duration.collectAsState()
|
||||
val midiFile = "whawyd3.mid"
|
||||
val midiFile = "whawyd3.mid" //What do we gain by all our hard work?
|
||||
var refreshTrigeer by remember { mutableStateOf(0)}
|
||||
|
||||
val volumelevel by sharedScreenModel.volumeLevel.collectAsState()
|
||||
|
|
@ -248,6 +249,7 @@ LaunchedEffect(isPlay, isPos) {
|
|||
currentPos = currentPos,
|
||||
volume = volumelevel,
|
||||
duration = duration,
|
||||
solfaScrollState,
|
||||
onPlayPauseClick = {
|
||||
sharedScreenModel.togglePlayPause()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
package mg.dot.feufaro.ui
|
||||
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.core.AnimationSpec
|
||||
import androidx.compose.animation.core.ExperimentalAnimationSpecApi
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
|
|
@ -34,6 +39,7 @@ fun MidiControlPanel(
|
|||
currentPos: Float,
|
||||
volume: Float,
|
||||
duration: Float,
|
||||
solfaScrollState: ScrollState,
|
||||
onPlayPauseClick: () -> Unit,
|
||||
onSeek: (Float) -> Unit,
|
||||
onVolumeChange: (Float) -> Unit,
|
||||
|
|
@ -62,6 +68,25 @@ fun MidiControlPanel(
|
|||
var showSATBTools by remember { mutableStateOf(false) }
|
||||
var expandedCtl by remember { mutableStateOf(false) }
|
||||
val platform = getPlatform().name
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
LaunchedEffect(currentPos, duration, solfaScrollState.viewportSize, solfaScrollState.maxValue) {
|
||||
if (duration > 0f && solfaScrollState.maxValue > 0) {
|
||||
val progress = (currentPos / duration).coerceIn(0f, 1f)
|
||||
val viewportHeight = solfaScrollState.viewportSize.toFloat()
|
||||
val totalContentHeight = solfaScrollState.maxValue + viewportHeight
|
||||
|
||||
val targetY = (progress * (totalContentHeight-200)) - (viewportHeight / 2)
|
||||
val finalTarget = targetY.coerceIn(0f, solfaScrollState.maxValue.toFloat())
|
||||
solfaScrollState.animateScrollTo(
|
||||
value = finalTarget.toInt(),
|
||||
animationSpec = tween (
|
||||
durationMillis = 300,
|
||||
easing = LinearEasing
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(tempo) {
|
||||
currentBpm = mediaPlayer.getCurrentBPM()
|
||||
}
|
||||
|
|
@ -80,7 +105,7 @@ fun MidiControlPanel(
|
|||
|
||||
tempo = newFactor
|
||||
mediaPlayer?.setTempo(newFactor)
|
||||
println("tempo : $tempo")
|
||||
// println("tempo : $tempo")
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
|
@ -93,7 +118,6 @@ fun MidiControlPanel(
|
|||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth(if (platform.startsWith("Android")) 1f else 0.6f)
|
||||
.padding(16.dp)
|
||||
.background(color = Color.Gray.copy(alpha = 0.5f), shape = RoundedCornerShape(size = 5.dp)),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue