From ddce2250193cf7d33ded32a1087d6828a9c9565c Mon Sep 17 00:00:00 2001 From: Salomon BRYS Date: Thu, 4 Jul 2024 20:07:06 +0200 Subject: [PATCH] Stability --- .../kotlin/net/kodein/cup/sa/SourceCode.kt | 6 +++--- .../plugin/cup-laser/build.gradle.kts | 2 ++ .../kotlin/net/kodein/cup/laser/Laser.kt | 18 +++++++++--------- .../plugin/cup-speaker-window/build.gradle.kts | 2 ++ .../net/kodein/cup/speaker/SpeakerWindow.kt | 8 +++++++- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Compose-Ur-Pres/cup-source-code/src/commonMain/kotlin/net/kodein/cup/sa/SourceCode.kt b/Compose-Ur-Pres/cup-source-code/src/commonMain/kotlin/net/kodein/cup/sa/SourceCode.kt index 2b67d04..a212cfc 100644 --- a/Compose-Ur-Pres/cup-source-code/src/commonMain/kotlin/net/kodein/cup/sa/SourceCode.kt +++ b/Compose-Ur-Pres/cup-source-code/src/commonMain/kotlin/net/kodein/cup/sa/SourceCode.kt @@ -131,11 +131,11 @@ private fun SourceCodePart( } } - val partOverStyles = overSpanStyles.toPersistentMap().builder().apply { + val partOverStyles = overSpanStyles.toPersistentMap().mutate { forEachStyle { index, saStyle, fraction -> - put(index, saStyle.spanStyle() to fraction) + it[index] = saStyle.spanStyle() to fraction } - }.build() + } Box( Modifier diff --git a/Compose-Ur-Pres/plugin/cup-laser/build.gradle.kts b/Compose-Ur-Pres/plugin/cup-laser/build.gradle.kts index 65a0408..7ed93d4 100644 --- a/Compose-Ur-Pres/plugin/cup-laser/build.gradle.kts +++ b/Compose-Ur-Pres/plugin/cup-laser/build.gradle.kts @@ -27,6 +27,8 @@ kotlin { implementation(kotlin.compose.materialIconsExtended) implementation(projects.cup) + + implementation(libs.kotlinx.collectionsImmutable) } all { diff --git a/Compose-Ur-Pres/plugin/cup-laser/src/commonMain/kotlin/net/kodein/cup/laser/Laser.kt b/Compose-Ur-Pres/plugin/cup-laser/src/commonMain/kotlin/net/kodein/cup/laser/Laser.kt index d37a8e8..8302bf0 100644 --- a/Compose-Ur-Pres/plugin/cup-laser/src/commonMain/kotlin/net/kodein/cup/laser/Laser.kt +++ b/Compose-Ur-Pres/plugin/cup-laser/src/commonMain/kotlin/net/kodein/cup/laser/Laser.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.drawscope.clipPath import androidx.compose.ui.input.pointer.* import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.unit.toSize +import kotlinx.collections.immutable.* import net.kodein.cup.PluginCupAPI @@ -34,7 +35,7 @@ public sealed class Laser { @PluginCupAPI public data class Pointer( override val drawing: Boolean = false, - val points: List> = emptyList(), + val points: ImmutableList> = persistentListOf(), val pointer: Offset? = null ) : Laser() } @@ -117,9 +118,8 @@ public fun LaserDraw( is Laser.Pointer -> { setLaser( laser.copy( - points = buildList { - addAll(laser.points) - add(listOf(rp)) + points = laser.points.toPersistentList().mutate { + it.add(persistentListOf(rp)) }, drawing = true ) @@ -155,12 +155,12 @@ public fun LaserDraw( } } is Laser.Pointer -> { - val points = if (laser.drawing) buildList { - addAll(laser.points.subList(0, laser.points.size - 1)) - add(laser.points.last() + rp) - } else laser.points setLaser(laser.copy( - points = points, + points = if (laser.drawing) { + laser.points.subList(0, laser.points.size - 1).toPersistentList().mutate { + it.add(laser.points.last().toPersistentList().plus(rp)) + } + } else laser.points, pointer = rp )) } diff --git a/Compose-Ur-Pres/plugin/cup-speaker-window/build.gradle.kts b/Compose-Ur-Pres/plugin/cup-speaker-window/build.gradle.kts index 11b7ba9..e00b477 100644 --- a/Compose-Ur-Pres/plugin/cup-speaker-window/build.gradle.kts +++ b/Compose-Ur-Pres/plugin/cup-speaker-window/build.gradle.kts @@ -28,6 +28,8 @@ kotlin { implementation(projects.cup) implementation(projects.plugin.cupLaser) + + implementation(libs.kotlinx.collectionsImmutable) } jvmMain.dependencies { diff --git a/Compose-Ur-Pres/plugin/cup-speaker-window/src/commonMain/kotlin/net/kodein/cup/speaker/SpeakerWindow.kt b/Compose-Ur-Pres/plugin/cup-speaker-window/src/commonMain/kotlin/net/kodein/cup/speaker/SpeakerWindow.kt index 9883c4c..5b2191a 100644 --- a/Compose-Ur-Pres/plugin/cup-speaker-window/src/commonMain/kotlin/net/kodein/cup/speaker/SpeakerWindow.kt +++ b/Compose-Ur-Pres/plugin/cup-speaker-window/src/commonMain/kotlin/net/kodein/cup/speaker/SpeakerWindow.kt @@ -2,6 +2,9 @@ package net.kodein.cup.speaker import androidx.compose.foundation.layout.ColumnScope import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList import net.kodein.cup.config.CupConfigurationBuilder import net.kodein.cup.config.CupConfigurationDsl import net.kodein.cup.utils.DataMap @@ -14,13 +17,16 @@ public sealed class ASpeakerNotes : DataMapElement(Key) { internal companion object Key : DataMap.Key } +@Stable public class SpeakerNotes( - public val notes: List> + notes: List> ) : DataMapElement(Key) { internal companion object Key : DataMap.Key { private val allSteps = 0..Int.MAX_VALUE } + public val notes: ImmutableList> = notes.toImmutableList() + public constructor(md: String): this(listOf(allSteps to md)) @Deprecated("Speaker notes are now forcibly in Markdown, please use SpeakerNotes(markdownText)")