#doodle
Title
# doodle
c

Cherrio LLC

03/19/2023, 12:26 PM
Hello @Nick, We seem unable to apply radius to some certain edges like topLeft, topRight We tried to see if the
``canvas.rect``
has an overloaded function for that, none. What we tried
Copy code
``````canvas.rect(
view.bounds.atOrigin,
fill = backgroundColor.paint,
stroke = Stroke.invoke(border.color, border.width.toDouble())
)``````
n

Nick

03/19/2023, 1:52 PM
There’s no overload (but sounds like it could help) because you can create a
``Path``
with this effect using Polygon.rounded, or it’s more flexible variant that lets you set different radii for any subset of vertices.
Copy code
``````canvas.path(
view.bounds.atOrigin.rounded(…),
…
)``````
c

Cherrio LLC

03/21/2023, 1:11 PM
Hey @Nick, Is this the best and optimal way to have a
``CutCornerShape``
?
Copy code
``````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)``````
n

Nick

03/21/2023, 3:55 PM
reading this on mobile, so apologies if i misunderstand the code. it looks like you’re creating a rectangle with corner sliced off. this approach is fine, but you might want to avoid doing it in
``render``
, 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``
.
6 Views