From 591f55d6eae96b51b5a766fb4e8e5c8aec911523 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Sun, 15 Dec 2024 11:30:52 +0100 Subject: [PATCH] Fix selection alpha and add pen options --- app/lib/selections/elements/pen.dart | 19 +++++++++---------- app/lib/selections/elements/shape.dart | 9 ++++++--- app/lib/selections/properties/pen.dart | 6 +++--- app/lib/selections/tools/label.dart | 9 +++++++-- app/lib/selections/tools/shape.dart | 26 +++++++++++++++----------- app/lib/selections/utilities.dart | 7 +++++-- metadata/en-US/changelogs/124.txt | 2 ++ 7 files changed, 47 insertions(+), 31 deletions(-) diff --git a/app/lib/selections/elements/pen.dart b/app/lib/selections/elements/pen.dart index d0648fe77b68..d01d550edd3f 100644 --- a/app/lib/selections/elements/pen.dart +++ b/app/lib/selections/elements/pen.dart @@ -1,23 +1,22 @@ part of '../selection.dart'; class PenElementSelection extends ElementSelection { + final _propertySelection = PenPropertySelection(); + PenElementSelection(super.selected); @override List buildProperties(BuildContext context) { final element = selected.first.element; + void updateProperty(PenProperty property) => updateElements( + context, elements.map((e) => e.copyWith(property: property)).toList()); return [ ...super.buildProperties(context), - ColorField( - title: Text(AppLocalizations.of(context).color), - value: Color(element.property.color), - onChanged: (color) => updateElements( - context, - elements - .map((e) => e.copyWith( - // ignore: deprecated_member_use - property: e.property.copyWith(color: color.value))) - .toList()), + SizedBox(height: 16), + ..._propertySelection.build( + context, + element.property, + updateProperty, ), ]; } diff --git a/app/lib/selections/elements/shape.dart b/app/lib/selections/elements/shape.dart index c17d6355b31a..2807013d30ad 100644 --- a/app/lib/selections/elements/shape.dart +++ b/app/lib/selections/elements/shape.dart @@ -10,13 +10,16 @@ class ShapeElementSelection extends ElementSelection { ...super.buildProperties(context), ColorField( title: Text(AppLocalizations.of(context).color), - value: Color(element.property.color), + value: Color(element.property.color).withAlpha(255), onChanged: (color) => updateElements( context, elements .map((e) => e.copyWith( - // ignore: deprecated_member_use - property: e.property.copyWith(color: color.value))) + property: e.property.copyWith( + color: convertOldColor( + // ignore: deprecated_member_use + color.value, + element.property.color)))) .toList()), ), ExactSlider( diff --git a/app/lib/selections/properties/pen.dart b/app/lib/selections/properties/pen.dart index b2f705f534ac..1646703d4764 100644 --- a/app/lib/selections/properties/pen.dart +++ b/app/lib/selections/properties/pen.dart @@ -14,10 +14,10 @@ class PenPropertySelection extends PropertySelection ...super.build(context, property, onChanged), const SizedBox(height: 4), ColorField( - value: Color(property.color), - onChanged: (value) => + value: Color(property.color).withAlpha(255), + onChanged: (value) => onChanged(property.copyWith( // ignore: deprecated_member_use - onChanged(property.copyWith(color: value.value)), + color: convertOldColor(value.value, property.color))), title: Text(AppLocalizations.of(context).color), ), ExactSlider( diff --git a/app/lib/selections/tools/label.dart b/app/lib/selections/tools/label.dart index cced00d36004..f53160efa65c 100644 --- a/app/lib/selections/tools/label.dart +++ b/app/lib/selections/tools/label.dart @@ -14,8 +14,13 @@ class LabelToolSelection extends ToolSelection { value: Color(selected.first.foreground), onChanged: (value) => update( context, - // ignore: deprecated_member_use - selected.map((e) => e.copyWith(foreground: value.value)).toList()), + selected + .map((e) => e.copyWith( + foreground: convertOldColor( + // ignore: deprecated_member_use + value.value, + selected.first.foreground))) + .toList()), title: Text(AppLocalizations.of(context).foreground), ), ExactSlider( diff --git a/app/lib/selections/tools/shape.dart b/app/lib/selections/tools/shape.dart index 0e6b453beb06..45155aacfd6f 100644 --- a/app/lib/selections/tools/shape.dart +++ b/app/lib/selections/tools/shape.dart @@ -71,7 +71,7 @@ class ShapeToolSelection extends ToolSelection { .toList())), ExactSlider( header: Text(AppLocalizations.of(context).strokeWidth), - value: tool.property.strokeWidth, + value: property.strokeWidth, min: 0, max: 70, defaultValue: 5, @@ -83,13 +83,14 @@ class ShapeToolSelection extends ToolSelection { .toList())), const SizedBox(height: 50), ColorField( - value: Color(tool.property.color), + value: Color(property.color), onChanged: (color) => update( context, selected .map((e) => e.copyWith( - // ignore: deprecated_member_use - property: e.property.copyWith(color: color.value))) + property: e.property.copyWith( + // ignore: deprecated_member_use + color: convertOldColor(color.value, property.color)))) .toList()), title: Text(AppLocalizations.of(context).color), ), @@ -240,8 +241,9 @@ class _CircleShapeView extends StatelessWidget { title: Text(AppLocalizations.of(context).fill), leading: const PhosphorIcon(PhosphorIconsLight.paintBucket), defaultColor: Colors.transparent, - // ignore: deprecated_member_use - onChanged: (color) => onChanged(shape.copyWith(fillColor: color.value)), + onChanged: (color) => onChanged(shape.copyWith( + // ignore: deprecated_member_use + fillColor: convertOldColor(color.value, shape.fillColor))), ), ExactSlider( // ignore: deprecated_member_use @@ -271,8 +273,9 @@ class _TriangleShapeView extends StatelessWidget { title: Text(AppLocalizations.of(context).fill), leading: const PhosphorIcon(PhosphorIconsLight.paintBucket), defaultColor: Colors.transparent, - // ignore: deprecated_member_use - onChanged: (color) => onChanged(shape.copyWith(fillColor: color.value)), + onChanged: (color) => onChanged(shape.copyWith( + // ignore: deprecated_member_use + fillColor: convertOldColor(color.value, shape.fillColor))), ), ExactSlider( // ignore: deprecated_member_use @@ -309,9 +312,10 @@ class _RectangleShapeViewState extends State<_RectangleShapeView> { leading: const PhosphorIcon(PhosphorIconsLight.paintBucket), value: Color(widget.shape.fillColor), defaultColor: Colors.transparent, - onChanged: (color) => - // ignore: deprecated_member_use - widget.onChanged(widget.shape.copyWith(fillColor: color.value)), + onChanged: (color) => widget.onChanged(widget.shape.copyWith( + fillColor: + // ignore: deprecated_member_use + convertOldColor(color.value, widget.shape.fillColor))), ), ExactSlider( // ignore: deprecated_member_use diff --git a/app/lib/selections/utilities.dart b/app/lib/selections/utilities.dart index 194ce4043ad4..2a6324b806c9 100644 --- a/app/lib/selections/utilities.dart +++ b/app/lib/selections/utilities.dart @@ -232,8 +232,11 @@ class _UtilitiesViewState extends State<_UtilitiesView> title: Text(AppLocalizations.of(context).color), value: Color(widget.option.gridColor), onChanged: (value) => widget.onToolChanged( - // ignore: deprecated_member_use - widget.option.copyWith(gridColor: value.value), + widget.option.copyWith( + gridColor: convertOldColor( + // ignore: deprecated_member_use + value.value, + widget.option.gridColor)), ), ), const SizedBox(height: 8), diff --git a/metadata/en-US/changelogs/124.txt b/metadata/en-US/changelogs/124.txt index 9acbe0e10991..e13b7c4dc645 100644 --- a/metadata/en-US/changelogs/124.txt +++ b/metadata/en-US/changelogs/124.txt @@ -10,6 +10,7 @@ * Change zoom dependent to false by default * Use material blue and red as default colors * Improve sliders for background dialog +* Add additional selection ui options to the pen element * Fix export on web * Fix shape detection always enabled in pen tool * Fix ruler not working correctly in pen tool @@ -23,6 +24,7 @@ * Fix document isn't saved when clicking home * Fix stamp don't use unique element ids * Fix render order when creating multiple elements when baking +* Fix some color fields don't keep alpha value * Show git hash instead of version in web version * Upgrade to flutter 3.27