add auto-scroll to center current measure if partition scrollState max !0

This commit is contained in:
hasinarak3@gmail.com 2026-02-06 14:19:55 +03:00
parent 01d44d6b42
commit 7c1f920ae8
3 changed files with 37 additions and 5 deletions

View file

@ -34,6 +34,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput 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.FontStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntOffset
@ -64,6 +65,7 @@ object ScreenSolfa : Screen {
val gridTUOData = GridTUOData(measure, tuoList, stanza) val gridTUOData = GridTUOData(measure, tuoList, stanza)
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
var viewportHeight by remember { mutableStateOf(0) }
var isScanning by remember { mutableStateOf(false) } var isScanning by remember { mutableStateOf(false) }
var qrCodeResult by remember { mutableStateOf("Aucun code scanné") } var qrCodeResult by remember { mutableStateOf("Aucun code scanné") }
@ -75,7 +77,8 @@ object ScreenSolfa : Screen {
qrCodeResult = qrCodeResult, qrCodeResult = qrCodeResult,
onScannerButtonClick = { onScannerButtonClick = {
isScanning = true isScanning = true
} },
solfaScrollState = scrollState
) { paddingValues -> ) { paddingValues ->
Box( Box(
Modifier.fillMaxSize().padding(paddingValues) Modifier.fillMaxSize().padding(paddingValues)
@ -91,6 +94,9 @@ object ScreenSolfa : Screen {
showContextualMenu = true showContextualMenu = true
} }
) )
}
.onGloballyPositioned { coordinates ->
viewportHeight = coordinates.size.height
}, },
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
@ -192,7 +198,7 @@ object ScreenSolfa : Screen {
} }
Row ( Row (
modifier = Modifier modifier = Modifier
.height(199.dp) .height(75.dp)
) { ) {
} }
} }

View file

@ -50,6 +50,7 @@ fun MainScreenWithDrawer(
sharedScreenModel: SharedScreenModel, sharedScreenModel: SharedScreenModel,
qrCodeResult: String, qrCodeResult: String,
onScannerButtonClick: () -> Unit, onScannerButtonClick: () -> Unit,
solfaScrollState: ScrollState,
content: @Composable (PaddingValues) -> Unit, content: @Composable (PaddingValues) -> Unit,
) { ) {
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
@ -79,7 +80,7 @@ val isPos by sharedScreenModel.isPos.collectAsState()
var isDragging = sharedScreenModel.isDragging var isDragging = sharedScreenModel.isDragging
val currentPos by sharedScreenModel.currentPos.collectAsState() val currentPos by sharedScreenModel.currentPos.collectAsState()
val duration by sharedScreenModel.duration.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)} var refreshTrigeer by remember { mutableStateOf(0)}
val volumelevel by sharedScreenModel.volumeLevel.collectAsState() val volumelevel by sharedScreenModel.volumeLevel.collectAsState()
@ -248,6 +249,7 @@ LaunchedEffect(isPlay, isPos) {
currentPos = currentPos, currentPos = currentPos,
volume = volumelevel, volume = volumelevel,
duration = duration, duration = duration,
solfaScrollState,
onPlayPauseClick = { onPlayPauseClick = {
sharedScreenModel.togglePlayPause() sharedScreenModel.togglePlayPause()
}, },

View file

@ -1,6 +1,11 @@
package mg.dot.feufaro.ui package mg.dot.feufaro.ui
import androidx.compose.animation.* 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.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@ -34,6 +39,7 @@ fun MidiControlPanel(
currentPos: Float, currentPos: Float,
volume: Float, volume: Float,
duration: Float, duration: Float,
solfaScrollState: ScrollState,
onPlayPauseClick: () -> Unit, onPlayPauseClick: () -> Unit,
onSeek: (Float) -> Unit, onSeek: (Float) -> Unit,
onVolumeChange: (Float) -> Unit, onVolumeChange: (Float) -> Unit,
@ -62,6 +68,25 @@ fun MidiControlPanel(
var showSATBTools by remember { mutableStateOf(false) } var showSATBTools by remember { mutableStateOf(false) }
var expandedCtl by remember { mutableStateOf(false) } var expandedCtl by remember { mutableStateOf(false) }
val platform = getPlatform().name 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) { LaunchedEffect(tempo) {
currentBpm = mediaPlayer.getCurrentBPM() currentBpm = mediaPlayer.getCurrentBPM()
} }
@ -80,7 +105,7 @@ fun MidiControlPanel(
tempo = newFactor tempo = newFactor
mediaPlayer?.setTempo(newFactor) mediaPlayer?.setTempo(newFactor)
println("tempo : $tempo") // println("tempo : $tempo")
} }
Column( Column(
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@ -93,7 +118,6 @@ fun MidiControlPanel(
Column( Column(
modifier = modifier modifier = modifier
.fillMaxWidth(if (platform.startsWith("Android")) 1f else 0.6f) .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)), .background(color = Color.Gray.copy(alpha = 0.5f), shape = RoundedCornerShape(size = 5.dp)),
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {