Hi i am experimenting with the WindowInsetsRulers....
# compose-android
t
Hi i am experimenting with the WindowInsetsRulers. I want to simulate them for the preview. So i can check in the preview if my composable components handle the Insets correctly. But there are some problems i am using the following code to simulate the rulers:
Copy code
fun Modifier.provideWindowInsetsRulers(
    rulers: RectRulers
): Modifier = layout { measurable, constraints ->
    val placeable = measurable.measure(constraints)
    layout(
        width = placeable.width,
        height = placeable.height,
        rulers = {
            val (w, h) = coordinates.size
            <http://rulers.top|rulers.top> provides 100f
            rulers.bottom provides h - 100f
            rulers.left provides 100f
            rulers.right provides w - 100f
        }
    ) {
        placeable.place(0, 0)
    }
}
More details in the thread
So when i use this in a preview:
Copy code
@Preview
@Composable
fun RulerTestPreview() {
    val rulers = WindowInsetsRulers.NavigationBars.current
    val fitRulers = WindowInsetsRulers.NavigationBars.current
    Box(
        Modifier.fillMaxSize()
            .provideWindowInsetsRulers(rulers)
            .background(Color.Green)
            .fitInside(fitRulers)
            .background(Color.LightGray)
    )
}
It works fine:
But when i set
val fitRulers = WindowInsetsRulers.SafeDrawing.current
then i get this:
And when i set:
val fitRulers = WindowInsetsRulers.StatusBars.current
then i get this:
Maybe @Alex Vanyo can you have a look or point someone to this thread who is familiar with this API.
Hmm i think i figured it out. It looks like the default Waterfall rulers mess the thing up. When i override also the Waterfall rulers than it works as expected.