Wietlol
08/07/2024, 7:04 PM@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 translationZach Klippenstein (he/him) [MOD]
08/07/2024, 11:06 PMCanvas
block on the other hand is a subset of that and can only draw pixels. It can't even have its own state (although drawWithCache
can, kind of).Zach Klippenstein (he/him) [MOD]
08/07/2024, 11:08 PMBox
or a custom layout to place your other composables, then use a Canvas
or one of the draw modifiers to draw below them.Zach Klippenstein (he/him) [MOD]
08/07/2024, 11:10 PMWietlol
08/08/2024, 6:30 PMZach Klippenstein (he/him) [MOD]
08/08/2024, 6:31 PMZach Klippenstein (he/him) [MOD]
08/08/2024, 6:31 PMWietlol
08/08/2024, 6:34 PMWietlol
08/08/2024, 6:34 PMWietlol
08/08/2024, 6:35 PMZach Klippenstein (he/him) [MOD]
08/08/2024, 6:40 PMit might prove a bit too difficult for the compose engine to apply the re-rendering of the entire diagram on every mouse drag eventit shouldn't, that's a large part of its job
Zach Klippenstein (he/him) [MOD]
08/08/2024, 6:41 PMZach Klippenstein (he/him) [MOD]
08/08/2024, 6:41 PMoffset { }
not offset()
to avoid recomposingWietlol
08/08/2024, 6:41 PMWietlol
08/08/2024, 6:42 PM