From a3bd7aea2e91fb69a301b669182618fd5dd74484 Mon Sep 17 00:00:00 2001 From: Michael Jansen Date: Fri, 13 Oct 2023 21:57:21 -0400 Subject: [PATCH] Add auto editor setting to hide other paths on hover (#403) * Add auto editor setting to hide other paths on hover * add test for setting --- lib/util/prefs.dart | 2 + lib/widgets/editor/path_painter.dart | 62 +++++++++++-------- lib/widgets/editor/split_auto_editor.dart | 3 + .../tree_widgets/editor_settings_tree.dart | 28 +++++++++ .../editor_settings_tree_test.dart | 30 +++++++++ 5 files changed, 98 insertions(+), 27 deletions(-) diff --git a/lib/util/prefs.dart b/lib/util/prefs.dart index 3ae5d728..1c0895e2 100644 --- a/lib/util/prefs.dart +++ b/lib/util/prefs.dart @@ -19,6 +19,7 @@ class PrefsKeys { static const String pathFolders = 'pathFolders'; static const String autoFolders = 'autoFolders'; static const String snapToGuidelines = 'snapToGuidelines'; + static const String hidePathsOnHover = 'hidePathsOnHover'; } class Defaults { @@ -40,4 +41,5 @@ class Defaults { static List autoFolders = []; // Can't be const or user wont be able to add new folders static const bool snapToGuidelines = true; + static const bool hidePathsOnHover = true; } diff --git a/lib/widgets/editor/path_painter.dart b/lib/widgets/editor/path_painter.dart index 8e08446b..0ead7c22 100644 --- a/lib/widgets/editor/path_painter.dart +++ b/lib/widgets/editor/path_painter.dart @@ -15,6 +15,7 @@ class PathPainter extends CustomPainter { final List paths; final FieldImage fieldImage; final bool simple; + final bool hideOtherPathsOnHover; final String? hoveredPath; final int? hoveredWaypoint; final int? selectedWaypoint; @@ -40,6 +41,7 @@ class PathPainter extends CustomPainter { required this.paths, required this.fieldImage, this.simple = false, + this.hideOtherPathsOnHover = false, this.hoveredPath, this.hoveredWaypoint, this.selectedWaypoint, @@ -78,6 +80,12 @@ class PathPainter extends CustomPainter { scale = size.width / fieldImage.defaultSize.width; for (int i = 0; i < paths.length; i++) { + if (hideOtherPathsOnHover && + hoveredPath != null && + hoveredPath != paths[i].name) { + continue; + } + if (!simple) { _paintRadius(paths[i], canvas, scale); } @@ -99,35 +107,35 @@ class PathPainter extends CustomPainter { _paintWaypoint(paths[i], canvas, scale, 0); _paintWaypoint(paths[i], canvas, scale, paths[i].waypoints.length - 1); } + } - if (startingPose != null) { - PathPainterUtil.paintRobotOutline( - startingPose!.position, - startingPose!.rotation, - fieldImage, - robotSize, - scale, - canvas, - Colors.green.withOpacity(0.5)); - - var paint = Paint() - ..style = PaintingStyle.fill - ..color = Colors.green.withOpacity(0.5) - ..strokeWidth = 2; + if (startingPose != null) { + PathPainterUtil.paintRobotOutline( + startingPose!.position, + startingPose!.rotation, + fieldImage, + robotSize, + scale, + canvas, + Colors.green.withOpacity(0.8)); - canvas.drawCircle( - PathPainterUtil.pointToPixelOffset( - startingPose!.position, scale, fieldImage), - PathPainterUtil.uiPointSizeToPixels(25, scale, fieldImage), - paint); - paint.style = PaintingStyle.stroke; - paint.color = Colors.black; - canvas.drawCircle( - PathPainterUtil.pointToPixelOffset( - startingPose!.position, scale, fieldImage), - PathPainterUtil.uiPointSizeToPixels(25, scale, fieldImage), - paint); - } + var paint = Paint() + ..style = PaintingStyle.fill + ..color = Colors.green.withOpacity(0.5) + ..strokeWidth = 2; + + canvas.drawCircle( + PathPainterUtil.pointToPixelOffset( + startingPose!.position, scale, fieldImage), + PathPainterUtil.uiPointSizeToPixels(25, scale, fieldImage), + paint); + paint.style = PaintingStyle.stroke; + paint.color = Colors.black; + canvas.drawCircle( + PathPainterUtil.pointToPixelOffset( + startingPose!.position, scale, fieldImage), + PathPainterUtil.uiPointSizeToPixels(25, scale, fieldImage), + paint); } if (previewTime != null) { diff --git a/lib/widgets/editor/split_auto_editor.dart b/lib/widgets/editor/split_auto_editor.dart index 2ea661d9..0cb1e16c 100644 --- a/lib/widgets/editor/split_auto_editor.dart +++ b/lib/widgets/editor/split_auto_editor.dart @@ -205,6 +205,9 @@ class _SplitAutoEditorState extends State painter: PathPainter( paths: widget.autoPaths, simple: true, + hideOtherPathsOnHover: widget.prefs + .getBool(PrefsKeys.hidePathsOnHover) ?? + Defaults.hidePathsOnHover, hoveredPath: _hoveredPath, fieldImage: widget.fieldImage, startingPose: widget.auto.startingPose, diff --git a/lib/widgets/editor/tree_widgets/editor_settings_tree.dart b/lib/widgets/editor/tree_widgets/editor_settings_tree.dart index 83aff749..11bed419 100644 --- a/lib/widgets/editor/tree_widgets/editor_settings_tree.dart +++ b/lib/widgets/editor/tree_widgets/editor_settings_tree.dart @@ -18,6 +18,7 @@ class EditorSettingsTree extends StatefulWidget { class _EditorSettingsTreeState extends State { late SharedPreferences _prefs; bool _snapToGuidelines = Defaults.snapToGuidelines; + bool _hidePathsOnHover = Defaults.hidePathsOnHover; @override void initState() { @@ -28,6 +29,8 @@ class _EditorSettingsTreeState extends State { _prefs = value; _snapToGuidelines = _prefs.getBool(PrefsKeys.snapToGuidelines) ?? Defaults.snapToGuidelines; + _hidePathsOnHover = _prefs.getBool(PrefsKeys.hidePathsOnHover) ?? + Defaults.hidePathsOnHover; }); }); } @@ -63,6 +66,31 @@ class _EditorSettingsTreeState extends State { ), ], ), + Row( + children: [ + Checkbox( + value: _hidePathsOnHover, + onChanged: (val) { + if (val != null) { + setState(() { + _hidePathsOnHover = val; + _prefs.setBool(PrefsKeys.hidePathsOnHover, val); + }); + } + }, + ), + const Padding( + padding: EdgeInsets.only( + bottom: 3.0, + left: 4.0, + ), + child: Text( + 'Hide Other Paths on Hover', + style: TextStyle(fontSize: 15), + ), + ), + ], + ), ], ); } diff --git a/test/widgets/editor/tree_widgets/editor_settings_tree_test.dart b/test/widgets/editor/tree_widgets/editor_settings_tree_test.dart index dcbca1b5..8665b2a8 100644 --- a/test/widgets/editor/tree_widgets/editor_settings_tree_test.dart +++ b/test/widgets/editor/tree_widgets/editor_settings_tree_test.dart @@ -10,6 +10,7 @@ void main() { setUp(() async { SharedPreferences.setMockInitialValues({ PrefsKeys.snapToGuidelines: false, + PrefsKeys.hidePathsOnHover: false, }); prefs = await SharedPreferences.getInstance(); }); @@ -43,4 +44,33 @@ void main() { expect(prefs.getBool(PrefsKeys.snapToGuidelines), false); }); + + testWidgets('hide paths check', (widgetTester) async { + await widgetTester.pumpWidget(const MaterialApp( + home: Scaffold( + body: EditorSettingsTree( + initiallyExpanded: true, + ), + ), + )); + await widgetTester.pump(); + + final row = find.widgetWithText(Row, 'Hide Other Paths on Hover'); + + expect(row, findsOneWidget); + + final check = find.descendant(of: row, matching: find.byType(Checkbox)); + + expect(check, findsOneWidget); + + await widgetTester.tap(check); + await widgetTester.pumpAndSettle(); + + expect(prefs.getBool(PrefsKeys.hidePathsOnHover), true); + + await widgetTester.tap(check); + await widgetTester.pumpAndSettle(); + + expect(prefs.getBool(PrefsKeys.hidePathsOnHover), false); + }); }