Skip to content

Commit

Permalink
Merge pull request #1134 from lichess-org/board_border
Browse files Browse the repository at this point in the history
Add a border setting to the board
  • Loading branch information
veloce authored Nov 9, 2024
2 parents abe5f78 + b6ed471 commit 106cd91
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 34 deletions.
13 changes: 13 additions & 0 deletions lib/src/model/settings/board_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:chessground/chessground.dart';
import 'package:flutter/widgets.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lichess_mobile/src/model/settings/preferences_storage.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/color_palette.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand Down Expand Up @@ -63,6 +64,10 @@ class BoardPreferences extends _$BoardPreferences
return save(state.copyWith(coordinates: !state.coordinates));
}

Future<void> toggleBorder() {
return save(state.copyWith(showBorder: !state.showBorder));
}

Future<void> togglePieceAnimation() {
return save(state.copyWith(pieceAnimation: !state.pieceAnimation));
}
Expand Down Expand Up @@ -120,6 +125,7 @@ class BoardPrefs with _$BoardPrefs implements Serializable {
unknownEnumValue: ShapeColor.green,
)
required ShapeColor shapeColor,
@JsonKey(defaultValue: false) required bool showBorder,
}) = _BoardPrefs;

static const defaults = BoardPrefs(
Expand All @@ -136,12 +142,19 @@ class BoardPrefs with _$BoardPrefs implements Serializable {
enableShapeDrawings: true,
magnifyDraggedPiece: true,
shapeColor: ShapeColor.green,
showBorder: false,
);

ChessboardSettings toBoardSettings() {
return ChessboardSettings(
pieceAssets: pieceSet.assets,
colorScheme: boardTheme.colors,
border: showBorder
? BoardBorder(
color: darken(boardTheme.colors.darkSquare, 0.2),
width: 16.0,
)
: null,
showValidMoves: showLegalMoves,
showLastMove: boardHighlights,
enableCoordinates: coordinates,
Expand Down
15 changes: 6 additions & 9 deletions lib/src/view/board_editor/board_editor_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,12 @@ class _BoardEditor extends ConsumerWidget {
size: boardSize,
pieces: pieces,
orientation: orientation,
settings: ChessboardEditorSettings(
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
enableCoordinates: boardPrefs.coordinates,
borderRadius: isTablet
? const BorderRadius.all(Radius.circular(4.0))
: BorderRadius.zero,
boxShadow: isTablet ? boardShadows : const <BoxShadow>[],
),
settings: boardPrefs.toBoardSettings().copyWith(
borderRadius: isTablet
? const BorderRadius.all(Radius.circular(4.0))
: BorderRadius.zero,
boxShadow: isTablet ? boardShadows : const <BoxShadow>[],
),
pointerMode: editorState.editorPointerMode,
onDiscardedPiece: (Square square) => ref
.read(boardEditorControllerProvider(initialFen).notifier)
Expand Down
17 changes: 8 additions & 9 deletions lib/src/view/coordinate_training/coordinate_training_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,14 @@ class _TrainingBoardState extends ConsumerState<_TrainingBoard> {
),
squareHighlights: widget.squareHighlights,
orientation: widget.orientation,
settings: ChessboardEditorSettings(
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
enableCoordinates: trainingPrefs.showCoordinates,
borderRadius: widget.isTablet
? const BorderRadius.all(Radius.circular(4.0))
: BorderRadius.zero,
boxShadow: widget.isTablet ? boardShadows : const <BoxShadow>[],
),
settings: boardPrefs.toBoardSettings().copyWith(
enableCoordinates: trainingPrefs.showCoordinates,
borderRadius: widget.isTablet
? const BorderRadius.all(Radius.circular(4.0))
: BorderRadius.zero,
boxShadow:
widget.isTablet ? boardShadows : const <BoxShadow>[],
),
pointerMode: EditorPointerMode.edit,
onEditedSquare: (square) {
if (trainingState.trainingActive &&
Expand Down
28 changes: 17 additions & 11 deletions lib/src/view/settings/theme_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:math' as math;
import 'package:chessground/chessground.dart';
import 'package:dartchess/dartchess.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/constants.dart';
Expand Down Expand Up @@ -46,15 +45,15 @@ class _Body extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final boardPrefs = ref.watch(boardPreferencesProvider);

const horizontalPadding = 52.0;
const horizontalPadding = 16.0;

return SafeArea(
child: ListView(
children: [
LayoutBuilder(
builder: (context, constraints) {
final double boardSize = math.min(
290,
400,
constraints.biggest.shortestSide - horizontalPadding * 2,
);
return Padding(
Expand All @@ -80,14 +79,12 @@ class _Body extends ConsumerWidget {
dest: Square.fromName('c6'),
),
}.lock,
settings: ChessboardSettings(
enableCoordinates: false,
borderRadius:
const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
),
settings: boardPrefs.toBoardSettings().copyWith(
enableCoordinates: true,
borderRadius:
const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
),
),
),
);
Expand Down Expand Up @@ -154,6 +151,15 @@ class _Body extends ConsumerWidget {
);
},
),
SwitchSettingTile(
// TODO translate
leading: const Icon(Icons.border_outer),
title: const Text('Show border'),
value: boardPrefs.showBorder,
onChanged: (value) {
ref.read(boardPreferencesProvider.notifier).toggleBorder();
},
),
],
),
],
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ packages:
dependency: "direct main"
description:
name: chessground
sha256: "363e3c408ef360807ee2d04ee6a2caab2d63fa0f66542cda2005927300da379e"
sha256: e2fba2e89f69a41fc77ef034a06fd087f14fdd5909b7d98bffb6e182d56d2a3a
url: "https://pub.dev"
source: hosted
version: "5.3.0"
version: "6.0.0"
ci:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
app_settings: ^5.1.1
async: ^2.10.0
cached_network_image: ^3.2.2
chessground: ^5.2.0
chessground: ^6.0.0
collection: ^1.17.0
connectivity_plus: ^6.0.2
cronet_http: ^1.3.1
Expand Down
3 changes: 1 addition & 2 deletions test/test_provider_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@ Future<Widget> makeTestProviderScope(

VisibilityDetectorController.instance.updateInterval = Duration.zero;

// disable piece animation and drawing shapes to simplify tests
// disable piece animation to simplify tests
final defaultBoardPref = {
'preferences.board': jsonEncode(
BoardPrefs.defaults
.copyWith(
pieceAnimation: false,
enableShapeDrawings: false,
)
.toJson(),
),
Expand Down

0 comments on commit 106cd91

Please sign in to comment.