Skip to content

Commit

Permalink
Add auto editor setting to hide other paths on hover (#403)
Browse files Browse the repository at this point in the history
* Add auto editor setting to hide other paths on hover

* add test for setting
  • Loading branch information
mjansen4857 authored Oct 14, 2023
1 parent a0184fe commit a3bd7ae
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 27 deletions.
2 changes: 2 additions & 0 deletions lib/util/prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -40,4 +41,5 @@ class Defaults {
static List<String> autoFolders =
[]; // Can't be const or user wont be able to add new folders
static const bool snapToGuidelines = true;
static const bool hidePathsOnHover = true;
}
62 changes: 35 additions & 27 deletions lib/widgets/editor/path_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PathPainter extends CustomPainter {
final List<PathPlannerPath> paths;
final FieldImage fieldImage;
final bool simple;
final bool hideOtherPathsOnHover;
final String? hoveredPath;
final int? hoveredWaypoint;
final int? selectedWaypoint;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/editor/split_auto_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class _SplitAutoEditorState extends State<SplitAutoEditor>
painter: PathPainter(
paths: widget.autoPaths,
simple: true,
hideOtherPathsOnHover: widget.prefs
.getBool(PrefsKeys.hidePathsOnHover) ??
Defaults.hidePathsOnHover,
hoveredPath: _hoveredPath,
fieldImage: widget.fieldImage,
startingPose: widget.auto.startingPose,
Expand Down
28 changes: 28 additions & 0 deletions lib/widgets/editor/tree_widgets/editor_settings_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EditorSettingsTree extends StatefulWidget {
class _EditorSettingsTreeState extends State<EditorSettingsTree> {
late SharedPreferences _prefs;
bool _snapToGuidelines = Defaults.snapToGuidelines;
bool _hidePathsOnHover = Defaults.hidePathsOnHover;

@override
void initState() {
Expand All @@ -28,6 +29,8 @@ class _EditorSettingsTreeState extends State<EditorSettingsTree> {
_prefs = value;
_snapToGuidelines = _prefs.getBool(PrefsKeys.snapToGuidelines) ??
Defaults.snapToGuidelines;
_hidePathsOnHover = _prefs.getBool(PrefsKeys.hidePathsOnHover) ??
Defaults.hidePathsOnHover;
});
});
}
Expand Down Expand Up @@ -63,6 +66,31 @@ class _EditorSettingsTreeState extends State<EditorSettingsTree> {
),
],
),
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),
),
),
],
),
],
);
}
Expand Down
30 changes: 30 additions & 0 deletions test/widgets/editor/tree_widgets/editor_settings_tree_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void main() {
setUp(() async {
SharedPreferences.setMockInitialValues({
PrefsKeys.snapToGuidelines: false,
PrefsKeys.hidePathsOnHover: false,
});
prefs = await SharedPreferences.getInstance();
});
Expand Down Expand Up @@ -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);
});
}

0 comments on commit a3bd7ae

Please sign in to comment.