LXJ
LXJ

Reputation: 1616

How to restrict drawables only shown inside canvas?

I have a canvas positioned on the right side of the screen. To the left are some buttons. If x values of some drawbles are negative, they are drawn on the left side, outside of the canvas. How can I avoid it?

Row {
    Button(onClick = {
    }) {
        Text("File")
    }
    Canvas(modifier = ...) {
        drawPoints(dataPts, PointMode.Points, Color.Blue, strokeWidth = 5f)
    }
}

Upvotes: 0

Views: 308

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 88112

By default, all Compose views do not clip their content outside the boundaries.

You can add Modifier.clipToBounds when you need to clip it:

Canvas(Modifier.clipToBounds())

Or you can use Modifier.clip to clip to a specific shape.

Upvotes: 1

Related Questions