drawOutline

Function

Common
fun DrawScope.drawOutline(
    outline: Outline,
    color: Color,
    @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DrawScope.DefaultBlendMode,
) =
    drawOutlineHelper(
        outline,
        { rect ->
            drawRect(color, rect.topLeft(), rect.size(), alpha, style, colorFilter, blendMode)
        },
        { rrect ->
            val radius = rrect.bottomLeftCornerRadius.x
            drawRoundRect(
                color = color,
                topLeft = rrect.topLeft(),
                size = rrect.size(),
                cornerRadius = CornerRadius(radius),
                alpha = alpha,
                style = style,
                colorFilter = colorFilter,
                blendMode = blendMode,
            )
        },
        { path -> drawPath(path, color, alpha, style, colorFilter, blendMode) },
    )

Draws the Outline on a DrawScope.

Parameters

outlinethe outline to draw.
colorColor applied to the outline when it is drawn
alphaOpacity to be applied to outline from 0.0f to 1.0f representing fully transparent to fully opaque respectively
styleSpecifies whether the outline is stroked or filled in
colorFilter:ColorFilter to apply to the color when drawn into the destination
blendMode:Blending algorithm to be applied to the outline
Common
fun DrawScope.drawOutline(
    outline: Outline,
    brush: Brush,
    @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DrawScope.DefaultBlendMode,
) =
    drawOutlineHelper(
        outline,
        { rect ->
            drawRect(brush, rect.topLeft(), rect.size(), alpha, style, colorFilter, blendMode)
        },
        { rrect ->
            val radius = rrect.bottomLeftCornerRadius.x
            drawRoundRect(
                brush = brush,
                topLeft = rrect.topLeft(),
                size = rrect.size(),
                cornerRadius = CornerRadius(radius),
                alpha = alpha,
                style = style,
                colorFilter = colorFilter,
                blendMode = blendMode,
            )
        },
        { path -> drawPath(path, brush, alpha, style, colorFilter, blendMode) },
    )

Draws the Outline on a DrawScope.

Parameters

outlinethe outline to draw.
brushBrush applied to the outline when it is drawn
alphaOpacity to be applied to outline from 0.0f to 1.0f representing fully transparent to fully opaque respectively
styleSpecifies whether the outline is stroked or filled in
colorFilter:ColorFilter to apply to the Brush when drawn into the destination
blendMode:Blending algorithm to be applied to the outline
Common
fun Canvas.drawOutline(outline: Outline, paint: Paint) =
    when (outline) {
        is Outline.Rectangle -> drawRect(outline.rect, paint)
        is Outline.Rounded -> {
            val path = outline.roundRectPath
            if (path != null) {
                drawPath(path, paint)
            } else {
                drawRoundRect(
                    left = outline.roundRect.left,
                    top = outline.roundRect.top,
                    right = outline.roundRect.right,
                    bottom = outline.roundRect.bottom,
                    radiusX = outline.roundRect.bottomLeftCornerRadius.x,
                    radiusY = outline.roundRect.bottomLeftCornerRadius.y,
                    paint = paint,
                )
            }
        }
        is Outline.Generic -> drawPath(outline.path, paint)
    }

Draws the Outline on a Canvas.

Parameters

outlinethe outline to draw.
paintthe paint used for the drawing.