Kirill Grouchnikov
11/15/2020, 8:39 PMAppWindowAmbient.current.y
gives the top location of the current desktop window. Is there a way to get the vertical offset from the window top for Canvas
or DrawScope
? That would allow doing vertical gradients across multiple composables without trying to place them into a common container.Timo Drick
11/16/2020, 12:14 AMonGloballyPositioned
but i am not sure if it is a good idea to use the position during animation. But for static drawing it should be fine.Kirill Grouchnikov
11/16/2020, 1:24 AMTimo Drick
11/16/2020, 1:25 AMTimo Drick
11/16/2020, 1:26 AMKirill Grouchnikov
11/16/2020, 1:36 AMval offset = remember { mutableStateOf(Offset(0.0f, 0.0f)) }
Kirill Grouchnikov
11/16/2020, 1:36 AMBox
that has my `Canvas`:
.onGloballyPositioned {
offset.value = it.localToRoot(Offset(0.0f, 0.0f))
}
Kirill Grouchnikov
11/16/2020, 1:37 AMoffset.value.y
gives me the offset of "this" box relative to the window root. Thanks, Timo!Kirill Grouchnikov
11/16/2020, 1:51 AMprivate class MyBackground(private val color: Color) : OnGloballyPositionedModifier, DrawModifier {
var offset = Offset(0.0f, 0.0f)
override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
offset = coordinates.localToRoot(Offset(0.0f, 0.0f))
}
override fun ContentDrawScope.draw() {
println(offset.y)
drawRect(color = color)
drawContent()
}
}
Kirill Grouchnikov
11/16/2020, 1:52 AM.draw()
and it gets recomposed when I resize the window and the relevant containers that use such a composite modifier get resized.Timo Drick
11/16/2020, 4:53 PMTimo Drick
11/16/2020, 4:59 PMTimo Drick
11/16/2020, 5:00 PMKirill Grouchnikov
11/16/2020, 5:32 PM