Cherrio LLC
03/19/2023, 12:26 PMcanvas.rect
has an overloaded function for that, none.
What we tried
canvas.rect(
view.bounds.atOrigin,
radius = radius,
fill = backgroundColor.paint,
stroke = Stroke.invoke(border.color, border.width.toDouble())
)
Nick
03/19/2023, 1:52 PMPath
with this effect using Polygon.rounded, or it’s more flexible variant that lets you set different radii for any subset of vertices.
canvas.path(
view.bounds.atOrigin.rounded(…),
…
)
Cherrio LLC
03/21/2023, 1:11 PMCutCornerShape
?
val corners = shapeType as CutCornerShape
val startPosition = view.bounds.atOrigin.position
val startEdge = Point(x = startPosition.x + corners.topLeft, startPosition.y )
val path = path(startEdge)
val rect = view.bounds.atOrigin
path.lineTo(Point(x = rect.width - corners.topRight, startPosition.y))
path.lineTo(Point(x = rect.width, startPosition.y + corners.topRight))
path.lineTo(Point(x = rect.width, rect.height - corners.bottomRight))
path.lineTo(Point(x = rect.width - corners.bottomRight, rect.height))
path.lineTo(Point(x = startPosition.x + corners.bottomLeft, rect.height))
path.lineTo(Point(x = startPosition.x, rect.height - corners.bottomLeft))
path.lineTo(Point(x = startPosition.x, startPosition.y + corners.topLeft))
path.lineTo(startEdge)
path(path.close(), fill = paint, stroke = stroke)
Nick
03/21/2023, 3:55 PMrender
, since render
can be called even if there are no changes to the bounds
. i’d suggest caching the path and computing it only when `width`/`height` changes. you would do this by observing boundsChanged
and checking that the new and old values have different sizes. that’s because you will get notified when the view’s `x`/`y` change as well. but those won’t change your path.
another minor thing. Rectangle.atOrigin
returns a Rectangle
with the same `width`/`height`, but `x`/`y` equal to 0
. so the position of that rect will always be 0,0
. so your startPosition
, as calculated above, will always be 0,0
.