Cherrio LLC
02/27/2023, 1:02 AMview.bounds
but couldn't so farNick
02/27/2023, 1:14 AMLayout
. the layout in your view’s container (or the Display
if your view is top-level) can makes sure your views siblings are spaced away from it however you’d like. the layout does this by specifying the bounds
of all the views within a container.Nick
02/27/2023, 1:15 AMCherrio LLC
02/27/2023, 1:18 AMNick
02/27/2023, 1:22 AMCherrio LLC
03/03/2023, 8:39 AMview.displayRect.rounded { index: Int, point: Point ->
20.0
}
To change the rounded corners. It didnt work though
My questions:
1. What does that function do
2. How can i round the corners of a viewNick
03/03/2023, 3:27 PMoverride fun render(canvas: Canvas) {
canvas.rect(bounds.atOrigin, radius = 20.0, ...)
}
You could also render the rect as a Path if the corners need different radii. This is where you'd use the method you asked about:
override fun render(canvas: Canvas) {
// As usual, we use atOrigin b/c bounds is actually defined in the parent coordinate space, which means
// it has an x,y position. All we need is a rect the size of the view at 0,0
val path = bounds.atOrigin.rounded { index, _ ->
when (index) {
0, 2 -> 20.0 // round 1st and 3rd corners with larger radius
else -> 10.0
}
}
// the result is a path we can now render
canvas.path(path, fill = Red.paint)
}
Of course you might want to cache the path and only regenerate it on boundsChanged to make this a bit more performant.Cherrio LLC
03/03/2023, 4:22 PMNick
03/03/2023, 4:23 PMCherrio LLC
03/03/2023, 4:24 PMNick
03/03/2023, 4:39 PMrenderProperty
if you're changing a single value. Or you could use observable
for the changed value and recalculate your path (assuming you're doing what you asked about above). That path could be the renderProperty
so that setting it triggers a rerender:
// this will trigger repaint if the path updates
private var path by renderProperty(computePath())
// re-compute path on changes to your value
private var value by observable(...) { _, new ->
path = computePath()
}
private fun computePath(): Path {
...
}
Cherrio LLC
03/03/2023, 5:29 PMCherrio LLC
03/03/2023, 5:30 PMcanvas.circle()
?