-
-
Save NikolaDespotoski/327ec8e5c2076c196cf608a32804de62 to your computer and use it in GitHub Desktop.
Migrate composed 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun Modifier.curve( | |
fillColor: Color, | |
lineColor: Color, | |
backgroundColor: Color, | |
stroke: Stroke, | |
points: SnapshotStateList<Point>, | |
thumbSize: Dp | |
) = this then CurveModifier( | |
fillColor = fillColor, | |
lineColor = lineColor, | |
backgroundColor = backgroundColor, | |
stroke = stroke, | |
points = points | |
) | |
@Immutable | |
private data class CurveModifier( | |
private val fillColor: Color, | |
private val lineColor: Color, | |
private val backgroundColor: Color, | |
private val stroke: Stroke, | |
private val points: SnapshotStateList<Point> | |
) : ModifierNodeElement<CurveNode>() { | |
override fun InspectorInfo.inspectableProperties() { | |
debugInspectorInfo { | |
properties["fillColor"] = fillColor | |
properties["lineColor"] = lineColor | |
properties["points"] = points.joinToString() | |
properties["stroke"] = stroke | |
} | |
} | |
override fun create() = CurveNode( | |
fillColor = fillColor, | |
lineColor = lineColor, | |
backgroundColor = backgroundColor, | |
stroke = stroke, | |
points = points | |
) | |
override fun update(node: CurveNode) { | |
node.fillColor = fillColor | |
node.lineColor = lineColor | |
node.backgroundColor = backgroundColor | |
node.stroke = stroke | |
node.points = points | |
} | |
} | |
private class CurveNode( | |
var fillColor: Color, | |
var lineColor: Color, | |
var backgroundColor: Color, | |
var stroke: Stroke, | |
var points: SnapshotStateList<Point> | |
) : DrawModifierNode, Modifier.Node() { | |
private val path = Path() // <--- remembered | |
override fun ContentDrawScope.draw() { | |
if (!path.isEmpty) { | |
path.reset() | |
} | |
path.drawSomething( | |
stroke = stroke, size = size, points = points.toList() | |
) | |
drawPath(path = path, color = lineColor, style = stroke) | |
drawPath(path = path, color = fillColor, alpha = 0.4f) | |
drawContent() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment