Hey. I'm writing a custom layout and measuring som...
# compose
g
Hey. I'm writing a custom layout and measuring some Text composables, with a maxWidth constrain. When the text wraps into multiple lines, the measure result seems to match the maxWidth constrain, instead of measuring the actual space used by the text (In the example image, I would expect the right bound of the text to match the red line). Is there a way to achieve this? I'm measuring with:
Copy code
mesurable.measure(Constraints(0, maxColumnWidth, 0, Constraints.Infinity))
🇩🇰 4
z
The values reported from the TextLayoutResult are incorrect?
g
Not sure what you mean. I don't really have access to any
TextLayoutResult
. I measure the measurables and get some placeables back. And I don't know how to access the
TextLayoutResult
from the
Text
composables to check if they are correct or not
z
There's no way to do that just from the layout, you'd need to get it from the text composable explicitly. @Siyamed might know if there's a reason
Text
doesn't measure itself to the actual width - that seems like something it should be able to do.
👍 1
s
This is a very very old thread but still worth mentioning. StaticLayout accepts a width and fits everythong into that width. With the constaints we measure how mich space is given and create the staticlayout with the final width. I believe it is possible to go over the lines and report the real final width based on line ends but we kept the system behavior for a reason (moght be we just kept it the same or there was a reason)