mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-02 04:47:01 +08:00
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:
@ -128,40 +128,20 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
DropdownPreference(
|
ListTile(
|
||||||
'Font Size',
|
title: Text("Font Size"),
|
||||||
'font_size',
|
subtitle: Text(
|
||||||
defaultVal: "Normal",
|
Settings.noteViewerFontSizeToString(
|
||||||
values: [
|
Settings.instance.noteViewerFontSize),
|
||||||
"Extra Small",
|
),
|
||||||
"Small",
|
onTap: () async {
|
||||||
"Normal",
|
String result = await showDialog<String>(
|
||||||
"Large",
|
context: context, builder: (context) => FontSizeSettingsDialog());
|
||||||
"Extra Large",
|
|
||||||
],
|
var fontSize = Settings.noteViewerFontSizeFromString(result);
|
||||||
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;
|
|
||||||
}
|
|
||||||
Settings.instance.noteViewerFontSize = fontSize;
|
Settings.instance.noteViewerFontSize = fontSize;
|
||||||
Settings.instance.save();
|
Settings.instance.save();
|
||||||
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SettingsHeader("Git Author Settings"),
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -62,7 +62,11 @@ class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double getNoteViewerFontSize() {
|
double getNoteViewerFontSize() {
|
||||||
switch (noteViewerFontSize) {
|
return noteViewerFontSizeToDouble(noteViewerFontSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double noteViewerFontSizeToDouble(NoteViewerFontSize size) {
|
||||||
|
switch (size) {
|
||||||
case NoteViewerFontSize.Normal:
|
case NoteViewerFontSize.Normal:
|
||||||
return 18.0;
|
return 18.0;
|
||||||
case NoteViewerFontSize.Small:
|
case NoteViewerFontSize.Small:
|
||||||
@ -75,7 +79,42 @@ class Settings {
|
|||||||
return 26.0;
|
return 26.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false, "getNoteViewerFontSize: We should never be here");
|
assert(false, "noteViewerFontSizeToDouble: We should never be here");
|
||||||
return 50000.0;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user