In `Text`, is there a way to specify the minimum t...
# compose
j
In
Text
, 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
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
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
Turned out that is possible:
with(DensityAmbient.current) { 3.em.toDp() }
I’m sorry, I tried it out and it results in
java.lang.IllegalStateException: Only Sp can convert to Px
😕
👆 1
d
@Denis Ismailaj, check this message https://kotlinlang.slack.com/archives/CJLTWPH7S/p1612638156434300?thread_ts=1612009094.039300&cid=CJLTWPH7S. It uses TextDelegate (that's an internal API, afaik). You need to set
Constraints
you need. It's another question how to convert ems to px