Skip to content

Commit

Permalink
bruig: First pass to refine font size
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlyp committed Nov 1, 2023
1 parent 94d18ed commit 64d2ed9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 73 deletions.
4 changes: 2 additions & 2 deletions bruig/flutterui/bruig/lib/components/md_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class MarkdownArea extends StatelessWidget {
codeBlockMaxHeight: 200,
styleSheet: MarkdownStyleSheet(
p: TextStyle(
fontSize: 8 + theme.getFontSize() * 7,
fontSize: theme.getFontSize(),
color: textColor,
fontWeight: hasNick ? FontWeight.w700 : FontWeight.w300,
letterSpacing: 0.44),
Expand Down Expand Up @@ -439,7 +439,7 @@ class MarkdownArea extends StatelessWidget {
color: textColor,
backgroundColor: Colors.black87,
height: 1.2,
fontSize: 8 + theme.getFontSize() * 7,
fontSize: theme.getFontSize(),
fontFamily: 'Inter',
textBaseline: TextBaseline.alphabetic),
),
Expand Down
74 changes: 40 additions & 34 deletions bruig/flutterui/bruig/lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,50 +102,56 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
const SizedBox(height: 50),
Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Text('Font Size',
style: TextStyle(
fontSize: 8 + theme.getFontSize() * 7, color: textColor)),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
const SizedBox(width: 50),
Expanded(
child: Slider(
divisions: 3,
min: 1,
max: 4,
value: theme.getFontSize(),
onChanged: (double value) {
setState(() {
if (value < theme.defaultFontSize) {
theme.setSmallFontMode();
} else if (value >= theme.defaultFontSize &&
value < theme.largeFontSize) {
theme.setDefaultFontMode();
} else if (value >= theme.largeFontSize &&
value < theme.hugeFontSize) {
theme.setLargeFontMode();
} else if (value >= theme.largeFontSize) {
theme.setHugeFontMode();
}
});
},
child: Container(
margin: EdgeInsets.only(left: 10, right: 10),
decoration: new BoxDecoration(
borderRadius:
new BorderRadius.all(new Radius.circular(5.0)),
boxShadow: [
new BoxShadow(
color: Colors.black38,
offset: new Offset(0.0, 2.0),
blurRadius: 10)
]),
child: Slider(
value: theme.getFontCoef(),
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) => theme.setFontSize(s),
divisions: 3,
min: 1.0,
max: 4.0,
),
)),
const SizedBox(width: 50),
]),
const SizedBox(height: 20),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Text('Small',
style: TextStyle(
fontSize: 8 + theme.smallFontSize * 7, color: textColor)),
style: TextStyle(fontSize: 12 * 1, color: textColor)),
const SizedBox(width: 35),
Text('Normal',
style: TextStyle(
fontSize: 8 + theme.defaultFontSize * 7,
color: textColor)),
style: TextStyle(fontSize: 12 * 2, color: textColor)),
const SizedBox(width: 20),
Text('Large',
style: TextStyle(
fontSize: 8 + theme.largeFontSize * 7, color: textColor)),
style: TextStyle(fontSize: 12 * 3, color: textColor)),
const SizedBox(width: 10),
Text('Huge',
style: TextStyle(
fontSize: 8 + theme.hugeFontSize * 7, color: textColor)),
style: TextStyle(fontSize: 12 * 4, color: textColor)),
]),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(left: 20),
height: 50,
child: Row(children: [
Text('Current Font Size: ',
style: TextStyle(fontSize: 12, color: textColor)),
const SizedBox(width: 20),
Text('Bison Relay',
style: TextStyle(
fontSize: theme.getFontSize(), color: textColor)),
])),
]),
const SizedBox(height: 20),
]),
Expand Down
47 changes: 10 additions & 37 deletions bruig/flutterui/bruig/lib/theme_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import './storage_manager.dart';
// colorScheme: ColorScheme.fromSeed(seedColor: Color(0xff2970ff))),

class ThemeNotifier with ChangeNotifier {
final double defaultFontSize = 2;
final double smallFontSize = 1;
final double largeFontSize = 3;
final double hugeFontSize = 4;
final double defaultFontSize = 1;
static String emojifont =
Platform.isWindows ? "notoemoji_win" : "notoemoji_unix";
final darkTheme = ThemeData(
Expand Down Expand Up @@ -84,7 +81,9 @@ class ThemeNotifier with ChangeNotifier {
ThemeData getTheme() => _themeData;

late double _fontSize = defaultFontSize;
double getFontSize() => _fontSize;
double getFontCoef() => _fontSize;

double getFontSize() => _fontSize * 10 + 2;

ThemeNotifier() {
StorageManager.readData('themeMode').then((value) {
Expand All @@ -98,18 +97,10 @@ class ThemeNotifier with ChangeNotifier {
}
notifyListeners();
});
StorageManager.readData('fontSize').then((value) {
StorageManager.readData('fontCoef').then((value) {
debugPrint('value read from storage: ${value.toString()}');
var fontMode = value ?? 'defaultFontSize';
if (fontMode == 'defaultFontSize') {
_fontSize = defaultFontSize;
} else if (fontMode == 'smallFontSize') {
_fontSize = smallFontSize;
} else if (fontMode == 'largeFontSize') {
_fontSize = largeFontSize;
} else if (fontMode == 'hugeFontSize') {
_fontSize = hugeFontSize;
}
_fontSize = double.parse(value);
print(_fontSize);
notifyListeners();
});
}
Expand All @@ -126,27 +117,9 @@ class ThemeNotifier with ChangeNotifier {
notifyListeners();
}

void setSmallFontMode() async {
_fontSize = smallFontSize;
StorageManager.saveData('fontSize', 'smallFontSize');
notifyListeners();
}

void setDefaultFontMode() async {
_fontSize = defaultFontSize;
StorageManager.saveData('fontSize', 'defaultFontSize');
notifyListeners();
}

void setLargeFontMode() async {
_fontSize = largeFontSize;
StorageManager.saveData('fontSize', 'largeFontSize');
notifyListeners();
}

void setHugeFontMode() async {
_fontSize = hugeFontSize;
StorageManager.saveData('fontSize', 'hugeFontSize');
void setFontSize(double fs) async {
_fontSize = fs;
StorageManager.saveData('fontCoef', fs.toString());
notifyListeners();
}
}

0 comments on commit 64d2ed9

Please sign in to comment.