From f0f9d0e174ff3744490a22a678e60c38b32f30ee Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Jul 2024 20:32:01 +0300 Subject: [PATCH] Add direct canvas customization for DeviceDrawable2D --- .../kscience/controls/constructor/devices/LimitSwitch.kt | 2 +- .../src/commonMain/kotlin/DeviceDrawable2DStore.kt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/devices/LimitSwitch.kt b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/devices/LimitSwitch.kt index cba6b83..d06a385 100644 --- a/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/devices/LimitSwitch.kt +++ b/controls-constructor/src/commonMain/kotlin/space/kscience/controls/constructor/devices/LimitSwitch.kt @@ -14,7 +14,7 @@ import space.kscience.dataforge.context.Context /** - * Virtual [LimitSwitch] + * A device that detects if a motor hits the end of its range */ public class LimitSwitch( context: Context, diff --git a/controls-visualisation-compose/src/commonMain/kotlin/DeviceDrawable2DStore.kt b/controls-visualisation-compose/src/commonMain/kotlin/DeviceDrawable2DStore.kt index 1c17aad..94bf76c 100644 --- a/controls-visualisation-compose/src/commonMain/kotlin/DeviceDrawable2DStore.kt +++ b/controls-visualisation-compose/src/commonMain/kotlin/DeviceDrawable2DStore.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.Canvas import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.unit.toSize @@ -24,11 +25,11 @@ public class DeviceDrawable2DStore(public val scope: CoroutineScope, public val public val drawableFlow: MutableStateFlow> = MutableStateFlow(emptyMap()) } -public fun DeviceDrawable2DStore.emit(id: String, drawable2D: DeviceDrawable2D){ +public fun DeviceDrawable2DStore.emit(id: String, drawable2D: DeviceDrawable2D) { drawableFlow.value += (id to drawable2D) } -public fun DeviceDrawable2DStore.emitAll(drawables: Map){ +public fun DeviceDrawable2DStore.emitAll(drawables: Map) { drawableFlow.value += drawables } @@ -62,6 +63,7 @@ public fun > DeviceDrawable2DStore.o @Composable public fun Device2DCanvas( modifier: Modifier = Modifier, + onDraw: DrawScope.() -> Unit = {}, flowBuilder: suspend DeviceDrawable2DStore.() -> Unit, ) { val coroutineScope = rememberCoroutineScope() @@ -85,6 +87,7 @@ public fun Device2DCanvas( drawables.values.forEach { with(it) { draw() } } + onDraw() } } }