using Compose (multiplatform for desktop and web) how do I create a composable component inside a canvas?
What I am trying to achieve is to draw a diagram, but for some of the texts (and other things), the user should be able to edit that text
So, my idea was to make the text actually a textfield (but with custom styling to remove pretty much everything about style) so that the user can just edit it like any other textfield
I tried to make a Canvas and inside its draw method, I want to render certain components like a text field:
@Preview
@Composable
fun MyComponent() {
var text by remember { mutableStateOf("Hello") }
Column {
TextField(
value = text,
onValueChange = { text = it },
label = { Text("Label") }
)
Canvas(modifier = Modifier.fillMaxSize()) {
val canvasQuadrantSize = size / 2F
drawRect(
color = Color.Magenta,
size = canvasQuadrantSize
)
// error @Composable invocations can only happen from the context of a @Composable function
// TextField(
// value = text,
// onValueChange = { text = it },
// label = { Text("Label") }
// )
}
}
}
I am not quite sure what approach I should take to make this possible
especially taking into account that the component should also be affected by all the transformations that take place inside the canvas render, such as scaling and translation