Skip to content

Instantly share code, notes, and snippets.

@reline
Last active November 11, 2020 22:52
Show Gist options
  • Save reline/39cc011a07445bd59163771cf8e50ce6 to your computer and use it in GitHub Desktop.
Save reline/39cc011a07445bd59163771cf8e50ce6 to your computer and use it in GitHub Desktop.
Sample for rendering a list of dictionary entries using Jetpack Compose
@Composable
fun DictionaryEntries(words: List<Word>) {
Column(modifier = Modifier.padding(all = 16.dp), verticalArrangement = Arrangement.spacedBy(32.dp)) {
for (word in words) {
Card(elevation = 2.dp, modifier = Modifier.fillMaxWidth(), shape = RoundedCornerShape(2.dp)) {
DictionaryEntry(word.rubies)
}
}
}
}
@Composable
fun DictionaryEntry(rubies: List<Ruby>) {
Row(verticalGravity = Alignment.Bottom, modifier = Modifier.padding(8.dp)) {
for (ruby in rubies) {
Reading(ruby.first, ruby.second)
}
}
}
@Composable
fun Reading(japanese: String, okurigana: String?) {
Column(verticalArrangement = Arrangement.Bottom, horizontalGravity = Alignment.CenterHorizontally) {
if (okurigana != null) {
Text(text = okurigana, modifier = Modifier.gravity(Alignment.CenterHorizontally))
}
Text(text = japanese, fontSize = 40.sp)
}
}
data class Ruby(val first: String, val second: String? = null)
data class Word(val rubies: List<Ruby>)
val words = listOf(
Word(listOf(
Ruby("今日", "こんにち"), Ruby("は")
)),
Word(listOf(
Ruby("話", "はなし")
)),
Word(listOf(
Ruby("落", "らく"), Ruby("葉", "よう")
)),
Word(listOf(
Ruby("美", "うつく"), Ruby("しい", null)
)),
)
@reline
Copy link
Author

reline commented Sep 23, 2020

Should realistically support centering 4 hiragana above a single kanji, then here is a list of exceptions over that ratio.
Keep in mind that some words are also very long, so just making the kanji larger may not be viable...

Okurigana(ruby=仝, rt=どうじょう), 5.0
Okurigana(ruby=瓩, rt=キログラム), 5.0
Okurigana(ruby=粁, rt=キロメートル), 6.0
Okurigana(ruby=姑, rt=しゅうとめ), 5.0
Okurigana(ruby=志, rt=こころざし), 5.0
Okurigana(ruby=承, rt=うけたまわ), 5.0
Okurigana(ruby=政, rt=まつりごと), 5.0
Okurigana(ruby=謀, rt=はかりごと), 5.0
Okurigana(ruby=慮, rt=おもんぱか), 5.0
Okurigana(ruby=几, rt=おしまずき), 5.0
Okurigana(ruby=忝, rt=かたじけな), 5.0
Okurigana(ruby=忝, rt=かたじけな), 5.0
Okurigana(ruby=鯱, rt=しゃちほこ), 5.0
Okurigana(ruby=慮, rt=おもんぱか), 5.0
Okurigana(ruby=掌, rt=たなごころ), 5.0
Okurigana(ruby=恣, rt=ほしいまま), 5.0
Okurigana(ruby=政, rt=まつりごと), 5.0
Okurigana(ruby=鸛, rt=こうのとり), 5.0
Okurigana(ruby=Ε, rt=イプシロン), 5.0
Okurigana(ruby=Ο, rt=オミクロン), 5.0
Okurigana(ruby=Υ, rt=ウプシロン), 5.0
Okurigana(ruby=尢, rt=だいのまげあし), 7.0
Okurigana(ruby=巛, rt=まがりかわ), 5.0
Okurigana(ruby=籵, rt=デカメートル), 6.0
Okurigana(ruby=竏, rt=キロリットル), 6.0
Okurigana(ruby=W, rt=ダブリュー), 5.0
Okurigana(ruby=承, rt=うけたまわ), 5.0
Okurigana(ruby=恣, rt=ほしいまま), 5.0
Okurigana(ruby=掌, rt=たなごころ), 5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment