Skip to content

Commit

Permalink
Improve moves/summary toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Nov 14, 2023
1 parent ff61b18 commit 29500bf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Binary file modified assets/fonts/LichessIcons.ttf
Binary file not shown.
6 changes: 6 additions & 0 deletions fluttericon.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@
"css": "tools",
"code": 63449,
"src": "fontawesome5"
},
{
"uid": "898ddc67cb7d9ae53dbd4cce78043e9e",
"css": "flow-cascade",
"code": 59421,
"src": "entypo"
}
]
}
17 changes: 13 additions & 4 deletions lib/src/model/analysis/analysis_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AnalysisController extends _$AnalysisController {
contextOpening: options.opening,
isLocalEvaluationAllowed: options.isLocalEvaluationAllowed,
isLocalEvaluationEnabled: prefs.enableLocalEvaluation,
showAcplChart: false,
displayMode: DisplayMode.moves,
acplChartData: acplChartData?.lock,
);
}
Expand Down Expand Up @@ -222,8 +222,12 @@ class AnalysisController extends _$AnalysisController {
state = state.copyWith(pgnHeaders: headers);
}

void toggleAcplChart() {
state = state.copyWith(showAcplChart: !state.showAcplChart);
void toggleDisplayMode() {
state = state.copyWith(
displayMode: state.displayMode == DisplayMode.moves
? DisplayMode.summary
: DisplayMode.moves,
);
}

/// Gets the node and maybe the associated branch opening at the given path.
Expand Down Expand Up @@ -349,6 +353,11 @@ class AnalysisController extends _$AnalysisController {
}
}

enum DisplayMode {
moves,
summary,
}

@freezed
class AnalysisState with _$AnalysisState {
const AnalysisState._();
Expand Down Expand Up @@ -386,7 +395,7 @@ class AnalysisState with _$AnalysisState {
required bool isLocalEvaluationEnabled,

/// Whether to show the ACPL chart instead of tree view.
required bool showAcplChart,
required DisplayMode displayMode,

/// The last move played.
Move? lastMove,
Expand Down
6 changes: 6 additions & 0 deletions lib/src/styles/lichess_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
/// Author: Dave Gandy
/// License: SIL ()
/// Homepage: http://fortawesome.github.com/Font-Awesome/
/// * Entypo, Copyright (C) 2012 by Daniel Bruce
/// Author: Daniel Bruce
/// License: SIL (http://scripts.sil.org/OFL)
/// Homepage: http://www.entypo.com
/// * Font Awesome 5, Copyright (C) 2016 by Dave Gandy
/// Author: Dave Gandy
/// License: SIL (https://github.com/FortAwesome/Font-Awesome/blob/master/LICENSE.txt)
Expand Down Expand Up @@ -85,6 +89,8 @@ class LichessIcons {
IconData(0xe81a, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData lichess =
IconData(0xe81b, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData flow_cascade =
IconData(0xe81d, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData tag =
IconData(0xf02b, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData tags =
Expand Down
17 changes: 13 additions & 4 deletions lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:share_plus/share_plus.dart';
import 'package:fl_chart/fl_chart.dart';

import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/styles/lichess_icons.dart';
import 'package:lichess_mobile/src/model/common/eval.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/model/engine/engine_evaluation.dart';
Expand Down Expand Up @@ -148,7 +149,9 @@ class _Body extends ConsumerWidget {

final showAcplChart = ref.watch(
ctrlProvider.select(
(value) => value.acplChartData != null && value.showAcplChart,
(value) =>
value.acplChartData != null &&
value.displayMode == DisplayMode.summary,
),
);

Expand Down Expand Up @@ -588,6 +591,9 @@ class _BottomBar extends ConsumerWidget {
ref.watch(ctrlProvider.select((value) => value.canGoBack));
final canGoNext =
ref.watch(ctrlProvider.select((value) => value.canGoNext));
final displayMode = ref.watch(
ctrlProvider.select((value) => value.displayMode),
);

return Container(
padding: Styles.horizontalBodyPadding,
Expand All @@ -610,11 +616,14 @@ class _BottomBar extends ConsumerWidget {
if (options.hasLichessServerAnalysis == true)
BottomBarButton(
label: context.l10n.computerAnalysis,
shortLabel: 'Summary',
shortLabel:
displayMode == DisplayMode.summary ? 'Moves' : 'Summary',
onTap: () {
ref.read(ctrlProvider.notifier).toggleAcplChart();
ref.read(ctrlProvider.notifier).toggleDisplayMode();
},
icon: Icons.area_chart,
icon: displayMode == DisplayMode.summary
? LichessIcons.flow_cascade
: Icons.area_chart,
),
RepeatButton(
onLongPress: canGoBack ? () => _moveBackward(ref) : null,
Expand Down

0 comments on commit 29500bf

Please sign in to comment.