Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -877,13 +877,22 @@ internal object TextLayoutManager {
)
}

val desiredWidth = ceil(Layout.getDesiredWidth(text, paint)).toInt()

// Layout.getDesiredWidth is a full measuring pass over the text, so only run it when its
// result can affect the layout width. It cannot when the width is EXACTLY, nor when the text
// was boring but did not fit: boring.width is the unwrapped width of the same text and we only
// get here if it exceeds floor(width), so min(desiredWidth, floor(width)) is floor(width).
val layoutWidth =
when (widthYogaMeasureMode) {
YogaMeasureMode.EXACTLY -> ceil(width).toInt()
YogaMeasureMode.AT_MOST -> min(desiredWidth, floor(width).toInt())
else -> desiredWidth
when {
widthYogaMeasureMode == YogaMeasureMode.EXACTLY -> ceil(width).toInt()
widthYogaMeasureMode == YogaMeasureMode.AT_MOST && boring != null -> floor(width).toInt()
else -> {
val desiredWidth = ceil(Layout.getDesiredWidth(text, paint)).toInt()
if (widthYogaMeasureMode == YogaMeasureMode.AT_MOST) {
min(desiredWidth, floor(width).toInt())
} else {
desiredWidth
}
}
}
val enableStartOverhang = widthYogaMeasureMode == YogaMeasureMode.EXACTLY
val layout =
Expand Down
Loading