Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@
},
"inputGestures": "Input gestures",
"nativeTitleBar": "Native title bar",
"mode": "Mode",
"syncMode": "Sync mode",
"connection": "Connection",
"always": "Always",
Expand Down Expand Up @@ -919,6 +920,7 @@
"bringForward": "Bring forward",
"sendBackward": "Send backward",
"rotation": "Rotation",
"direction": "Direction",
"onlyAvailableLargerScreen": "Only available on larger screens",
"toolbarPosition": "Toolbar position",
"rotate": "Rotate",
Expand Down
2 changes: 2 additions & 0 deletions app/lib/selections/selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ part 'tools/eraser.dart';
part 'tools/grid.dart';
part 'tools/label.dart';
part 'tools/laser.dart';
part 'tools/selection.dart';
part 'tools/path_eraser.dart';
part 'tools/pen.dart';
part 'tools/polygon.dart';
part 'tools/ruler.dart';
part 'tools/shape.dart';
part 'tools/stamp.dart';
part 'tools/texture.dart';
part 'tools/spacer.dart';

part 'properties/property.dart';
part 'properties/pen.dart';
Expand Down
44 changes: 44 additions & 0 deletions app/lib/selections/tools/selection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
part of '../selection.dart';

class SelectToolSelection extends ToolSelection<SelectTool> {
SelectToolSelection(super.selected);

@override
List<Widget> buildProperties(BuildContext context) {
final loc = AppLocalizations.of(context);
return [
...super.buildProperties(context),
ListTile(
title: Text(loc.mode),
trailing: DropdownMenu<SelectMode>(
initialSelection: selected.first.mode,
dropdownMenuEntries: SelectMode.values
.map(
(e) => DropdownMenuEntry(
label: e.getLocalizedName(context),
leadingIcon: Icon(e.icon(PhosphorIconsStyle.light)),
value: e,
),
)
.toList(),
onSelected: (value) {
if (value != null) {
update(
context,
selected.map((e) => e.copyWith(mode: value)).toList(),
);
}
},
),
),
];
}

@override
Selection insert(dynamic element) {
if (element is SelectTool) {
return SelectToolSelection([...selected, element]);
}
return super.insert(element);
}
}
44 changes: 44 additions & 0 deletions app/lib/selections/tools/spacer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
part of '../selection.dart';

class SpacerToolSelection extends ToolSelection<SpacerTool> {
SpacerToolSelection(super.selected);

@override
List<Widget> buildProperties(BuildContext context) {
final loc = AppLocalizations.of(context);
return [
...super.buildProperties(context),
ListTile(
title: Text(loc.direction),
trailing: DropdownMenu<Axis2D>(
initialSelection: selected.first.axis,
dropdownMenuEntries: Axis2D.values
.map(
(e) => DropdownMenuEntry(
label: e.getLocalizedName(context),
leadingIcon: Icon(e.icon(PhosphorIconsStyle.light)),
value: e,
),
)
.toList(),
onSelected: (value) {
if (value != null) {
update(
context,
selected.map((e) => e.copyWith(axis: value)).toList(),
);
}
},
),
),
];
}

@override
Selection insert(dynamic element) {
if (element is SpacerTool) {
return SpacerToolSelection([...selected, element]);
}
return super.insert(element);
}
}
2 changes: 2 additions & 0 deletions app/lib/selections/tools/tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ToolSelection<T extends Tool> extends Selection<T> {
TextureTool e => TextureToolSelection([e]),
BarcodeTool e => BarcodeToolSelection([e]),
PolygonTool e => PolygonToolSelection([e]),
SelectTool e => SelectToolSelection([e]),
SpacerTool e => SpacerToolSelection([e]),
_ => ToolSelection<T>([selected]),
}
as ToolSelection<T>;
Expand Down
31 changes: 28 additions & 3 deletions app/lib/visualizer/tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension ToolCategoryVisualizer on ToolCategory {
ToolCategory.action => PhosphorIcons.play,
ToolCategory.view => PhosphorIcons.eye,
};

String getLocalizedName(BuildContext context) => switch (this) {
ToolCategory.normal => AppLocalizations.of(context).normal,
ToolCategory.import => AppLocalizations.of(context).import,
Expand All @@ -36,13 +37,38 @@ extension BarcodeTypeVisualizer on BarcodeType {
BarcodeType.dataMatrix => AppLocalizations.of(context).dataMatrix,
BarcodeType.code128 => AppLocalizations.of(context).code128,
};

IconGetter get icon => switch (this) {
BarcodeType.qrCode => PhosphorIcons.qrCode,
BarcodeType.dataMatrix => PhosphorIcons.scan,
BarcodeType.code128 => PhosphorIcons.barcode,
};
}

extension SelectModeVisualizer on SelectMode {
String getLocalizedName(BuildContext context) => switch (this) {
SelectMode.rectangle => AppLocalizations.of(context).rectangle,
SelectMode.lasso => AppLocalizations.of(context).lasso,
};

IconGetter get icon => switch (this) {
SelectMode.rectangle => PhosphorIcons.selection,
SelectMode.lasso => PhosphorIcons.lasso,
};
}

extension Axis2DVisualizer on Axis2D {
String getLocalizedName(BuildContext context) => switch (this) {
Axis2D.horizontal => AppLocalizations.of(context).horizontal,
Axis2D.vertical => AppLocalizations.of(context).vertical,
};

IconGetter get icon => switch (this) {
Axis2D.horizontal => PhosphorIcons.splitHorizontal,
Axis2D.vertical => PhosphorIcons.splitVertical,
};
}

extension ToolVisualizer on Tool {
String getDisplay(BuildContext context) {
if (name.trim().isEmpty) return getLocalizedName(context);
Expand Down Expand Up @@ -83,9 +109,8 @@ extension ToolVisualizer on Tool {
String getLocalizedCaption(BuildContext context) {
final loc = AppLocalizations.of(context);
return switch (this) {
SpacerTool e =>
e.axis == Axis2D.horizontal ? loc.horizontal : loc.vertical,
SelectTool e => e.mode == SelectMode.lasso ? loc.lasso : loc.rectangle,
SpacerTool e => e.axis.getLocalizedName(context),
SelectTool e => e.mode.getLocalizedName(context),
ExportTool e => switch (e.options) {
ImageExportOptions() => loc.image,
SvgExportOptions() => loc.svg,
Expand Down
Loading