Colton Idle
05/21/2021, 7:35 PMZach Klippenstein (he/him) [MOD]
05/21/2021, 7:43 PMste
05/21/2021, 7:50 PMNativePaint.breakText
?Zach Klippenstein (he/him) [MOD]
05/21/2021, 7:54 PMShakil Karim
05/21/2021, 8:56 PM@Composable
@InternalTextApi
fun calculateTextSize(constraints: Constraints, text: AnnotatedString, textSize: TextUnit): TextUnit {
val textDelegate = TextDelegate(
text = text,
style = MaterialTheme.typography.h6.copy(fontSize = textSize),
maxLines = 1,
density = LocalDensity.current,
resourceLoader = object : Font.ResourceLoader {
override fun load(font: Font): Any {
return false
}
}
)
val layoutResult = textDelegate.layout(constraints, LayoutDirection.Ltr)
return if (layoutResult.didOverflowHeight) {
Log.d("TAG", "Delegate text size again $textSize")
calculateTextSize(constraints, text, textSize - 2.sp)
} else {
Log.d("TAG", "Delegate text size done $textSize")
//debug { "Delegate text size done $textSize" }
textSize
}
}Chris Sinco [G]
05/21/2021, 9:45 PMZach Klippenstein (he/him) [MOD]
05/21/2021, 10:07 PMShakil Karim
05/25/2021, 9:51 AMZach Klippenstein (he/him) [MOD]
06/01/2021, 3:07 PM