Skip to content

Instantly share code, notes, and snippets.

@nikhil-mandlik-dev
Created June 25, 2023 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhil-mandlik-dev/2a451963407c89205b7418e27e349398 to your computer and use it in GitHub Desktop.
Save nikhil-mandlik-dev/2a451963407c89205b7418e27e349398 to your computer and use it in GitHub Desktop.
Drawing Minute Second Overlay
//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