Alejandro Rios
03/08/2024, 11:08 PMprogress border
for a pet project using CMP, I'm having an issue where the text is cut, more details in the 🧵Alejandro Rios
03/08/2024, 11:12 PMBox(
contentAlignment = Alignment.Center,
modifier = modifier
.rotate(boardRotationAngle)
.drawBehind {
scale(1f, -1f, Offset(size.width / 2, size.height / 2)) {
rotate(if (isAndroid) -90f else 0f) {
if (path.isEmpty) {
path.addRoundRect(
RoundRect(
Rect(offset = Offset.Zero, size),
cornerRadius = CornerRadius(16.dp.toPx(), 16.dp.toPx())
)
)
}
pathWithProgress.reset()
pathMeasure.setPath(path, forceClosed = false)
pathMeasure.getSegment(
startDistance = 0f,
stopDistance = pathMeasure.length * borderProgress,
pathWithProgress,
startWithMoveTo = true
)
clipPath(path) {
drawRect(color)
}
drawPath(
path = pathWithProgress,
style = Stroke(5.dp.toPx()),
color = Color(0xFFD28B2D)
)
val progressEndPos = if (pathMeasure.getPosition(pathMeasure.length * progress) != Offset.Unspecified) {
val (x, y) = pathMeasure.getPosition(pathMeasure.length * progress)
Offset(x, y)
} else {
Offset(0f, 0f)
}
drawCircle(
color = Color(0xFFD28B2D),
center = progressEndPos,
radius = 15.dp.toPx()
)
drawText(
textMeasurer = textMeasurer,
text = wordsGuessed,
style = style,
topLeft = Offset(
x = progressEndPos.x - textLayoutResult.size.width / 2,
y = progressEndPos.y - textLayoutResult.size.height / 2,
)
)
}
}
}
) { }
The box has a size of 350, I have to rotate the square so the orange line you see starts from topLeft position(might need more adjustments there but I'll work on that later), right now I have no idea why the letter is cut in half(this case a 3), that happens when the circle is on top or bottom, left or right appears to be ok.
I tried extracting the drawText
from the scale
part, but no luckromainguy
03/08/2024, 11:17 PMAlejandro Rios
03/08/2024, 11:20 PMclip
I'll lose the round bordersromainguy
03/08/2024, 11:26 PMdrawPath(path, color)
?romainguy
03/08/2024, 11:27 PMromainguy
03/08/2024, 11:27 PMromainguy
03/08/2024, 11:27 PMpathWithProgress.reset()
pathMeasure.setPath(path, forceClosed = false)
romainguy
03/08/2024, 11:27 PMromainguy
03/08/2024, 11:28 PMdrawWithCache{}
to perform these expensive operations only onceAlejandro Rios
03/08/2024, 11:30 PMromainguy
03/08/2024, 11:54 PMAlejandro Rios
03/08/2024, 11:57 PMromainguy
03/09/2024, 12:06 AMromainguy
03/09/2024, 12:06 AMAlejandro Rios
03/09/2024, 12:10 AM