mirror of
https://github.com/h7x4/Jisho-Study-Tool.git
synced 2024-12-22 05:57:28 +01:00
add romaji under sentences
This commit is contained in:
parent
04793b58ca
commit
935d2a17df
@ -7,6 +7,7 @@ import '../../../../settings.dart';
|
|||||||
|
|
||||||
class KanjiKanaBox extends StatelessWidget {
|
class KanjiKanaBox extends StatelessWidget {
|
||||||
final JishoJapaneseWord word;
|
final JishoJapaneseWord word;
|
||||||
|
final bool showRomajiBelow;
|
||||||
final ColorSet colors;
|
final ColorSet colors;
|
||||||
final bool autoTransliterateRomaji;
|
final bool autoTransliterateRomaji;
|
||||||
final bool centerFurigana;
|
final bool centerFurigana;
|
||||||
@ -18,6 +19,7 @@ class KanjiKanaBox extends StatelessWidget {
|
|||||||
const KanjiKanaBox({
|
const KanjiKanaBox({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.word,
|
required this.word,
|
||||||
|
this.showRomajiBelow = false,
|
||||||
this.colors = LightTheme.defaultMenuGreyNormal,
|
this.colors = LightTheme.defaultMenuGreyNormal,
|
||||||
this.autoTransliterateRomaji = true,
|
this.autoTransliterateRomaji = true,
|
||||||
this.centerFurigana = true,
|
this.centerFurigana = true,
|
||||||
@ -30,7 +32,10 @@ class KanjiKanaBox extends StatelessWidget {
|
|||||||
this.padding = const EdgeInsets.all(5.0),
|
this.padding = const EdgeInsets.all(5.0),
|
||||||
}) : super(key: key);
|
}) : 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -40,43 +45,46 @@ class KanjiKanaBox extends StatelessWidget {
|
|||||||
? transliterateKanaToLatin(word.reading!)
|
? transliterateKanaToLatin(word.reading!)
|
||||||
: word.reading!);
|
: word.reading!);
|
||||||
|
|
||||||
|
final fFontsize = furiganaFontsize ??
|
||||||
|
((kanjiFontsize != null) ? 0.8 * kanjiFontsize! : null);
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: margin,
|
margin: margin,
|
||||||
padding: padding,
|
padding: padding,
|
||||||
decoration: BoxDecoration(
|
color: colors.background,
|
||||||
color: colors.background,
|
|
||||||
// boxShadow: [
|
|
||||||
// BoxShadow(
|
|
||||||
// color: Colors.black.withOpacity(0.5),
|
|
||||||
// spreadRadius: 1,
|
|
||||||
// blurRadius: 0.5,
|
|
||||||
// offset: const Offset(1, 1),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
),
|
|
||||||
child: DefaultTextStyle.merge(
|
child: DefaultTextStyle.merge(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: centerFurigana ? CrossAxisAlignment.center : CrossAxisAlignment.start,
|
crossAxisAlignment: centerFurigana
|
||||||
|
? CrossAxisAlignment.center
|
||||||
|
: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// See header.dart for more details about this logic
|
// See header.dart for more details about this logic
|
||||||
hasFurigana
|
hasFurigana
|
||||||
? Text(
|
? Text(
|
||||||
wordReading ?? 'あ',
|
wordReading!,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: furiganaFontsize ??
|
fontSize: fFontsize,
|
||||||
((kanjiFontsize != null)
|
color: colors.foreground,
|
||||||
? 0.8 * kanjiFontsize!
|
|
||||||
: null),
|
|
||||||
color: wordReading != null ? colors.foreground : Colors.transparent,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: const Text(''),
|
: Text(
|
||||||
|
'あ',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.transparent,
|
||||||
|
fontSize: fFontsize,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
DefaultTextStyle.merge(
|
DefaultTextStyle.merge(
|
||||||
child: hasFurigana
|
child: hasFurigana
|
||||||
? Text(word.word!)
|
? Text(word.word!)
|
||||||
: Text(wordReading ?? word.word!),
|
: Text(wordReading ?? word.word!),
|
||||||
style: TextStyle(fontSize: kanjiFontsize),
|
style: TextStyle(fontSize: kanjiFontsize),
|
||||||
)
|
),
|
||||||
|
if (romajiEnabled && showRomajiBelow)
|
||||||
|
Text(
|
||||||
|
transliterateKanaToLatin(kana),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
style: TextStyle(color: colors.foreground),
|
style: TextStyle(color: colors.foreground),
|
||||||
|
@ -36,6 +36,7 @@ class Sentences extends StatelessWidget {
|
|||||||
.map(
|
.map(
|
||||||
(word) => KanjiKanaBox(
|
(word) => KanjiKanaBox(
|
||||||
word: word,
|
word: word,
|
||||||
|
showRomajiBelow: true,
|
||||||
margin: EdgeInsets.zero,
|
margin: EdgeInsets.zero,
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
centerFurigana: false,
|
centerFurigana: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user