Skip to content

Commit 8b581d9

Browse files
committed
Update stopwatch subdial hands
1 parent e878a75 commit 8b581d9

1 file changed

Lines changed: 50 additions & 49 deletions

File tree

  • composeApp/src/commonMain/kotlin/com/danielebonaldo/dashboard/clockcompassdial

composeApp/src/commonMain/kotlin/com/danielebonaldo/dashboard/clockcompassdial/ClockCompassDial.kt

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.runtime.*
1111
import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.geometry.CornerRadius
1313
import androidx.compose.ui.geometry.Offset
14+
import androidx.compose.ui.geometry.Rect
1415
import androidx.compose.ui.geometry.Size
1516
import androidx.compose.ui.graphics.Color
1617
import androidx.compose.ui.graphics.Path
@@ -265,6 +266,37 @@ fun MorphingDialCanvas(
265266

266267
drawOuterTicks(compassDegrees, primaryTickLength * sizeRatio, center)
267268

269+
if (clockTextAlpha > 0f) {
270+
drawClockNumbers(
271+
textMeasurer = textMeasurer,
272+
center = center,
273+
radius = radius,
274+
sizeRatio = sizeRatio,
275+
alpha = clockTextAlpha
276+
)
277+
}
278+
279+
if (stopwatchTextAlpha > 0f) {
280+
drawStopwatchSecondsNumbers(
281+
textMeasurer = textMeasurer,
282+
center = center,
283+
radius = radius,
284+
sizeRatio = sizeRatio,
285+
alpha = stopwatchTextAlpha
286+
)
287+
}
288+
289+
if (compassTextAlpha > 0f) {
290+
drawCompassLabels(
291+
textMeasurer = textMeasurer,
292+
center = center,
293+
radius = radius,
294+
alpha = compassTextAlpha,
295+
sizeRatio = sizeRatio,
296+
compassDegrees = compassDegrees
297+
)
298+
}
299+
268300
if (stopwatchSubdialsVisibilityRatio > 0f) {
269301
val maxSubdialRadius = radius * StopwatchPillHeightRatio / 2
270302
val subdialPrimaryTickLength = primaryTickLength * 0.6f
@@ -317,37 +349,6 @@ fun MorphingDialCanvas(
317349
}
318350
}
319351

320-
if (clockTextAlpha > 0f) {
321-
drawClockNumbers(
322-
textMeasurer = textMeasurer,
323-
center = center,
324-
radius = radius,
325-
sizeRatio = sizeRatio,
326-
alpha = clockTextAlpha
327-
)
328-
}
329-
330-
if (stopwatchTextAlpha > 0f) {
331-
drawStopwatchSecondsNumbers(
332-
textMeasurer = textMeasurer,
333-
center = center,
334-
radius = radius,
335-
sizeRatio = sizeRatio,
336-
alpha = stopwatchTextAlpha
337-
)
338-
}
339-
340-
if (compassTextAlpha > 0f) {
341-
drawCompassLabels(
342-
textMeasurer = textMeasurer,
343-
center = center,
344-
radius = radius,
345-
alpha = compassTextAlpha,
346-
sizeRatio = sizeRatio,
347-
compassDegrees = compassDegrees
348-
)
349-
}
350-
351352
translate(left = center.x, top = center.y) {
352353
drawTaperedHand(
353354
angleDegrees = hoursHandAngle,
@@ -696,40 +697,40 @@ private fun DrawScope.drawStopwatchHand(
696697
baseWidth: Float,
697698
handColor: Color
698699
) {
699-
// 1. Create the Path
700700
val path = Path().apply {
701-
// Start at the very tip of the needle (pointing straight up)
702-
moveTo(0f, -handLength)
703-
704-
// Draw down to the right side of the base
701+
moveTo(-baseWidth / 2f, 0f)
702+
lineTo(-baseWidth / 2f, -handLength + baseWidth / 2f)
703+
arcTo(
704+
rect = Rect(
705+
left = -baseWidth / 2f,
706+
top = -handLength,
707+
right = baseWidth / 2f,
708+
bottom = -handLength + baseWidth
709+
),
710+
startAngleDegrees = 180f,
711+
sweepAngleDegrees = 180f,
712+
forceMoveTo = false
713+
)
705714
lineTo(baseWidth / 2f, 0f)
706-
//
707-
// // Draw down to the right side of the tail
708-
// lineTo(baseWidth / 4f, tailLength)
709-
//
710-
// // Draw across to the left side of the tail
711-
// lineTo(-baseWidth / 4f, tailLength)
712-
713-
// Draw up to the left side of the base
714-
lineTo(-baseWidth / 2f, 0f)
715-
716-
// Close the path back to the tip
717715
close()
718716
}
719717

720-
// 2. Rotate and Draw
721718
rotate(degrees = angleDegrees, pivot = Offset.Zero) {
722719
drawPath(
723720
path = path,
724721
color = handColor
725722
)
726723

727-
// Optional: Draw a tiny center pin on top of the needle
728724
drawCircle(
729725
color = handColor,
730726
radius = baseWidth * 1.5f,
731727
center = Offset.Zero
732728
)
729+
drawCircle(
730+
color = Color.Black.copy(alpha = 0.4f),
731+
radius = baseWidth * 0.8f,
732+
center = Offset.Zero
733+
)
733734
}
734735
}
735736

0 commit comments

Comments
 (0)