martmists
11/25/2024, 3:40 PMBox(
modifier = Modifier
.size(64.dp) // limit size of aspectRatio. TODO: limit to size of Text (+ padding) somehow
.aspectRatio(1f)
.padding(10.dp)
) {
Row(
modifier = Modifier
.padding(2.dp)
.border(2.dp, color, RoundedCornerShape(6.dp)) // Border around text
.fillMaxSize(), // Make sure we're square like the parent
verticalAlignment = Alignment.CenterVertically, // place text centered in the square
horizontalArrangement = Arrangement.Center,
) {
Text(
metric.source.type.uppercase(),
style = LocalTextStyle.current.copy(color = color, fontSize = 12.sp, fontWeight = FontWeight.Bold),
)
}
}
But the text is aligned closer to the bottom rather than being centered.Stylianos Gakis
11/25/2024, 3:54 PMplatformStyle = PlatformTextStyle(includeFontPadding = false),
It should center align itself properly.
With this code:
Box(
modifier = Modifier
.size(64.dp) // limit size of aspectRatio. TODO: limit to size of Text (+ padding) somehow
.aspectRatio(1f)
.padding(10.dp),
) {
Row(
modifier = Modifier
.padding(2.dp)
.border(2.dp, color, RoundedCornerShape(6.dp)) // Border around text
.fillMaxSize(), // Make sure we're square like the parent
verticalAlignment = Alignment.CenterVertically, // place text centered in the square
horizontalArrangement = Arrangement.Center,
) {
BasicText(
"HTTP",
style = TextStyle(
color = color,
fontSize = 12.sp,
fontWeight = FontWeight.Bold,
platformStyle = PlatformTextStyle(includeFontPadding = false),
),
)
}
HorizontalDivider(Modifier.align(Alignment.Center), color = Color.Black)
}
I get the following screenshot:Stylianos Gakis
11/25/2024, 3:54 PMBasicText
too, to ensure that your custom style is not breaking anything there?Stylianos Gakis
11/25/2024, 3:58 PM