From 2989407d313396bfacf6e24eff665a4194999a7e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Fri, 28 May 2021 23:48:10 +0800 Subject: [PATCH] flutter: config: Support setting piece width --- src/ui/flutter_app/lib/common/config.dart | 3 ++ src/ui/flutter_app/lib/l10n/intl_de.arb | 4 ++ src/ui/flutter_app/lib/l10n/intl_en.arb | 4 ++ src/ui/flutter_app/lib/l10n/intl_zh.arb | 1 + .../lib/painting/pieces_painter.dart | 3 +- .../personalization_settings_page.dart | 37 +++++++++++++++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/ui/flutter_app/lib/common/config.dart b/src/ui/flutter_app/lib/common/config.dart index aab357cb..be7c97bd 100644 --- a/src/ui/flutter_app/lib/common/config.dart +++ b/src/ui/flutter_app/lib/common/config.dart @@ -48,6 +48,7 @@ class Config { static bool isNotationsShown = false; static double boardBorderLineWidth = 2.0; static double boardInnerLineWidth = 2.0; + static double pieceWidth = 0.9; static double boardTop = 36.0; // Color @@ -102,6 +103,7 @@ class Config { Config.isNotationsShown = settings['IsNotationsShown'] ?? false; Config.boardBorderLineWidth = settings['BoardBorderLineWidth'] ?? 2; Config.boardInnerLineWidth = settings['BoardInnerLineWidth'] ?? 2; + Config.pieceWidth = settings['PieceWidth'] ?? 0.9; Config.boardTop = settings['BoardTop'] ?? 36; // Color @@ -171,6 +173,7 @@ class Config { settings['IsNotationsShown'] = Config.isNotationsShown; settings['BoardBorderLineWidth'] = Config.boardBorderLineWidth; settings['BoardInnerLineWidth'] = Config.boardInnerLineWidth; + settings['PieceWidth'] = Config.pieceWidth; settings['BoardTop'] = Config.boardTop; // Color diff --git a/src/ui/flutter_app/lib/l10n/intl_de.arb b/src/ui/flutter_app/lib/l10n/intl_de.arb index 24ad01dc..fd8209d7 100644 --- a/src/ui/flutter_app/lib/l10n/intl_de.arb +++ b/src/ui/flutter_app/lib/l10n/intl_de.arb @@ -600,6 +600,10 @@ "@boardInnerLineWidth": { "description": "Board inner line width" }, + "pieceWidth": "Steingröße", + "@pieceWidth": { + "description": "Board inner line width" + }, "standardNotation": "Standardnotation", "@standardNotation": { "description": "Standard notation" diff --git a/src/ui/flutter_app/lib/l10n/intl_en.arb b/src/ui/flutter_app/lib/l10n/intl_en.arb index b3f647b9..ebce8ace 100644 --- a/src/ui/flutter_app/lib/l10n/intl_en.arb +++ b/src/ui/flutter_app/lib/l10n/intl_en.arb @@ -600,6 +600,10 @@ "@boardInnerLineWidth": { "description": "Board inner line width" }, + "pieceWidth": "Piece width", + "@pieceWidth": { + "description": "Piece width" + }, "standardNotation": "Standard notation", "@standardNotation": { "description": "Standard notation" diff --git a/src/ui/flutter_app/lib/l10n/intl_zh.arb b/src/ui/flutter_app/lib/l10n/intl_zh.arb index a11ae0cd..28cc45fa 100644 --- a/src/ui/flutter_app/lib/l10n/intl_zh.arb +++ b/src/ui/flutter_app/lib/l10n/intl_zh.arb @@ -150,6 +150,7 @@ "display": "显示", "boardBorderLineWidth": "棋盘外框线宽", "boardInnerLineWidth": "棋盘内部线宽", + "pieceWidth": "棋子大小", "standardNotation": "标准棋谱格式", "restore": "重置", "restoreDefaultSettings": "恢复默认设置", diff --git a/src/ui/flutter_app/lib/painting/pieces_painter.dart b/src/ui/flutter_app/lib/painting/pieces_painter.dart index 54f5fef7..4213edda 100644 --- a/src/ui/flutter_app/lib/painting/pieces_painter.dart +++ b/src/ui/flutter_app/lib/painting/pieces_painter.dart @@ -44,8 +44,7 @@ class PiecesPainter extends PiecesBasePainter { this.focusIndex = invalidIndex, this.blurIndex = invalidIndex, }) : super(width: width) { - // - pieceWidth = squareWidth * 0.9; // size of square + pieceWidth = squareWidth * Config.pieceWidth; } @override diff --git a/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart b/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart index d983ad3e..faa33528 100644 --- a/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart +++ b/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart @@ -171,6 +171,37 @@ class _PersonalizationSettingsPageState ); } + SliderTheme _pieceWidthSliderTheme(context, setState) { + return SliderTheme( + data: AppTheme.sliderThemeData, + child: Slider( + value: Config.pieceWidth.toDouble(), + min: 0.5, + max: 1.0, + divisions: 50, + label: Config.pieceWidth.toStringAsFixed(1), + onChanged: (value) { + setState(() { + print("[config] pieceWidth value: $value"); + Config.pieceWidth = value; + Config.save(); + }); + }, + ), + ); + } + + setPieceWidth() async { + showModalBottomSheet( + context: context, + builder: (BuildContext context) => StatefulBuilder( + builder: (context, setState) { + return _pieceWidthSliderTheme(context, setState); + }, + ), + ); + } + SliderTheme _boardTopSliderTheme(context, setState) { return SliderTheme( data: AppTheme.sliderThemeData, @@ -251,6 +282,12 @@ class _PersonalizationSettingsPageState onTap: setBoardInnerLineWidth, ), ListItemDivider(), + SettingsListTile( + context: context, + titleString: S.of(context).pieceWidth, + onTap: setPieceWidth, + ), + ListItemDivider(), SettingsListTile( context: context, titleString: S.of(context).boardTop,