diff --git a/lib/components/search/search_results_body/parts/kanji_kana_box.dart b/lib/components/search/search_results_body/parts/kanji_kana_box.dart index bb90e83..2aa0b43 100644 --- a/lib/components/search/search_results_body/parts/kanji_kana_box.dart +++ b/lib/components/search/search_results_body/parts/kanji_kana_box.dart @@ -7,6 +7,7 @@ import '../../../../settings.dart'; class KanjiKanaBox extends StatelessWidget { final JishoJapaneseWord word; + final bool showRomajiBelow; final ColorSet colors; final bool autoTransliterateRomaji; final bool centerFurigana; @@ -18,6 +19,7 @@ class KanjiKanaBox extends StatelessWidget { const KanjiKanaBox({ Key? key, required this.word, + this.showRomajiBelow = false, this.colors = LightTheme.defaultMenuGreyNormal, this.autoTransliterateRomaji = true, this.centerFurigana = true, @@ -30,7 +32,10 @@ class KanjiKanaBox extends StatelessWidget { this.padding = const EdgeInsets.all(5.0), }) : super(key: key); - bool get hasFurigana => word.word != null; + bool get hasFurigana => word.reading != null; + + String get kana => '${word.reading ?? ""}${word.word ?? ""}' + .replaceAll(RegExp(r'\p{Script=Hani}', unicode: true), ''); @override Widget build(BuildContext context) { @@ -40,43 +45,46 @@ class KanjiKanaBox extends StatelessWidget { ? transliterateKanaToLatin(word.reading!) : word.reading!); + final fFontsize = furiganaFontsize ?? + ((kanjiFontsize != null) ? 0.8 * kanjiFontsize! : null); + return Container( margin: margin, padding: padding, - decoration: BoxDecoration( - color: colors.background, - // boxShadow: [ - // BoxShadow( - // color: Colors.black.withOpacity(0.5), - // spreadRadius: 1, - // blurRadius: 0.5, - // offset: const Offset(1, 1), - // ), - // ], - ), + color: colors.background, child: DefaultTextStyle.merge( child: Column( - crossAxisAlignment: centerFurigana ? CrossAxisAlignment.center : CrossAxisAlignment.start, + crossAxisAlignment: centerFurigana + ? CrossAxisAlignment.center + : CrossAxisAlignment.start, children: [ // See header.dart for more details about this logic hasFurigana ? Text( - wordReading ?? 'あ', + wordReading!, style: TextStyle( - fontSize: furiganaFontsize ?? - ((kanjiFontsize != null) - ? 0.8 * kanjiFontsize! - : null), - color: wordReading != null ? colors.foreground : Colors.transparent, + fontSize: fFontsize, + color: colors.foreground, ), ) - : const Text(''), + : Text( + 'あ', + style: TextStyle( + color: Colors.transparent, + fontSize: fFontsize, + ), + ), + DefaultTextStyle.merge( child: hasFurigana ? Text(word.word!) : Text(wordReading ?? word.word!), style: TextStyle(fontSize: kanjiFontsize), - ) + ), + if (romajiEnabled && showRomajiBelow) + Text( + transliterateKanaToLatin(kana), + ) ], ), style: TextStyle(color: colors.foreground), diff --git a/lib/components/search/search_results_body/parts/sense/sentences.dart b/lib/components/search/search_results_body/parts/sense/sentences.dart index 6bc7566..8e4ce94 100644 --- a/lib/components/search/search_results_body/parts/sense/sentences.dart +++ b/lib/components/search/search_results_body/parts/sense/sentences.dart @@ -36,6 +36,7 @@ class Sentences extends StatelessWidget { .map( (word) => KanjiKanaBox( word: word, + showRomajiBelow: true, margin: EdgeInsets.zero, padding: EdgeInsets.zero, centerFurigana: false,