Add direct canvas customization for DeviceDrawable2D
This commit is contained in:
parent
fbf79f0a37
commit
f0f9d0e174
@ -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(
|
public class LimitSwitch(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.Canvas
|
|||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.geometry.Size
|
import androidx.compose.ui.geometry.Size
|
||||||
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
import androidx.compose.ui.graphics.drawscope.clipRect
|
import androidx.compose.ui.graphics.drawscope.clipRect
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.unit.toSize
|
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 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)
|
drawableFlow.value += (id to drawable2D)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun DeviceDrawable2DStore.emitAll(drawables: Map<String, DeviceDrawable2D>){
|
public fun DeviceDrawable2DStore.emitAll(drawables: Map<String, DeviceDrawable2D>) {
|
||||||
drawableFlow.value += drawables
|
drawableFlow.value += drawables
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ public fun <T, D : Device, P : DevicePropertySpec<D, T>> DeviceDrawable2DStore.o
|
|||||||
@Composable
|
@Composable
|
||||||
public fun Device2DCanvas(
|
public fun Device2DCanvas(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
onDraw: DrawScope.() -> Unit = {},
|
||||||
flowBuilder: suspend DeviceDrawable2DStore.() -> Unit,
|
flowBuilder: suspend DeviceDrawable2DStore.() -> Unit,
|
||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
@ -85,6 +87,7 @@ public fun Device2DCanvas(
|
|||||||
drawables.values.forEach {
|
drawables.values.forEach {
|
||||||
with(it) { draw() }
|
with(it) { draw() }
|
||||||
}
|
}
|
||||||
|
onDraw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user