From fea05c3f21080194c03d6fb8cfe45d6369143c1c Mon Sep 17 00:00:00 2001 From: Hasinjato Date: Thu, 5 Nov 2026 15:47:50 +0300 Subject: [PATCH] =?UTF-8?q?Implements=20litanies=20lyrics=20truncate=20&?= =?UTF-8?q?=20all=20lyrics=20bottom=20'=E2=8B=86'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mg/dot/feufaro/solfa/POneStanzaLyrics.kt | 16 +++++ .../kotlin/mg/dot/feufaro/solfa/Solfa.kt | 1 + .../mg/dot/feufaro/solfa/TimeUnitObject.kt | 70 +++++++++++++++++-- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/POneStanzaLyrics.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/POneStanzaLyrics.kt index 8feeb68..740a3bd 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/POneStanzaLyrics.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/POneStanzaLyrics.kt @@ -3,6 +3,15 @@ package mg.dot.feufaro.solfa class POneStanzaLyrics { private val lyrics: MutableList = mutableListOf("") private val alternativeLyrics: MutableMap> = mutableMapOf() + + private val litany: MutableMap = mutableMapOf() + companion object { + private val REGEX_LITANY = Regex("\\$\\{L[:=]([^\\}]*)\\}") + } + fun getLitany(stanzaNumber: Int): String? = litany[stanzaNumber] + fun copyLitany(fromStanzaNumber: Int, toStanzaNumber: Int) { + litany[fromStanzaNumber]?.let { litany.putIfAbsent(toStanzaNumber, it) } + } fun getLyrics(stanzaNumber: Int) : String { return this.lyrics[stanzaNumber] } @@ -10,6 +19,13 @@ class POneStanzaLyrics { while (this.lyrics.size <= stanzaNumber) { this.lyrics.add("") } + val litanyText = REGEX_LITANY.findAll(lyrics) + .map { it.groupValues[1].trim() } + .filter { it.isNotEmpty() } + .joinToString(" ") + if (litanyText.isNotEmpty()) { + litany[stanzaNumber] = litanyText + } this.lyrics[stanzaNumber] = lyrics.replace(Regex("\\$\\{[^\\}]*\\}-?"), "") } fun setAlternativeLyrics(stanzaNumber: Int, voiceNumber: Int, text: String) { diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt index 469c21f..4e8d73c 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt @@ -2893,6 +2893,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository for (i in refrainBeginsAt..refrainMax) { L[i].setLyrics(stanzaNumber, L[i].getLyrics(1)) L[i].copyAlternativeLyrics(1, stanzaNumber) + L[i].copyLitany(1, stanzaNumber) } } diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt index 57e1605..cf285f2 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt @@ -143,6 +143,11 @@ class TimeUnitObject (val pTemplate: PTemplate, val prevTUO: TimeUnitObject?, co } fun isLitany(): Boolean = pTemplate.hasMarker($$"${L}") + fun litanyText(stanzaNumber: Int): String? { + if (!isLitany()) return null + return lyrics.firstNotNullOfOrNull { it.getLitany(stanzaNumber) }?.takeIf { it.isNotBlank() } + } + fun addLyrics(lyricsIn: POneStanzaLyrics) { lyrics.add(lyricsIn) } @@ -812,6 +817,17 @@ fun LazyVerticalGridTUO( } } + val litanyLabels: Map> = remember(tuoList, currentStanza) { + val map = LinkedHashMap>() + tuoList.drop(1).forEach { litanyTuo -> + val text = litanyTuo.litanyText(currentStanza) + if (text != null) { + map[litanyTuo.numBlock] = "⋆".repeat(map.size + 1) to text.trim() + } + } + map + } + if (!isLayoutReady) { Box( modifier = Modifier @@ -1114,7 +1130,7 @@ fun LazyVerticalGridTUO( ) } } - } + } if (showTooltipWarn) { TooltipBox( state = tooltipState, @@ -1135,11 +1151,20 @@ fun LazyVerticalGridTUO( } } - val allTemps = measureTUOs.map { it.getSingleSyllable(currentStanza) } - val maxLines = allTemps.maxOfOrNull { it.size } ?: 0 - val textMeasurer = rememberTextMeasurer() + val litanyStyle = MaterialTheme.typography.titleMedium + val litanyMaxWidthPx = with(density) { ((gridWidthDp / gridColumnCount) - 4.dp).toPx() } + val allTemps = measureTUOs.map { oneTUO -> + val litany = litanyLabels[oneTUO.numBlock] + if (litany != null) { + listOf(fitLitanyLabel(litany.first, litany.second, textMeasurer, litanyStyle, litanyMaxWidthPx)) + } else { + oneTUO.getSingleSyllable(currentStanza) + } + } + val maxLines = allTemps.maxOfOrNull { it.size } ?: 0 + Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Start @@ -1188,6 +1213,7 @@ fun LazyVerticalGridTUO( overflow = TextOverflow.Visible, style = TextStyle( color = when { + litanyLabels.containsKey(measureTUOs[syls_i].numBlock) -> MaterialTheme.colorScheme.onBackground.copy(0.7f) (isTooLong) -> MaterialTheme.colorScheme.onBackground (index == 0) -> MaterialTheme.colorScheme.onBackground else -> MaterialTheme.colorScheme.onBackground @@ -1206,8 +1232,23 @@ fun LazyVerticalGridTUO( } } } + } + if (litanyLabels.isNotEmpty()) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(start = 8.dp, end = 8.dp, top = 12.dp, bottom = 8.dp) + ) { + litanyLabels.values.forEach { (stars, fullText) -> + Text( + text = "$stars$fullText", + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onBackground.copy(0.7f) + ) + } } } + } } } } @@ -1464,6 +1505,27 @@ private fun TuoEditDialogWrapper( ) } +fun fitLitanyLabel( + stars: String, + text: String, + textMeasurer: TextMeasurer, + style: TextStyle, + maxWidthPx: Float +): String { + fun widthOf(s: String): Int = + textMeasurer.measure(text = s, style = style, maxLines = 1, softWrap = false).size.width + + val full = stars + text + if (widthOf(full) <= maxWidthPx) return full + var end = text.length + while (end > 0) { + val candidate = stars + text.substring(0, end).trimEnd() + "..." + if (widthOf(candidate) <= maxWidthPx) return candidate + end-- + } + return stars +} + @Composable fun makeSpaceBetweenSyllables( textMeasurer: TextMeasurer,