Is there a way to draw based on the size of an ele...
# compose
f
Is there a way to draw based on the size of an element? Something like
Copy code
Layout(children = {Text("Hello")},  layoutBlock = { measurables, incomingConstraints ->
    val sizeOfTheHelloText = /*calculate size*/
    Draw {
    /* draw some special border around the text */
    }
}
Or
Copy code
OnChildPositioned(onPositioned = { coords->
    Draw {
    /* draw some special border around the text */
    }
}) {
    Text("Hello")
}
The problem lies in
Draw
, as 'there is no composition context' there. Getting the size of the text I managed to figure out how to do. For context, I'm trying to make a button that fills up like a progress bar.
a
yes, you can't put Draw inside layoutBlock or onPositioned callback as both of them are executed not during the composition, but after when the underlying android view starts to be measured
but actually Draw already has what you need. the full signature is Draw { canvas, parentSize -> your code }
where parentSize is a pixel size of the parent layout for this Draw
f
Yeah you're totally right. Don't know how I missed that
a
you can find a lot of examples where we use parentSize in our material components