Skip to content

Commit

Permalink
Update dropdown buttons in shape and constraints to material 3
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 29, 2024
1 parent 5cc7321 commit 8521a65
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 deletions.
43 changes: 19 additions & 24 deletions app/lib/dialogs/constraints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class _ConstraintsViewState extends State<ConstraintsView> {
),
_ => 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;
Expand All @@ -70,30 +75,20 @@ class _ConstraintsViewState extends State<ConstraintsView> {
onTap: () => setState(() {
opened = !isExpanded;
}),
trailing: DropdownButton<String>(
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<String>(
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);
}
},
),
),
],
Expand Down
3 changes: 2 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -637,5 +637,6 @@
"colorToolbar": "Color toolbar",
"yesButShowButtons": "Yes, but show buttons",
"optionsPanelPosition": "Options panel position",
"hideDuration": "Hide duration"
"hideDuration": "Hide duration",
"animation": "Animation"
}
18 changes: 11 additions & 7 deletions app/lib/selections/tools/laser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,25 @@ class LaserToolSelection extends ToolSelection<LaserTool> {
),
),
ListTile(
title: Text(AppLocalizations.of(context).shape),
trailing: DropdownButton<LaserAnimation>(
items: LaserAnimation.values
title: Text(AppLocalizations.of(context).animation),
trailing: DropdownMenu<LaserAnimation>(
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,
Expand Down
43 changes: 23 additions & 20 deletions app/lib/selections/tools/shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ class _ShapeViewState extends State<ShapeView> {
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(() {
Expand All @@ -193,26 +200,22 @@ class _ShapeViewState extends State<ShapeView> {
canTapOnHeader: true,
headerBuilder: (context, expanded) => ListTile(
title: Text(AppLocalizations.of(context).shape),
trailing: DropdownButton<String>(
value: _currentShape.runtimeType.toString(),
items: [
PathShape.circle,
PathShape.rectangle,
PathShape.line,
PathShape.triangle
].map((e) {
var shape = e();
return DropdownMenuItem<String>(
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<String>(
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,
Expand Down
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/123.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8521a65

Please sign in to comment.