Skip to content

Commit

Permalink
Merge branch 'main' into search_query
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPeled authored Aug 13, 2024
2 parents 023f68a + bcb85f7 commit 16acc23
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 65 deletions.
25 changes: 20 additions & 5 deletions lib/widgets/dialog_widgets/dialog_color_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class DialogColorPicker extends StatefulWidget {
final Function(Color color) onColorPicked;
final String label;
final Color initialColor;
final Color? defaultColor;

const DialogColorPicker(
{super.key,
required this.onColorPicked,
required this.label,
required this.initialColor});
const DialogColorPicker({
super.key,
required this.onColorPicked,
required this.label,
required this.initialColor,
this.defaultColor,
});

@override
State<DialogColorPicker> createState() => _DialogColorPickerState();
Expand Down Expand Up @@ -106,6 +109,18 @@ class _DialogColorPickerState extends State<DialogColorPicker> {
},
child: const Text('Cancel'),
),
if (widget.defaultColor != null)
TextButton(
onPressed: () {
Navigator.of(context).pop(false);
widget.onColorPicked.call(widget.defaultColor!);

setState(() {
selectedColor = widget.defaultColor!;
});
},
child: const Text('Restore Default'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(false);
Expand Down
152 changes: 110 additions & 42 deletions lib/widgets/nt_widgets/multi-topic/field_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:elastic_dashboard/services/field_images.dart';
import 'package:elastic_dashboard/services/nt4_client.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/services/text_formatter_builder.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_color_picker.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_dropdown_chooser.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_text_input.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_toggle_switch.dart';
Expand All @@ -31,11 +32,68 @@ class FieldWidgetModel extends NTWidgetModel {
bool _showOtherObjects = true;
bool _showTrajectories = true;

Color _robotColor = Colors.red;
Color _trajectoryColor = Colors.white;

final double _otherObjectSize = 0.55;
final double _trajectoryPointSize = 0.08;

Size? _widgetSize;

get robotWidthMeters => _robotWidthMeters;

set robotWidthMeters(value) {
_robotWidthMeters = value;
refresh();
}

get robotLengthMeters => _robotLengthMeters;

set robotLengthMeters(value) {
_robotLengthMeters = value;
refresh();
}

get showOtherObjects => _showOtherObjects;

set showOtherObjects(value) {
_showOtherObjects = value;
refresh();
}

get showTrajectories => _showTrajectories;

set showTrajectories(value) {
_showTrajectories = value;
refresh();
}

get robotColor => _robotColor;

set robotColor(value) {
_robotColor = value;
refresh();
}

get trajectoryColor => _trajectoryColor;

set trajectoryColor(value) {
_trajectoryColor = value;
refresh();
}

get otherObjectSize => _otherObjectSize;

get trajectoryPointSize => _trajectoryPointSize;

get widgetSize => _widgetSize;

set widgetSize(value) {
_widgetSize = value;
}

get field => _field;

late String _robotTopicName;
final List<String> _otherObjectTopics = [];

Expand All @@ -50,10 +108,18 @@ class FieldWidgetModel extends NTWidgetModel {
String? fieldName,
bool showOtherObjects = true,
bool showTrajectories = true,
double robotWidthMeters = 0.85,
double robotLengthMeters = 0.85,
Color robotColor = Colors.red,
Color trajectoryColor = Colors.white,
super.dataType,
super.period,
}) : _showTrajectories = showTrajectories,
_showOtherObjects = showOtherObjects,
_robotWidthMeters = robotWidthMeters,
_robotLengthMeters = robotLengthMeters,
_robotColor = robotColor,
_trajectoryColor = trajectoryColor,
super() {
_fieldGame = fieldName ?? _fieldGame;

Expand Down Expand Up @@ -84,6 +150,10 @@ class FieldWidgetModel extends NTWidgetModel {
}

_field = FieldImages.getFieldFromGame(_fieldGame)!;

_robotColor = Color(tryCast(jsonData['robot_color']) ?? Colors.red.value);
_trajectoryColor =
Color(tryCast(jsonData['trajectory_color']) ?? Colors.white.value);
}

@override
Expand Down Expand Up @@ -134,6 +204,8 @@ class FieldWidgetModel extends NTWidgetModel {
'robot_length': _robotLengthMeters,
'show_other_objects': _showOtherObjects,
'show_trajectories': _showTrajectories,
'robot_color': robotColor.value,
'trajectory_color': trajectoryColor.value,
};
}

Expand Down Expand Up @@ -274,6 +346,39 @@ class FieldWidgetModel extends NTWidgetModel {
),
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: DialogColorPicker(
onColorPicked: (color) {
robotColor = color;
},
label: 'Robot Color',
initialColor: robotColor,
defaultColor: Colors.red,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: DialogColorPicker(
onColorPicked: (color) {
trajectoryColor = color;
},
label: 'Trajectory Color',
initialColor: trajectoryColor,
defaultColor: Colors.white,
),
),
),
],
),
];
}

