Kashismails
05/15/2025, 12:38 PMOleksandr Balan
05/15/2025, 2:15 PM@Preview
@Composable
private fun AnnotatedStringPreview() {
Text(
modifier = Modifier.padding(8.dp),
text = buildAnnotatedString {
appendInlineContent("<<sum>>")
append(" x")
append(" + ")
appendInlineContent("<<sum>>")
append(" y")
},
inlineContent = mapOf(
"<<sum>>" to InlineTextContent(
placeholder = Placeholder(
width = 0.8.em,
height = 0.8.em,
placeholderVerticalAlign = PlaceholderVerticalAlign.AboveBaseline,
),
children = { SumSymbol() },
),
),
fontSize = 40.sp,
)
}
@Composable
private fun SumSymbol(modifier: Modifier = Modifier) {
Canvas(modifier = modifier.fillMaxSize()) {
val w = size.width
val h = size.height
val points = listOf(
Offset(w * 0.9f, 0f),
Offset(0f, 0f),
Offset(w * 0.5f, h * 0.5f),
Offset(0f, h),
Offset(w * 0.9f, h),
)
drawPoints(
points = points,
pointMode = PointMode.Polygon,
cap = StrokeCap.Round,
color = Color.Black,
strokeWidth = 3.dp.toPx(),
)
}
}
Kashismails
05/15/2025, 5:04 PM