Setting Font Size: Improve the choosing dialog

Now show how big the font will be in a dialog. This way the user can
make a more informed decission, instead of just choosing "Small" vs
"Normal" and not knowing how big that actually would be.
This commit is contained in:
Vishesh Handa
2019-10-07 21:10:21 +02:00
parent 05fb3da7c2
commit 276a3bf976
2 changed files with 118 additions and 34 deletions

View File

@ -128,40 +128,20 @@ class SettingsListState extends State<SettingsList> {
}
},
),
DropdownPreference(
'Font Size',
'font_size',
defaultVal: "Normal",
values: [
"Extra Small",
"Small",
"Normal",
"Large",
"Extra Large",
],
onChange: (newVal) {
NoteViewerFontSize fontSize;
switch (newVal) {
case "Extra Small":
fontSize = NoteViewerFontSize.ExtraSmall;
break;
case "Small":
fontSize = NoteViewerFontSize.Small;
break;
case "Normal":
fontSize = NoteViewerFontSize.Normal;
break;
case "Large":
fontSize = NoteViewerFontSize.Large;
break;
case "Extra Large":
fontSize = NoteViewerFontSize.ExtraLarge;
break;
default:
fontSize = NoteViewerFontSize.Normal;
}
ListTile(
title: Text("Font Size"),
subtitle: Text(
Settings.noteViewerFontSizeToString(
Settings.instance.noteViewerFontSize),
),
onTap: () async {
String result = await showDialog<String>(
context: context, builder: (context) => FontSizeSettingsDialog());
var fontSize = Settings.noteViewerFontSizeFromString(result);
Settings.instance.noteViewerFontSize = fontSize;
Settings.instance.save();
setState(() {});
},
),
SettingsHeader("Git Author Settings"),
@ -283,3 +263,68 @@ class VersionNumberTileState extends State<VersionNumberTile> {
);
}
}
class FontSizeSettingsDialog extends StatelessWidget {
final String title = "Font Size";
@override
Widget build(BuildContext context) {
var style = Theme.of(context).textTheme.body1;
var sizes = <Widget>[
ListTile(
title: Text("Extra Small",
style: style.copyWith(
fontSize: Settings.noteViewerFontSizeToDouble(
NoteViewerFontSize.ExtraSmall))),
onTap: () {
Navigator.of(context).pop("Extra Small");
},
),
ListTile(
title: Text("Small",
style: style.copyWith(
fontSize: Settings.noteViewerFontSizeToDouble(
NoteViewerFontSize.Small))),
onTap: () {
Navigator.of(context).pop("Small");
},
),
ListTile(
title: Text("Normal",
style: style.copyWith(
fontSize: Settings.noteViewerFontSizeToDouble(
NoteViewerFontSize.Normal))),
onTap: () {
Navigator.of(context).pop("Normal");
},
),
ListTile(
title: Text("Large",
style: style.copyWith(
fontSize: Settings.noteViewerFontSizeToDouble(
NoteViewerFontSize.Large))),
onTap: () {
Navigator.of(context).pop("Large");
},
),
ListTile(
title: Text("Extra Large",
style: style.copyWith(
fontSize: Settings.noteViewerFontSizeToDouble(
NoteViewerFontSize.ExtraLarge))),
onTap: () {
Navigator.of(context).pop("Extra Large");
},
),
];
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
child: ListBody(
children: sizes,
),
),
);
}
}

View File

@ -62,7 +62,11 @@ class Settings {
}
double getNoteViewerFontSize() {
switch (noteViewerFontSize) {
return noteViewerFontSizeToDouble(noteViewerFontSize);
}
static double noteViewerFontSizeToDouble(NoteViewerFontSize size) {
switch (size) {
case NoteViewerFontSize.Normal:
return 18.0;
case NoteViewerFontSize.Small:
@ -75,7 +79,42 @@ class Settings {
return 26.0;
}
assert(false, "getNoteViewerFontSize: We should never be here");
assert(false, "noteViewerFontSizeToDouble: We should never be here");
return 50000.0;
}
static String noteViewerFontSizeToString(NoteViewerFontSize size) {
switch (size) {
case NoteViewerFontSize.Normal:
return "Normal";
case NoteViewerFontSize.Small:
return "Small";
case NoteViewerFontSize.ExtraSmall:
return "Extra Small";
case NoteViewerFontSize.Large:
return "Large";
case NoteViewerFontSize.ExtraLarge:
return "Extra Large";
}
assert(false, "noteViewerFontSizeToString: We should never be here");
return "";
}
static NoteViewerFontSize noteViewerFontSizeFromString(String val) {
switch (val) {
case "Extra Small":
return NoteViewerFontSize.ExtraSmall;
case "Small":
return NoteViewerFontSize.Small;
case "Normal":
return NoteViewerFontSize.Normal;
case "Large":
return NoteViewerFontSize.Large;
case "Extra Large":
return NoteViewerFontSize.ExtraLarge;
default:
return NoteViewerFontSize.Normal;
}
}
}