From 8521a65ab8713096fa635cb0c395a2428aef07dc Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Fri, 29 Nov 2024 22:34:55 +0100 Subject: [PATCH] Update dropdown buttons in shape and constraints to material 3 --- app/lib/dialogs/constraints.dart | 43 +++++++++++++---------------- app/lib/l10n/app_en.arb | 3 +- app/lib/selections/tools/laser.dart | 18 +++++++----- app/lib/selections/tools/shape.dart | 43 +++++++++++++++-------------- app/pubspec.lock | 4 +-- metadata/en-US/changelogs/123.txt | 1 + 6 files changed, 58 insertions(+), 54 deletions(-) diff --git a/app/lib/dialogs/constraints.dart b/app/lib/dialogs/constraints.dart index 022968371b2e..86c2c9996578 100644 --- a/app/lib/dialogs/constraints.dart +++ b/app/lib/dialogs/constraints.dart @@ -55,6 +55,11 @@ class _ConstraintsViewState extends State { ), _ => null, }; + final all = Map.fromEntries([ + const FixedElementConstraints(0, 0), + const ScaledElementConstraints(scaleX: 1, scaleY: 1), + const DynamicElementConstraints() + ].map((e) => MapEntry(e.getLocalizedName(context), e))); return ExpansionPanelList( expansionCallback: (panelIndex, isExpanded) => setState(() { opened = isExpanded; @@ -70,30 +75,20 @@ class _ConstraintsViewState extends State { onTap: () => setState(() { opened = !isExpanded; }), - trailing: DropdownButton( - items: [ - ...[ - const FixedElementConstraints(0, 0), - const ScaledElementConstraints(scaleX: 1, scaleY: 1), - const DynamicElementConstraints() - ].map((e) => DropdownMenuItem( - value: e.runtimeType.toString(), - child: Text( - e.getLocalizedName(context), - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), - onTap: () { - setState(() { - constraints = e; - opened = false; - }); - _onChanged(e); - }, - )) - ], - value: constraints?.runtimeType.toString(), - onChanged: (value) {}, + trailing: DropdownMenu( + dropdownMenuEntries: all.entries + .map((e) => DropdownMenuEntry( + value: e.key, + label: e.key, + )) + .toList(), + initialSelection: constraints.getLocalizedName(context), + onSelected: (value) { + final constraint = all[value]; + if (constraint != null) { + _onChanged(constraint); + } + }, ), ), ], diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index c9b095d69f3b..70c7e9049fd5 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -637,5 +637,6 @@ "colorToolbar": "Color toolbar", "yesButShowButtons": "Yes, but show buttons", "optionsPanelPosition": "Options panel position", - "hideDuration": "Hide duration" + "hideDuration": "Hide duration", + "animation": "Animation" } diff --git a/app/lib/selections/tools/laser.dart b/app/lib/selections/tools/laser.dart index d4b4a91b5900..dce7b6ac3073 100644 --- a/app/lib/selections/tools/laser.dart +++ b/app/lib/selections/tools/laser.dart @@ -61,21 +61,25 @@ class LaserToolSelection extends ToolSelection { ), ), ListTile( - title: Text(AppLocalizations.of(context).shape), - trailing: DropdownButton( - items: LaserAnimation.values + title: Text(AppLocalizations.of(context).animation), + trailing: DropdownMenu( + dropdownMenuEntries: LaserAnimation.values .map( - (e) => DropdownMenuItem( + (e) => DropdownMenuEntry( value: e, - child: Text(switch (e) { + label: switch (e) { LaserAnimation.fade => AppLocalizations.of(context).color, LaserAnimation.path => AppLocalizations.of(context).path, + }, + leadingIcon: Icon(switch (e) { + LaserAnimation.fade => PhosphorIconsLight.palette, + LaserAnimation.path => PhosphorIconsLight.path, }), ), ) .toList(), - value: selected.first.animation, - onChanged: (LaserAnimation? value) { + initialSelection: selected.first.animation, + onSelected: (value) { if (value != null) { update( context, diff --git a/app/lib/selections/tools/shape.dart b/app/lib/selections/tools/shape.dart index 250c551ca4da..58793771b8cf 100644 --- a/app/lib/selections/tools/shape.dart +++ b/app/lib/selections/tools/shape.dart @@ -181,6 +181,13 @@ class _ShapeViewState extends State { Widget build(BuildContext context) { Widget shapeView = _buildShapeView(); + final shapes = Map.fromEntries([ + PathShape.circle, + PathShape.rectangle, + PathShape.line, + PathShape.triangle + ].map((e) => e()).map((e) => MapEntry(e.getLocalizedName(context), e))); + return ExpansionPanelList( expansionCallback: (index, isExpanded) { setState(() { @@ -193,26 +200,22 @@ class _ShapeViewState extends State { canTapOnHeader: true, headerBuilder: (context, expanded) => ListTile( title: Text(AppLocalizations.of(context).shape), - trailing: DropdownButton( - value: _currentShape.runtimeType.toString(), - items: [ - PathShape.circle, - PathShape.rectangle, - PathShape.line, - PathShape.triangle - ].map((e) { - var shape = e(); - return DropdownMenuItem( - value: shape.runtimeType.toString(), - child: Row(children: [ - PhosphorIcon(shape.icon(PhosphorIconsStyle.light)), - const SizedBox(width: 8), - Text(shape.getLocalizedName(context)), - ]), - onTap: () => _onShapeChanged(shape), - ); - }).toList(), - onChanged: (value) {}, + trailing: DropdownMenu( + initialSelection: _currentShape.getLocalizedName(context), + dropdownMenuEntries: shapes.entries + .map((e) => DropdownMenuEntry( + label: e.key, + value: e.key, + leadingIcon: + Icon(e.value.icon(PhosphorIconsStyle.light)), + )) + .toList(), + onSelected: (value) { + final shape = shapes[value]; + if (shape != null) { + _onShapeChanged(shape); + } + }, ), ), body: shapeView, diff --git a/app/pubspec.lock b/app/pubspec.lock index 8d4fdedc8cbe..37b6c49e5fd1 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -1627,10 +1627,10 @@ packages: dependency: transitive description: name: win32 - sha256: "84ba388638ed7a8cb3445a320c8273136ab2631cd5f2c57888335504ddab1bc2" + sha256: "8b338d4486ab3fbc0ba0db9f9b4f5239b6697fcee427939a40e720cbb9ee0a69" url: "https://pub.dev" source: hosted - version: "5.8.0" + version: "5.9.0" win32_registry: dependency: transitive description: diff --git a/metadata/en-US/changelogs/123.txt b/metadata/en-US/changelogs/123.txt index 200603d455fa..b8a2e940551a 100644 --- a/metadata/en-US/changelogs/123.txt +++ b/metadata/en-US/changelogs/123.txt @@ -6,6 +6,7 @@ * Separate laser duration in normal duration and hide duration * Use long press to move tools on all platforms to improve desktop touch behavior * Use sha checksum for assets +* Update dropdown buttons in shape and constraints to material 3 * Separate personalization settings in new view settings * Fix webdav on windows