Expand Down Expand Up @@ -344,46 +449,6 @@ class FieldWidgetModel extends NTWidgetModel {
await Future.delayed(delayTime);
}
}

get robotWidthMeters => _robotWidthMeters;

set robotWidthMeters(value) {
_robotWidthMeters = value;
refresh();
}

get robotLengthMeters => _robotLengthMeters;

set robotLengthMeters(value) {
_robotLengthMeters = value;
refresh();
}

get showOtherObjects => _showOtherObjects;

set showOtherObjects(value) {
_showOtherObjects = value;
refresh();
}

get showTrajectories => _showTrajectories;

set showTrajectories(value) {
_showTrajectories = value;
refresh();
}

get otherObjectSize => _otherObjectSize;

get trajectoryPointSize => _trajectoryPointSize;

get widgetSize => _widgetSize;

set widgetSize(value) {
_widgetSize = value;
}

get field => _field;
}

class FieldWidget extends NTWidget {
Expand Down Expand Up @@ -448,7 +513,7 @@ class FieldWidget extends NTWidget {
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.35),
border: Border.all(
color: Colors.red,
color: model.robotColor,
width: 4.0,
),
),
Expand Down Expand Up @@ -613,6 +678,7 @@ class FieldWidget extends NTWidget {
for (List<Offset> points in trajectoryPoints)
CustomPaint(
painter: TrajectoryPainter(
color: model.trajectoryColor,
points: points,
strokeWidth: model.trajectoryPointSize *
model.field.pixelsPerMeterHorizontal *
Expand Down Expand Up @@ -668,10 +734,12 @@ class TrianglePainter extends CustomPainter {
class TrajectoryPainter extends CustomPainter {
final List<Offset> points;
final double strokeWidth;
final Color color;

TrajectoryPainter({
required this.points,
required this.strokeWidth,
this.color = Colors.white,
});

@override
Expand All @@ -680,7 +748,7 @@ class TrajectoryPainter extends CustomPainter {
return;
}
Paint trajectoryPaint = Paint()
..color = Colors.white
..color = color
..strokeWidth = strokeWidth
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/nt_widgets/single_topic/boolean_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class BooleanBoxModel extends NTWidgetModel {
},
label: 'True Color',
initialColor: _trueColor,
defaultColor: Colors.green,
),
const SizedBox(width: 10),
DialogColorPicker(
Expand All @@ -148,6 +149,7 @@ class BooleanBoxModel extends NTWidgetModel {
},
label: 'False Color',
initialColor: _falseColor,
defaultColor: Colors.red,
),
],
),
Expand Down
12 changes: 7 additions & 5 deletions lib/widgets/nt_widgets/single_topic/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ class GraphModel extends NTWidgetModel {
children: [
Flexible(
child: DialogColorPicker(
onColorPicked: (color) {
mainColor = color;
},
label: 'Graph Color',
initialColor: _mainColor),
onColorPicked: (color) {
mainColor = color;
},
label: 'Graph Color',
initialColor: _mainColor,
defaultColor: Colors.cyan,
),
),
Flexible(
child: DialogTextInput(
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class _SettingsDialogState extends State<SettingsDialog> {
onColorPicked: (color) => widget.onColorChanged?.call(color),
label: 'Team Color',
initialColor: currentColor,
defaultColor: Colors.blueAccent,
),
),
],
Expand Down
24 changes: 12 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -620,10 +620,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.11.1"
messagepack:
dependency: "direct main"
description:
Expand All @@ -636,10 +636,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.15.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -1033,10 +1033,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.7.2"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -1177,10 +1177,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "14.2.4"
watcher:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit 16acc23

Please sign in to comment.