Add direct canvas customization for DeviceDrawable2D

This commit is contained in:
Alexander Nozik 2024-07-23 20:32:01 +03:00
parent fbf79f0a37
commit f0f9d0e174
2 changed files with 6 additions and 3 deletions

View File

@ -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,

View File

@ -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<Map<String, DeviceDrawable2D>> = 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<String, DeviceDrawable2D>){
public fun DeviceDrawable2DStore.emitAll(drawables: Map<String, DeviceDrawable2D>) {
drawableFlow.value += drawables
}
@ -62,6 +63,7 @@ public fun <T, D : Device, P : DevicePropertySpec<D, T>> 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()
}
}
}