I am displaying single-line text in a container th...
# compose
m
I am displaying single-line text in a container that's too small, resulting in the last visible letter of the text to be partially cut-off. I would like that partial letter to not be displayed – have the text only show as many letters as can fit. Is there a built-in way to achieve that?
Copy code
Text(
    text = text,
    maxLines = 1,
    overflow = TextOverflow.Clip,
    softWrap = false,
)
e
determine the in-bounds characters in onTextLayout, put the total bounding rect in mutable state, and use it to clip Modifier.drawWithContent?
m
(I know it’s not what you are asking but…) in this situation, I usually just do a horizontal scale with
TextGeometricTransform(scaleX)
to make it fit.
m
Thanks, I ended up adding a fade effect to illustrate there is more text.
nice spin 4
f
(It's not exactly what you were asking either, but I think it's interesting enough to point it out) Google recently released autosizing logic for textview It could also match your use case https://developer.android.com/develop/ui/views/text-and-emoji/autosizing-textview?hl=fr
m
I wish they had a way to only scale the X axis, because that looks way better when you have text composables laid out in a row.