zt
07/20/2025, 6:59 PM.drawWithCache {
val path = shape.createOutline(size.toSize(), layoutDirection, this)
val graphicsLayer = obtainGraphicsLayer()
val saturationBrush = Brush.verticalGradient(listOf(Color.Transparent, Color.Black))
val hueBrush = Brush.horizontalGradient(
listOf(
Color.Transparent,
Color.hsv(color().hue, 1f, 1f)
)
)
graphicsLayer.apply {
setOutline(path)
compositingStrategy = CompositingStrategy.Offscreen // fixes weird transparent corners
clip = true
record {
drawRect(Color.White)
drawRect(hueBrush)
drawRect(saturationBrush)
}
}
onDrawBehind {
drawLayer(graphicsLayer)
}
}
romainguy
07/21/2025, 2:26 AMromainguy
07/21/2025, 2:27 AMzt
07/21/2025, 4:47 AMromainguy
07/21/2025, 4:50 AMzt
07/21/2025, 4:52 AMromainguy
07/21/2025, 4:55 AMLouis Pullen-Freilich [G]
07/21/2025, 10:15 AMOutline
you can use Path.addOutline()
and then clip thatzt
07/21/2025, 11:24 AM.drawWithCache {
val outline = shape.createOutline(size.toSize(), layoutDirection, this)
val path = Path().apply { addOutline(outline) }
val hueBrush = Brush.horizontalGradient(
listOf(
Color.Transparent,
Color.hsv(color().hue, 1f, 1f)
)
)
onDrawBehind {
clipPath(path) {
drawRect(Color.White)
drawRect(hueBrush)
drawRect(saturationBrush)
}
}
}
romainguy
07/21/2025, 2:48 PM