kotlinforandroid
06/12/2022, 9:42 AMJoseph Hawkes-Cates
06/12/2022, 4:12 PM.wrapContentSize(unbounded = true)
modifier on the dotted line composable and it'll allow it to exceed the bounds of the column.kotlinforandroid
06/12/2022, 4:33 PMkotlinforandroid
06/14/2022, 4:06 PM@Composable
fun RubyText(
text: String,
ruby: String? = null,
rubyVisible: Boolean = true,
style: TextStyle = TextStyle.Default,
) {
val rubyFontSize = LocalTextStyle.current.fontSize / 2
val boxHeight = rubyFontSize.toDp()
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Box(modifier = Modifier.requiredHeight(boxHeight + 3.dp).wrapContentSize(unbounded=true)) {
ruby?.let {
if (rubyVisible) {
Text(modifier = Modifier.wrapContentSize(unbounded=true), text = it, style = TextStyle(fontSize = rubyFontSize))
}
}
}
Text(text = text, style = style)
}
}
// This renders the second image (nside of the thread).
fun example2() {
RubyText(text = "このルールを")
RubyText(text = "守", ruby = "まも")
RubyText(text = "るらない")
RubyText(text = "人", ruby = "ひと")
RubyText(text = "は")
RubyText(text = "旅行", ruby = "りょこう")
RubyText(text = "ができなくなることもあります。")
}