Created
June 25, 2023 10:06
-
-
Save nikhil-mandlik-dev/2a451963407c89205b7418e27e349398 to your computer and use it in GitHub Desktop.
Drawing Minute Second Overlay
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
//drawing minute-second overlay | |
val minuteHandOverlayPath = Path().apply { | |
val startOffset = Offset( | |
x = center.x + (outerRadius * cos(8f * Math.PI / 180f)).toFloat(), | |
y = center.y - (outerRadius * sin(8f * Math.PI / 180f)).toFloat(), | |
) | |
val endOffset = Offset( | |
x = center.x + (outerRadius * cos(-8f * Math.PI / 180f)).toFloat(), | |
y = center.y - (outerRadius * sin(-8f * Math.PI / 180f)).toFloat(), | |
) | |
val overlayRadius = (endOffset.y - startOffset.y) / 2f | |
val secondsLabelMaxWidth = textMeasurer.measure( | |
text = buildAnnotatedString { append("60") }, | |
style = clockStyle.secondsDialStyle.stepsTextStyle | |
).size.width | |
val minutesLabelMaxWidth = textMeasurer.measure( | |
text = buildAnnotatedString { append("60") }, | |
style = clockStyle.minutesDialStyle.stepsTextStyle | |
).size.width | |
val overlayLineX = | |
size.width - clockStyle.secondsDialStyle.fiveStepsLineHeight.toPx() - clockStyle.secondsDialStyle.stepsLabelTopPadding.toPx() - secondsLabelMaxWidth - clockStyle.minutesDialStyle.fiveStepsLineHeight.toPx() - clockStyle.minutesDialStyle.stepsLabelTopPadding.toPx() - (minutesLabelMaxWidth /2f) | |
moveTo(x = startOffset.x, y = startOffset.y) | |
lineTo(x = overlayLineX, y = startOffset.y) | |
cubicTo( | |
x1 = overlayLineX - overlayRadius, | |
y1 = startOffset.y, | |
x2 = overlayLineX - overlayRadius, | |
y2 = endOffset.y, | |
x3 = overlayLineX, | |
y3 = endOffset.y | |
) | |
lineTo(endOffset.x, endOffset.y) | |
} | |
drawPath( | |
path = minuteHandOverlayPath, | |
color = clockStyle.overlayStrokeColor, | |
style = Stroke(width = clockStyle.overlayStrokeWidth.toPx(),) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment