, is there a way to specify the minimum text width in terms of
em
?
I have a composable that displays a number and an icon. I want the icon to not move when the amount of digits in the number changes. The maximum amount of digits is 3, so I would like to somehow specify the width of
Text
to be
3 em
.
ā 1
t
Timo Drick
09/05/2020, 7:46 PM
Sorry i do not know if this is possible but you could use a Row and than add a Modifier.weight(1f) to the Text. The row should have a Modifier.preferredWidth(10.dp) or something like that (dependent on your font).
j
Julius Marozas
09/06/2020, 11:36 AM
Yeah, I got it working through trial-and-error. But it would be more convenient and font-agnostic if I could specify something like
Modifier.preferredWidth(3.em.toDp())
(similarly to
10.dp.toPx()
).
v
Vsevolod Ganin
10/31/2020, 4:05 PM
Turned out that is possible:
with(DensityAmbient.current) { 3.em.toDp() }
Vsevolod Ganin
10/31/2020, 4:15 PM
Iām sorry, I tried it out and it results in
java.lang.IllegalStateException: Only Sp can convert to Px