From 8d1f8db7e89a67495962a067f085f1d515da0a06 Mon Sep 17 00:00:00 2001 From: lingjhf Date: Fri, 9 Oct 2026 19:24:00 +0800 Subject: [PATCH] feat(inspector): add animated independent corners and layered shadow controls --- .../editor/layouts/bounded_editor_layout.dart | 13 +- lib/features/properties/animation_labels.dart | 1 + lib/features/properties/audio_properties.dart | 14 +- .../properties/caption_properties.dart | 82 +- .../color_interpretation_properties.dart | 8 +- lib/features/properties/mask_properties.dart | 155 ++- lib/features/properties/picture_edits.dart | 3 +- lib/features/properties/picture_edits.g.dart | 2 +- .../properties/picture_properties.dart | 338 ++++-- .../properties/project_properties.dart | 24 +- .../properties/project_property_row.dart | 16 +- .../project_property_row_previews.dart | 6 +- lib/features/properties/properties_panel.dart | 2 +- .../properties/property_number_input.dart | 33 +- .../properties/shadow_properties.dart | 1070 +++++++++++++++++ lib/features/properties/speed_properties.dart | 5 +- test/caption_edit_context_test.dart | 3 +- test/compact_inspector_test.dart | 103 +- test/picture_corner_radius_test.dart | 226 ++++ test/picture_shadow_test.dart | 485 ++++++++ test/project_properties_test.dart | 8 +- test/property_number_input_test.dart | 2 +- test/transcription_tools_test.dart | 4 +- 23 files changed, 2375 insertions(+), 228 deletions(-) create mode 100644 lib/features/properties/shadow_properties.dart create mode 100644 test/picture_corner_radius_test.dart create mode 100644 test/picture_shadow_test.dart diff --git a/lib/features/editor/layouts/bounded_editor_layout.dart b/lib/features/editor/layouts/bounded_editor_layout.dart index 6379653..1874502 100644 --- a/lib/features/editor/layouts/bounded_editor_layout.dart +++ b/lib/features/editor/layouts/bounded_editor_layout.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import '../../../integrations/platform/device_experience.dart'; import '../../../l10n/l10n.dart'; +import '../../../shared/layout/workspace_layout_metrics.dart'; import 'package:cutdex_ui/icons.dart'; import 'package:cutdex_ui/theme.dart'; @@ -61,6 +62,11 @@ class BoundedEditorLayout extends StatelessWidget { : context.l10n.expandProperties, maxLines: 1, overflow: TextOverflow.ellipsis, + style: desktop && tool == EditorTool.properties + ? AppTheme.propertiesPanelTheme(Theme.of(context)) + .textTheme + .titleSmall + : null, ), ), ], @@ -103,7 +109,12 @@ class BoundedEditorLayout extends StatelessWidget { right: 0, width: page ? constraints.maxWidth - : math.min(320, constraints.maxWidth), + : math.min( + desktop && tool == EditorTool.properties + ? WorkspaceLayoutMetrics.propertiesPanelWidth + : 320, + constraints.maxWidth, + ), child: Material( key: const Key('editor-tool-surface'), elevation: page ? 0 : 8, diff --git a/lib/features/properties/animation_labels.dart b/lib/features/properties/animation_labels.dart index 6354276..ef3db38 100644 --- a/lib/features/properties/animation_labels.dart +++ b/lib/features/properties/animation_labels.dart @@ -7,6 +7,7 @@ extension TransformChannelLabel on TransformChannel { TransformChannel.position => context.l10n.position, TransformChannel.rotation => context.l10n.rotation, TransformChannel.scale => context.l10n.scale, + TransformChannel.cornerRadius => context.l10n.cornerRadius, }; } diff --git a/lib/features/properties/audio_properties.dart b/lib/features/properties/audio_properties.dart index 2271ad9..d685dbe 100644 --- a/lib/features/properties/audio_properties.dart +++ b/lib/features/properties/audio_properties.dart @@ -169,8 +169,7 @@ class _AudioPropertiesState extends State { if (_text.text != text) _text.text = text; } if (ClipAudioGain.isDetached(record)) { - return Padding( - padding: AppTheme.propertySectionPadding(context), + return AppPropertySection( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -343,15 +342,18 @@ class _AudioPropertiesState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - Padding( - padding: AppTheme.propertySectionPadding(context), + AppPropertySection( child: AppTheme.isDesktop(context) ? AppPropertyGroup( label: widget.hasAudio ? context.l10n.volume : context.l10n.unboundAudio, - actions: volumeActions, - child: volumeControls, + actions: volumeActions.skip(1).toList(), + padChild: false, + child: AppPropertyRow( + trailing: volumeActions.first, + children: [volumeControls], + ), ) : Column( crossAxisAlignment: CrossAxisAlignment.stretch, diff --git a/lib/features/properties/caption_properties.dart b/lib/features/properties/caption_properties.dart index 00fcb1c..6d6e768 100644 --- a/lib/features/properties/caption_properties.dart +++ b/lib/features/properties/caption_properties.dart @@ -196,8 +196,7 @@ class _CaptionPropertiesState extends State { : 28.0; return Column( children: [ - Padding( - padding: AppTheme.propertySectionPadding(context), + AppPropertySection( child: SizedBox( height: AppTheme.propertyInputHeight(context), child: Row( @@ -226,9 +225,13 @@ class _CaptionPropertiesState extends State { vertical: 0, ), prefixIcon: const Icon(AppIcons.search, size: 14), - prefixIconConstraints: const BoxConstraints( - minWidth: 28, - minHeight: 28, + prefixIconConstraints: BoxConstraints( + minWidth: AppTheme.isCompactInspector(context) + ? 24 + : 28, + minHeight: AppTheme.isCompactInspector(context) + ? 24 + : 28, ), ), onChanged: (value) => setState( @@ -448,7 +451,7 @@ class _CaptionPropertiesState extends State { Widget panel(Widget content) => WorkspacePanel( paintBackground: false, headerHeight: AppTheme.isDesktop(context) - ? AppDesktopMetrics.panelHeader + ? AppInspectorMetrics.sectionHeader : CompactPanelTabs.height, headerPadding: EdgeInsets.zero, showHeaderDivider: false, @@ -564,7 +567,9 @@ class _CaptionPropertiesState extends State { key: const ValueKey('caption-detail-scroll-fade'), builder: (controller) => ListView( controller: controller, - padding: const EdgeInsets.symmetric(vertical: AppSpacing.small), + padding: AppTheme.isDesktop(context) + ? EdgeInsets.zero + : const EdgeInsets.symmetric(vertical: AppSpacing.small), children: [ if (AppTheme.isDesktop(context)) @@ -775,16 +780,21 @@ class _CaptionPropertiesState extends State { }, ), ] + .where( + (item) => + !AppTheme.isDesktop(context) || + (item is! SizedBox && item is! Divider), + ) .map( (item) => item is SizedBox || identical(item, widget.transformProperties) ? item + : AppTheme.isDesktop(context) + ? AppPropertySection(child: item) : Padding( - padding: EdgeInsets.symmetric( - horizontal: AppTheme.isDesktop(context) - ? AppInspectorMetrics.padding - : AppSpacing.panelContentHorizontal, + padding: const EdgeInsets.symmetric( + horizontal: AppSpacing.panelContentHorizontal, ), child: item, ), @@ -804,11 +814,13 @@ class _CaptionTextInput extends StatefulWidget { required this.editContext, required this.onSubmit, this.label, + this.leading, this.maxLines = 1, }); final String value; final Object editContext; final String? label; + final Widget? leading; final int maxLines; final bool Function(String) onSubmit; @@ -870,6 +882,7 @@ class _CaptionTextInputState extends State<_CaptionTextInput> { controller: _controller, focusNode: _focus, label: widget.label, + leading: widget.leading, minLines: widget.maxLines, maxLines: widget.maxLines, textInputAction: TextInputAction.done, @@ -901,17 +914,39 @@ class _CaptionColorInput extends StatelessWidget { @override Widget build(BuildContext context) { final desktop = AppTheme.isDesktop(context); + final swatch = Container( + width: desktop ? 14 : 20, + height: desktop ? 14 : 20, + decoration: BoxDecoration( + color: Color(int.parse('FF${value.substring(1)}', radix: 16)), + border: Border.all( + color: desktop + ? Theme.of(context).colorScheme.outlineVariant + : Theme.of(context).colorScheme.outline, + ), + borderRadius: BorderRadius.circular(AppRadius.extraSmall), + ), + ); + if (desktop) { + return AppPropertyGroup( + label: label, + padChild: false, + child: AppPropertyRow( + reserveTrailing: false, + children: [ + _CaptionTextInput( + value: value, + editContext: editContext, + leading: SizedBox(width: 24, child: Center(child: swatch)), + onSubmit: onSubmit, + ), + ], + ), + ); + } final controls = Row( children: [ - Container( - width: 20, - height: 20, - decoration: BoxDecoration( - color: Color(int.parse('FF${value.substring(1)}', radix: 16)), - border: Border.all(color: Theme.of(context).colorScheme.outline), - borderRadius: BorderRadius.circular(AppRadius.extraSmall), - ), - ), + swatch, const SizedBox(width: AppSpacing.small), Expanded( child: _CaptionTextInput( @@ -923,11 +958,6 @@ class _CaptionColorInput extends StatelessWidget { ), ], ); - return desktop - ? AppPropertyGroup( - label: label, - child: Semantics(label: label, child: controls), - ) - : controls; + return controls; } } diff --git a/lib/features/properties/color_interpretation_properties.dart b/lib/features/properties/color_interpretation_properties.dart index bb49e88..12c9026 100644 --- a/lib/features/properties/color_interpretation_properties.dart +++ b/lib/features/properties/color_interpretation_properties.dart @@ -94,8 +94,8 @@ class ColorInterpretationProperties extends ConsumerWidget { ), ], ); - return Padding( - padding: AppTheme.propertySectionPadding(context), + return AppPropertySection( + bottomSpacing: AppTheme.isDesktop(context) ? 0 : null, child: AppTheme.isDesktop(context) ? ExpansionTile( key: PageStorageKey(( @@ -109,9 +109,9 @@ class ColorInterpretationProperties extends ConsumerWidget { ), tilePadding: EdgeInsets.zero, childrenPadding: const EdgeInsets.only( - top: AppInspectorMetrics.rowGap, + bottom: AppInspectorMetrics.groupGap, ), - minTileHeight: AppInspectorMetrics.input, + minTileHeight: AppInspectorMetrics.sectionHeader, dense: true, maintainState: true, initiallyExpanded: selected != null, diff --git a/lib/features/properties/mask_properties.dart b/lib/features/properties/mask_properties.dart index 1046689..9b13fb5 100644 --- a/lib/features/properties/mask_properties.dart +++ b/lib/features/properties/mask_properties.dart @@ -180,7 +180,7 @@ class _MaskPropertiesState extends ConsumerState { } }, child: ListenableSelector( - listenable: preview, + listenable: Listenable.merge([preview, preview.positionChanges]), select: () { final mask = preview.maskFor(widget.element); final animation = preview.maskAnimation(widget.element); @@ -264,10 +264,11 @@ class _MaskPropertiesState extends ConsumerState { }) => PropertyNumberInput( key: ValueKey((selectedId, label)), label: label, - inlineLabel: inlineLabel, - labelActions: AppTheme.isDesktop(context) && !inlineLabel - ? [key(label)] - : const [], + inlineLabel: inlineLabel || AppTheme.isDesktop(context), + prefix: AppTheme.isDesktop(context) && !inlineLabel ? '' : null, + prefixIcon: AppTheme.isDesktop(context) && wrapRotation + ? AppIcons.angle + : null, unit: unit, value: value, enabled: enabled, @@ -338,45 +339,65 @@ class _MaskPropertiesState extends ConsumerState { if (mounted) setState(() => _scrubField = null); }, ); - Widget axes(String label, Widget first, Widget second) => - LayoutBuilder( - builder: (context, constraints) { - final desktop = AppTheme.isDesktop(context); - final gap = AppTheme.propertyRowGap(context); - final pair = constraints.maxWidth < (desktop ? 180 : 240) - ? Column( - children: [ - first, - SizedBox(height: gap), - second, - ], - ) - : Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded(child: first), - SizedBox(width: gap), - Expanded(child: second), - ], - ); - return desktop - ? AppPropertyGroup( - label: label, - actions: [key(label)], - child: pair, - ) - : Row( - children: [ - Expanded(child: pair), - SizedBox(width: gap), - key(label), - ], - ); - }, + Widget axes( + String label, + Widget first, + Widget second, { + Widget? additional, + }) => LayoutBuilder( + builder: (context, constraints) { + final desktop = AppTheme.isDesktop(context); + final gap = AppTheme.propertyRowGap(context); + if (desktop) { + return AppPropertyGroup( + label: label, + padChild: false, + child: Column( + children: [ + AppPropertyRow( + trailing: key(label), + children: [first, second], + ), + ?additional, + ], + ), + ); + } + final pair = constraints.maxWidth < 240 + ? Column( + children: [ + first, + SizedBox(height: gap), + second, + ], + ) + : Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded(child: first), + SizedBox(width: gap), + Expanded(child: second), + ], + ); + return Row( + children: [ + Expanded(child: pair), + SizedBox(width: gap), + key(label), + ], ); + }, + ); Widget singleField(String label, Widget input) => AppTheme.isDesktop(context) - ? input + ? AppPropertyGroup( + label: label, + padChild: false, + child: AppPropertyRow( + trailing: key(label), + children: [input], + ), + ) : Row( children: [ Expanded(child: input), @@ -395,8 +416,7 @@ class _MaskPropertiesState extends ConsumerState { style: AppTheme.propertySectionTitleStyle(context), ), ); - Widget section(List children) => Padding( - padding: AppTheme.propertySectionPadding(context), + Widget section(List children) => AppPropertySection( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: children, @@ -586,8 +606,11 @@ class _MaskPropertiesState extends ConsumerState { if (AppTheme.isDesktop(context)) AppPropertyGroup( label: context.l10n.type, - actions: [shapeReset()], - child: shapeSelector(), + padChild: false, + child: AppPropertyRow( + trailing: shapeReset(), + children: [shapeSelector()], + ), ) else Row( @@ -620,22 +643,40 @@ class _MaskPropertiesState extends ConsumerState { unit: '%', inlineLabel: true, ), + additional: AppTheme.isDesktop(context) + ? AppPropertyRow( + trailing: key(context.l10n.rotation), + children: [ + field( + context.l10n.rotation, + mask.rotation, + -180, + 180, + (v) => mask.copyWith(rotation: v), + unit: '°', + wrapRotation: true, + ), + const SizedBox.shrink(), + ], + ) + : null, ), ]), - section([ - singleField( - context.l10n.rotation, - field( + if (!AppTheme.isDesktop(context)) + section([ + singleField( context.l10n.rotation, - mask.rotation, - -180, - 180, - (v) => mask.copyWith(rotation: v), - unit: '°', - wrapRotation: true, + field( + context.l10n.rotation, + mask.rotation, + -180, + 180, + (v) => mask.copyWith(rotation: v), + unit: '°', + wrapRotation: true, + ), ), - ), - ]), + ]), section([ heading(context.l10n.size), axes( diff --git a/lib/features/properties/picture_edits.dart b/lib/features/properties/picture_edits.dart index 4502d1e..9b0e5e2 100644 --- a/lib/features/properties/picture_edits.dart +++ b/lib/features/properties/picture_edits.dart @@ -100,7 +100,8 @@ class PictureEdits extends _$PictureEdits { value.y == current.y && value.scale == current.scale && value.scaleY == current.scaleY && - value.rotation == current.rotation) { + value.rotation == current.rotation && + value.sameCorners(current)) { return true; } session.commands.setTransform( diff --git a/lib/features/properties/picture_edits.g.dart b/lib/features/properties/picture_edits.g.dart index 7e9755f..3bdb68d 100644 --- a/lib/features/properties/picture_edits.g.dart +++ b/lib/features/properties/picture_edits.g.dart @@ -58,7 +58,7 @@ final class PictureEditsProvider } } -String _$pictureEditsHash() => r'6385f3bd53094d57ed054681d142591e059e8b08'; +String _$pictureEditsHash() => r'5a8ab10fcac9638fb0d98e214744f190fa499434'; final class PictureEditsFamily extends $Family with diff --git a/lib/features/properties/picture_properties.dart b/lib/features/properties/picture_properties.dart index 9287b4c..17c8aa4 100644 --- a/lib/features/properties/picture_properties.dart +++ b/lib/features/properties/picture_properties.dart @@ -22,6 +22,7 @@ import '../../shared/state/operation_scope.dart'; import '../preview/preview_panel.dart'; import 'property_number_input.dart'; import 'picture_edits.dart'; +import 'shadow_properties.dart'; class PictureProperties extends ConsumerStatefulWidget { const PictureProperties({ @@ -57,6 +58,7 @@ class _PicturePropertiesState extends ConsumerState { late final _operations = OperationScope(_operationContext); late final _seeks = OperationScope(_operationContext); bool _locked = true; + bool? _independentCorners; bool _hasFocusedControl = false; PictureEditsProvider get _editProvider => pictureEditsProvider(widget.session, widget.sequence, widget.clip.id); @@ -87,6 +89,7 @@ class _PicturePropertiesState extends ConsumerState { oldWidget.clip.id, ); if (previousIdentity != _editIdentity) { + _independentCorners = null; final edit = _clearScrub(); if (edit != null) scheduleMicrotask(edit.cancel); } @@ -204,7 +207,8 @@ class _PicturePropertiesState extends ConsumerState { value.y == _scrubBase!.y && value.rotation == _scrubBase!.rotation && value.scale == _scrubBase!.scale && - value.scaleY == _scrubBase!.scaleY)) { + value.scaleY == _scrubBase!.scaleY && + value.sameCorners(_scrubBase!))) { _cancelScrub(); return; } @@ -267,6 +271,12 @@ class _PicturePropertiesState extends ConsumerState { value.scale, value.scaleY, value.rotation, + value.cornerRadius, + value.topLeftRadius, + value.topRightRadius, + value.bottomRightRadius, + value.bottomLeftRadius, + _independentCorners, _scrubValid, _scrubBase != null, _saving, @@ -359,36 +369,46 @@ class _PicturePropertiesState extends ConsumerState { final desktop = AppTheme.isDesktop(context); final gap = AppTheme.propertyRowGap(context); - Widget axes(TransformChannel channel, Widget first, Widget second) => - LayoutBuilder( - builder: (context, constraints) { - final pair = constraints.maxWidth < (desktop ? 180 : 240) - ? Column( - children: [ - first, - SizedBox(height: gap), - second, - ], - ) - : Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded(child: first), - SizedBox(width: gap), - Expanded(child: second), - ], - ); - return desktop - ? pair - : Row( - children: [ - Expanded(child: pair), - SizedBox(width: gap), - keyButton(channel), - ], - ); - }, + Widget axes( + TransformChannel channel, + Widget first, + Widget second, { + Widget? trailing, + }) => LayoutBuilder( + builder: (context, constraints) { + if (desktop) { + return AppPropertyRow( + trailing: channel == TransformChannel.position + ? keyButton(channel) + : trailing, + children: [first, second], + ); + } + final pair = constraints.maxWidth < 240 + ? Column( + children: [ + first, + SizedBox(height: gap), + second, + ], + ) + : Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded(child: first), + SizedBox(width: gap), + Expanded(child: second), + ], + ); + return Row( + children: [ + Expanded(child: pair), + SizedBox(width: gap), + keyButton(channel), + ], ); + }, + ); Widget keyTools(TransformChannel channel) { if (animation == null || !animation.animated(channel)) { @@ -488,17 +508,23 @@ class _PicturePropertiesState extends ConsumerState { bool inlineLabel = false, String? prefix, IconData? prefixIcon, + int prefixQuarterTurns = 0, + String? valueText, }) => PropertyNumberInput( key: ValueKey(id), label: label, inlineLabel: inlineLabel, prefix: prefix, prefixIcon: prefixIcon, + prefixQuarterTurns: prefixQuarterTurns, + valueText: valueText, unit: unit, value: value, enabled: !_saving, readOnly: _scrubBase != null || preview?.transforms.hasPending == true, - submit: (v) => _commit(preview, (current) => change(current, v)), + submit: (v) => v < min || v > max + ? Future.value(false) + : _commit(preview, (current) => change(current, v)), onScrubStart: () => _startScrub( preview, id, @@ -520,8 +546,7 @@ class _PicturePropertiesState extends ConsumerState { widget.session.view(widget.sequence).playheadTick, ), ); - Widget section(List children) => Padding( - padding: AppTheme.propertySectionPadding(context), + Widget section(List children) => AppPropertySection( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: children, @@ -555,7 +580,10 @@ class _PicturePropertiesState extends ConsumerState { prefixIcon: desktop ? AppIcons.angle : null, ); final rotation = desktop - ? rotationInput + ? AppPropertyRow( + trailing: keyButton(TransformChannel.rotation), + children: [rotationInput, const SizedBox.shrink()], + ) : Row( children: [ Expanded(child: rotationInput), @@ -563,7 +591,7 @@ class _PicturePropertiesState extends ConsumerState { keyButton(TransformChannel.rotation), ], ); - final scale = axes( + Widget scaleControls({Widget? trailing}) => axes( TransformChannel.scale, number( 'picture-scale-x', @@ -595,6 +623,7 @@ class _PicturePropertiesState extends ConsumerState { : 10000, inlineLabel: true, ), + trailing: trailing, ); final lock = IconButton( key: const Key('picture-lock'), @@ -610,11 +639,10 @@ class _PicturePropertiesState extends ConsumerState { } : null, ); + final scale = scaleControls(); final alignmentControls = LayoutBuilder( - builder: (context, constraints) => Wrap( - spacing: AppSpacing.small, - runSpacing: AppSpacing.small, - children: [ + builder: (context, constraints) { + final groups = [ for (final group in [ [ ( @@ -648,7 +676,9 @@ class _PicturePropertiesState extends ConsumerState { ], ]) SizedBox( - width: constraints.maxWidth < 200 + width: desktop + ? null + : constraints.maxWidth < 200 ? constraints.maxWidth : (constraints.maxWidth - AppSpacing.small) / 2, child: AppButtonGroup( @@ -675,9 +705,89 @@ class _PicturePropertiesState extends ConsumerState { ], ), ), - ], - ), + ]; + if (desktop) return AppPropertyRow(children: groups); + return Wrap( + spacing: AppSpacing.small, + runSpacing: AppSpacing.small, + children: groups, + ); + }, ); + final radiusInput = number( + 'picture-corner-radius', + context.l10n.cornerRadius, + value.topLeftRadius, + (c, v) => c.copyWith(cornerRadius: v), + min: 0, + max: 1000000, + inlineLabel: desktop, + prefix: desktop ? '' : null, + prefixIcon: desktop ? AppIcons.cornerRadius : null, + valueText: value.hasMixedCorners ? '—' : null, + ); + final independent = _independentCorners ?? value.hasMixedCorners; + final cornerToggle = IconButton( + key: const ValueKey('picture-independent-corners'), + tooltip: context.l10n.independentCorners, + icon: const Icon(AppIcons.independentCorners), + isSelected: independent, + onPressed: + enabled && + _scrubBase == null && + preview?.transforms.hasPending != true + ? () => setState(() => _independentCorners = !independent) + : null, + ); + final cornerInputs = [ + number( + 'picture-corner-top-left', + context.l10n.cornerTopLeft, + value.topLeftRadius, + (c, v) => c.copyWith(topLeftRadius: v), + min: 0, + max: 1000000, + inlineLabel: true, + prefix: '', + prefixIcon: Icons.rounded_corner, + prefixQuarterTurns: 3, + ), + number( + 'picture-corner-top-right', + context.l10n.cornerTopRight, + value.topRightRadius, + (c, v) => c.copyWith(topRightRadius: v), + min: 0, + max: 1000000, + inlineLabel: true, + prefix: '', + prefixIcon: Icons.rounded_corner, + ), + number( + 'picture-corner-bottom-left', + context.l10n.cornerBottomLeft, + value.bottomLeftRadius, + (c, v) => c.copyWith(bottomLeftRadius: v), + min: 0, + max: 1000000, + inlineLabel: true, + prefix: '', + prefixIcon: Icons.rounded_corner, + prefixQuarterTurns: 2, + ), + number( + 'picture-corner-bottom-right', + context.l10n.cornerBottomRight, + value.bottomRightRadius, + (c, v) => c.copyWith(bottomRightRadius: v), + min: 0, + max: 1000000, + inlineLabel: true, + prefix: '', + prefixIcon: Icons.rounded_corner, + prefixQuarterTurns: 1, + ), + ]; final content = Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -690,46 +800,43 @@ class _PicturePropertiesState extends ConsumerState { ), ]), ], - if (!widget.animationView) + if (!widget.animationView && !desktop) section([ - if (desktop) - AppPropertyGroup( - label: context.l10n.alignment, - child: alignmentControls, - ) - else ...[ - Text( - context.l10n.alignment, - style: AppTheme.propertySectionTitleStyle(context), - ), - SizedBox(height: gap), - alignmentControls, - ], + Text( + context.l10n.alignment, + style: AppTheme.propertySectionTitleStyle(context), + ), + SizedBox(height: gap), + alignmentControls, ]), if (desktop) ...[ section([ AppPropertyGroup( label: context.l10n.position, - actions: [keyButton(TransformChannel.position)], - child: position, + padChild: false, + child: Column( + children: [ + if (!widget.animationView) alignmentControls, + position, + keyTools(TransformChannel.position), + rotation, + keyTools(TransformChannel.rotation), + ], + ), ), - keyTools(TransformChannel.position), ]), section([ AppPropertyGroup( label: context.l10n.scale, - actions: [lock, keyButton(TransformChannel.scale)], - child: scale, + actions: [keyButton(TransformChannel.scale)], + padChild: false, + child: Column( + children: [ + scaleControls(trailing: lock), + keyTools(TransformChannel.scale), + ], + ), ), - keyTools(TransformChannel.scale), - ]), - section([ - AppPropertyGroup( - label: context.l10n.rotation, - actions: [keyButton(TransformChannel.rotation)], - child: rotation, - ), - keyTools(TransformChannel.rotation), ]), ] else ...[ section([ @@ -759,6 +866,68 @@ class _PicturePropertiesState extends ConsumerState { keyTools(TransformChannel.scale), ]), ], + section([ + if (desktop) + AppPropertyGroup( + label: context.l10n.cornerRadius, + padChild: false, + child: Column( + children: [ + AppPropertyRow( + trailing: keyButton(TransformChannel.cornerRadius), + children: [ + radiusInput, + Align( + alignment: Alignment.centerRight, + child: cornerToggle, + ), + ], + ), + if (independent) ...[ + AppPropertyRow(children: cornerInputs.sublist(0, 2)), + AppPropertyRow(children: cornerInputs.sublist(2, 4)), + ], + keyTools(TransformChannel.cornerRadius), + ], + ), + ) + else ...[ + Row( + children: [ + Expanded(child: radiusInput), + SizedBox(width: gap), + cornerToggle, + keyButton(TransformChannel.cornerRadius), + ], + ), + if (independent) ...[ + SizedBox(height: gap), + Row( + children: [ + Expanded(child: cornerInputs[0]), + SizedBox(width: gap), + Expanded(child: cornerInputs[1]), + ], + ), + SizedBox(height: gap), + Row( + children: [ + Expanded(child: cornerInputs[2]), + SizedBox(width: gap), + Expanded(child: cornerInputs[3]), + ], + ), + ], + keyTools(TransformChannel.cornerRadius), + ], + ]), + ShadowProperties( + projectId: widget.projectId, + timelineId: widget.timelineId, + session: widget.session, + sequence: widget.sequence, + clip: widget.clip.id, + ), if (_error != null) section([ Text( @@ -824,7 +993,22 @@ class _KeyframeTimeline extends StatelessWidget { ], ), const SizedBox(height: AppSpacing.small), - for (final channel in TransformChannel.values) + for (final (id, label, times) in [ + for (final channel in TransformChannel.values) + (channel.name, channel.label(context), animation.keyTimes(channel)), + if (ClipShadowStack( + animation.record, + animation.localTick, + ).layers.isNotEmpty) + ( + 'shadow', + context.l10n.shadow, + ClipShadowStack( + animation.record, + animation.localTick, + ).keyOffsets.map((t) => animation.start + t).toList(), + ), + ]) SizedBox( height: 32, child: Row( @@ -832,7 +1016,7 @@ class _KeyframeTimeline extends StatelessWidget { SizedBox( width: 36, child: Text( - channel.label(context), + label, style: Theme.of(context).textTheme.bodySmall, ), ), @@ -851,7 +1035,7 @@ class _KeyframeTimeline extends StatelessWidget { ) * extent; return GestureDetector( - key: ValueKey('picture-key-track-${channel.name}'), + key: ValueKey('picture-key-track-$id'), behavior: HitTestBehavior.opaque, onTapDown: !enabled ? null @@ -883,18 +1067,16 @@ class _KeyframeTimeline extends StatelessWidget { width: 1, child: ColoredBox(color: colors.primary), ), - for (final tick in animation.keyTimes(channel)) + for (final tick in times) Positioned( left: x(tick) - AppControlSize.compact / 2, top: 4, width: AppControlSize.compact, height: AppControlSize.compact, child: IconButton( - key: ValueKey( - 'picture-key-marker-${channel.name}-$tick', - ), + key: ValueKey('picture-key-marker-$id-$tick'), tooltip: - '${channel.label(context)} ${((tick - animation.start) / TimelineClock.ticksPerSecond).toStringAsFixed(2)} s', + '$label ${((tick - animation.start) / TimelineClock.ticksPerSecond).toStringAsFixed(2)} s', padding: EdgeInsets.zero, onPressed: enabled ? () => onSeek(tick) diff --git a/lib/features/properties/project_properties.dart b/lib/features/properties/project_properties.dart index a648400..f070304 100644 --- a/lib/features/properties/project_properties.dart +++ b/lib/features/properties/project_properties.dart @@ -39,7 +39,9 @@ class ProjectProperties extends StatelessWidget { height: AppTheme.isDesktop(context) ? AppInspectorMetrics.input : null, child: TextButton( key: const ValueKey('project-settings-edit'), - style: AppTheme.isDesktop(context) + style: + AppTheme.isDesktop(context) && + !AppTheme.isCompactInspector(context) ? AppTheme.toolbarButtonStyle(context) : null, onPressed: () => showAppDialog( @@ -50,14 +52,17 @@ class ProjectProperties extends StatelessWidget { ), ), headerHeight: AppTheme.isDesktop(context) - ? AppDesktopMetrics.panelHeader + ? AppInspectorMetrics.sectionHeader : AppControlSize.panelToolbar, - headerPadding: EdgeInsets.symmetric( - horizontal: AppTheme.isDesktop(context) - ? AppInspectorMetrics.padding - : AppSpacing.panelContentHorizontal, - ), - showHeaderDivider: false, + headerPadding: AppTheme.isDesktop(context) + ? const EdgeInsets.only( + left: AppInspectorMetrics.padding, + right: AppInspectorMetrics.trailingPadding, + ) + : const EdgeInsets.symmetric( + horizontal: AppSpacing.panelContentHorizontal, + ), + showHeaderDivider: AppTheme.isCompactInspector(context), child: ScrollEdgeFadeBuilder( builder: (controller) => SingleChildScrollView( controller: controller, @@ -133,8 +138,7 @@ class _Info extends StatelessWidget { style: Theme.of(context).textTheme.bodyMedium, ), ); - return Padding( - padding: AppTheme.propertySectionPadding(context), + return AppPropertySection( child: Row( crossAxisAlignment: CrossAxisAlignment.start, spacing: AppSpacing.small, diff --git a/lib/features/properties/project_property_row.dart b/lib/features/properties/project_property_row.dart index 16bec49..0b406bc 100644 --- a/lib/features/properties/project_property_row.dart +++ b/lib/features/properties/project_property_row.dart @@ -14,9 +14,11 @@ class ProjectPropertyRow extends StatelessWidget { @override Widget build(BuildContext context) => Padding( - padding: const EdgeInsets.symmetric( - horizontal: AppInspectorMetrics.padding, - vertical: AppInspectorMetrics.rowGap, + padding: const EdgeInsets.fromLTRB( + AppInspectorMetrics.padding, + AppInspectorMetrics.rowPadding, + AppInspectorMetrics.trailingPadding, + AppInspectorMetrics.rowPadding, ), child: ConstrainedBox( constraints: const BoxConstraints(minHeight: AppInspectorMetrics.input), @@ -35,13 +37,11 @@ class ProjectPropertyRow extends StatelessWidget { label, maxLines: 3, overflow: TextOverflow.ellipsis, - style: AppTheme.toolbarTextStyle(context).copyWith( - color: Theme.of(context).colorScheme.onSurfaceVariant, - ), + style: AppTheme.propertyLabelStyle(context), ), ), ), - const SizedBox(width: AppInspectorMetrics.rowGap * 2), + const SizedBox(width: AppInspectorMetrics.rowGap), Expanded( flex: 3, child: Tooltip( @@ -51,7 +51,7 @@ class ProjectPropertyRow extends StatelessWidget { maxLines: 3, overflow: TextOverflow.ellipsis, textAlign: TextAlign.right, - style: AppTheme.toolbarTextStyle(context), + style: AppTheme.inputTextStyle(context), ), ), ), diff --git a/lib/features/properties/project_property_row_previews.dart b/lib/features/properties/project_property_row_previews.dart index ae76368..7531622 100644 --- a/lib/features/properties/project_property_row_previews.dart +++ b/lib/features/properties/project_property_row_previews.dart @@ -20,8 +20,10 @@ Widget lightProjectSummaryPreview() => _preview(Brightness.light); Widget _preview(Brightness brightness) => MaterialApp( debugShowCheckedModeBanner: false, - theme: AppTheme.desktopWorkspaceTheme( - AppTheme.forPalette(AppPalette.graphite, brightness), + theme: AppTheme.propertiesPanelTheme( + AppTheme.desktopWorkspaceTheme( + AppTheme.forPalette(AppPalette.graphite, brightness), + ), ), home: const Scaffold( body: SingleChildScrollView( diff --git a/lib/features/properties/properties_panel.dart b/lib/features/properties/properties_panel.dart index 9bbbec4..4e6188e 100644 --- a/lib/features/properties/properties_panel.dart +++ b/lib/features/properties/properties_panel.dart @@ -20,7 +20,7 @@ class EditorPropertiesPanel extends StatelessWidget { projectId: projectId, timelineId: timelineId, categoryHeaderHeight: AppTheme.isDesktop(context) - ? AppDesktopMetrics.panelHeader + ? AppInspectorMetrics.sectionHeader : CompactPanelTabs.height, categoryControls: (context, categories, selected, onSelected) => CompactPanelTabs( diff --git a/lib/features/properties/property_number_input.dart b/lib/features/properties/property_number_input.dart index 8154290..4055f25 100644 --- a/lib/features/properties/property_number_input.dart +++ b/lib/features/properties/property_number_input.dart @@ -19,6 +19,8 @@ class PropertyNumberInput extends StatefulWidget { this.inlineLabel = false, this.prefix, this.prefixIcon, + this.prefixQuarterTurns = 0, + this.valueText, this.labelActions = const [], this.decimalPlaces = 2, this.onScrubStart, @@ -33,6 +35,8 @@ class PropertyNumberInput extends StatefulWidget { final bool inlineLabel; final String? prefix; final IconData? prefixIcon; + final int prefixQuarterTurns; + final String? valueText; final List labelActions; final int decimalPlaces; final bool Function()? onScrubStart; @@ -50,11 +54,12 @@ class PropertyNumberInput extends StatefulWidget { } class _PropertyNumberInputState extends State { - late final _text = TextEditingController(text: _format(widget.value)); + late final _text = TextEditingController(text: _displayValue); final _focus = FocusNode(); bool _dirty = false; late final _operations = OperationScope(widget.editContext); String? _error; + String get _displayValue => widget.valueText ?? _format(widget.value); String _format(double value) { var text = value.toStringAsFixed(widget.decimalPlaces); if (text.contains('.')) text = text.replaceFirst(RegExp(r'\.?0+$'), ''); @@ -84,7 +89,7 @@ class _PropertyNumberInputState extends State { if (!mounted || !isCurrent()) return; setState(() { _error = accepted ? null : context.l10n.notApplied; - _text.text = _format(widget.value); + _text.text = _displayValue; }); } @@ -98,7 +103,7 @@ class _PropertyNumberInputState extends State { _dirty = false; _error = null; } - final text = _format(widget.value); + final text = _displayValue; // A no-op assignment still resets selection and asks EditableText to // reveal its caret, competing with the user's scroll on preview updates. if (!_dirty && _text.text != text) _text.text = text; @@ -115,8 +120,8 @@ class _PropertyNumberInputState extends State { @override Widget build(BuildContext context) { - final labelAbove = - AppTheme.isCompactInspector(context) && !widget.inlineLabel; + final compact = AppTheme.isCompactInspector(context); + final labelAbove = compact && !widget.inlineLabel; final label = widget.onScrubStart == null ? Text(widget.label ?? '', style: AppTheme.propertyLabelStyle(context)) : AppScrubLabel( @@ -126,7 +131,7 @@ class _PropertyNumberInputState extends State { ? AppTheme.propertySectionTitleStyle(context) : null, alignment: labelAbove ? Alignment.centerLeft : Alignment.center, - padding: labelAbove + padding: labelAbove || compact ? EdgeInsets.zero : const EdgeInsets.symmetric(horizontal: AppSpacing.small), enabled: widget.enabled && (!widget.readOnly || widget.scrubbing), @@ -134,7 +139,7 @@ class _PropertyNumberInputState extends State { _operations.invalidate(); _dirty = false; _error = null; - _text.text = _format(widget.value); + _text.text = _displayValue; return widget.onScrubStart!(); }, onUpdate: widget.onScrubUpdate, @@ -154,7 +159,17 @@ class _PropertyNumberInputState extends State { label: widget.label, labelAbove: labelAbove, labelActions: widget.labelActions, - leading: widget.onScrubStart == null ? null : label, + leading: widget.onScrubStart == null + ? null + : compact && !labelAbove + ? SizedBox( + width: AppInspectorMetrics.action, + child: RotatedBox( + quarterTurns: widget.prefixQuarterTurns, + child: label, + ), + ) + : label, unit: widget.unit, errorText: _error, onChanged: (_) { @@ -173,7 +188,7 @@ class _PropertyNumberInputState extends State { _operations.invalidate(); _dirty = false; _error = null; - _text.text = _format(widget.value); + _text.text = _displayValue; }); _focus.unfocus(); return KeyEventResult.handled; diff --git a/lib/features/properties/shadow_properties.dart b/lib/features/properties/shadow_properties.dart new file mode 100644 index 0000000..eae4ae7 --- /dev/null +++ b/lib/features/properties/shadow_properties.dart @@ -0,0 +1,1070 @@ +import 'dart:math' as math; + +import 'package:cutdex/l10n/l10n.dart'; +import 'package:cutdex_sdk/editor.dart'; +import 'package:cutdex_sdk/preview.dart'; +import 'package:cutdex_sdk/timeline/model.dart'; +import 'package:cutdex_ui/icons.dart'; +import 'package:cutdex_ui/theme.dart'; +import 'package:cutdex_ui/widgets.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../../workspace/timeline_session.dart'; +import '../../shared/state/operation_scope.dart'; +import '../preview/preview_panel.dart'; +import 'property_number_input.dart'; + +class ShadowProperties extends ConsumerStatefulWidget { + const ShadowProperties({ + super.key, + required this.projectId, + required this.timelineId, + required this.session, + required this.sequence, + required this.clip, + }); + final String projectId, timelineId; + final EditorTimelineSession session; + final SequenceId sequence; + final ElementId clip; + @override + ConsumerState createState() => _ShadowPropertiesState(); +} + +class _ShadowPropertiesState extends ConsumerState { + Object get _identity => ( + widget.session, + widget.sequence, + widget.clip, + widget.projectId, + widget.timelineId, + ); + late final _operations = OperationScope(_identity); + bool _saving = false; + String? _error; + @override + void didUpdateWidget(covariant ShadowProperties oldWidget) { + super.didUpdateWidget(oldWidget); + _operations.bind(_identity); + if (oldWidget.session != widget.session || + oldWidget.sequence != widget.sequence || + oldWidget.clip != widget.clip) { + _saving = false; + _error = null; + } + } + + @override + void dispose() { + _operations.dispose(); + super.dispose(); + } + + ({ClipShadowStack stack, int start})? _current() { + final view = widget.session.view(widget.sequence); + final query = view.version.kernelVersion.query(); + final handle = query.elementById(widget.clip); + if (handle == null) return null; + final start = query.absoluteStart(handle); + return ( + stack: ClipShadowStack(query.element(handle), view.playheadTick - start), + start: start, + ); + } + + Future _edit( + PreviewController? preview, + void Function(EditorCommandService commands, int tick) action, { + bool seek = false, + }) async { + if (_saving || + preview?.transforms.hasPending == true || + widget.session.activeSequenceId != widget.sequence) { + return false; + } + final guard = _operations.begin(); + final session = widget.session; + final sequence = widget.sequence; + final view = session.view(sequence); + final version = view.version.kernelVersion; + final tick = view.playheadTick; + setState(() { + _saving = true; + _error = null; + }); + try { + await preview?.pauseForCanvasInteraction(); + if (!mounted || + !guard() || + view.playheadTick != tick || + !identical(view.version.kernelVersion, version) || + session.activeSequenceId != sequence) { + return false; + } + if (seek) { + action(session.commands, tick); + } else { + session.runEdit( + 'editShadow', + sequence, + () => action(session.commands, tick), + context: { + 'clipIds': [widget.clip.value], + 'entryPoint': 'property', + 'playheadTick': tick, + }, + ); + } + return true; + } catch (_) { + if (mounted && guard()) { + setState(() => _error = context.l10n.updateShadowFailed); + } + return false; + } finally { + if (mounted && guard()) setState(() => _saving = false); + } + } + + @override + Widget build(BuildContext context) { + final preview = ref + .watch(editorPreviewProvider(widget.projectId, widget.timelineId)) + .asData + ?.value; + return ListenableBuilder( + listenable: widget.session.view(widget.sequence), + builder: (context, _) { + final current = _current(); + if (current == null) return const SizedBox.shrink(); + final stack = current.stack; + final layers = stack.layers; + final enabled = + !_saving && + stack.containsPlayhead && + preview?.transforms.hasPending != true; + Future edit(void Function(EditorCommandService, int) action) => + _edit(preview, action); + Future keys({ + KeyframeAction? action, + ParameterInterpolation? interpolation, + }) => edit( + (c, t) => c.editKeyframeChannel( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + parameterIds: stack.parameterIds, + action: action, + interpolation: interpolation, + ), + ); + Widget key = IconButton( + key: const ValueKey('shadow-key'), + tooltip: context.l10n.toggleKeyframe( + stack.keyed ? context.l10n.delete : context.l10n.addKeyframeAction, + context.l10n.shadow, + ), + isSelected: stack.keyed, + color: stack.animated ? Theme.of(context).colorScheme.primary : null, + icon: Transform.rotate( + angle: math.pi / 4, + child: Icon( + stack.keyed ? AppIcons.squareFilled : AppIcons.square, + size: 12, + ), + ), + onPressed: enabled && layers.isNotEmpty ? keys : null, + ); + Widget number( + ClipShadowLayer layer, + String field, + String? label, + double value, + ClipShadow Function(ClipShadow, double) change, { + double factor = 1, + String? unit, + bool inlineLabel = true, + }) { + final (minimum, maximum) = ClipShadow.range(field); + return PropertyNumberInput( + key: ValueKey('shadow-${layer.id}-$field'), + label: label, + inlineLabel: inlineLabel, + unit: unit, + value: value * factor, + enabled: enabled && layer.enabled, + readOnly: false, + scrubbing: false, + editContext: (_identity, layer.id), + onScrubUpdate: (_) {}, + onScrubEnd: () {}, + onScrubCancel: () {}, + submit: (v) => + !v.isFinite || v / factor < minimum || v / factor > maximum + ? Future.value(false) + : edit((c, t) { + final live = _current()!.stack.layers.firstWhere( + (l) => l.id == layer.id, + ); + c.setShadow( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + shadowId: layer.id, + value: change(live.shadow, v / factor), + ); + }), + ); + } + + final times = stack.keyOffsets.map((t) => t + current.start).toList(); + final tick = widget.session.view(widget.sequence).playheadTick; + final previous = times.where((t) => t < tick).lastOrNull; + final next = times.where((t) => t > tick).firstOrNull; + Widget seekButton(int? target, bool forward) => IconButton( + key: ValueKey('shadow-key-${forward ? 'next' : 'previous'}'), + tooltip: forward + ? context.l10n.nextKeyframe(context.l10n.shadow) + : context.l10n.previousKeyframe(context.l10n.shadow), + icon: Icon( + forward ? AppIcons.chevronRight : AppIcons.chevronLeft, + size: 16, + ), + onPressed: enabled && target != null + ? () => _edit( + preview, + (_, _) => widget.session.view(widget.sequence).seekTo(target), + seek: true, + ) + : null, + ); + return AppPropertySection( + bottomSpacing: layers.isEmpty ? 0 : null, + child: AppPropertyGroup( + label: context.l10n.shadow, + labelWidget: layers.isEmpty + ? Text( + context.l10n.shadow, + style: AppTheme.propertyLabelStyle(context), + ) + : null, + padChild: false, + actions: [ + key, + IconButton( + key: const ValueKey('shadow-add'), + tooltip: context.l10n.addShadow, + icon: const Icon(AppIcons.add, size: 16), + onPressed: enabled && layers.length < ClipShadowStack.maxLayers + ? () => edit( + (c, t) => c.addShadow( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + shadowId: c.newShadowId(), + ), + ) + : null, + ), + ], + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (stack.animated) + Row( + children: [ + Text( + context.l10n.keyframeCount(times.length), + style: Theme.of(context).textTheme.bodySmall, + ), + const Spacer(), + seekButton(previous, false), + seekButton(next, true), + AppDropdownMenu( + enabled: enabled, + builder: (context, toggle, focus) => IconButton( + focusNode: focus, + tooltip: context.l10n.keyframeSettings( + context.l10n.shadow, + ), + onPressed: toggle, + icon: const Icon(AppIcons.more, size: 16), + ), + items: [ + for (final (mode, label) in [ + ( + ParameterInterpolation.linear, + context.l10n.linear, + ), + (ParameterInterpolation.hold, context.l10n.hold), + ( + ParameterInterpolation.easeIn, + context.l10n.easeIn, + ), + ( + ParameterInterpolation.easeOut, + context.l10n.easeOut, + ), + ( + ParameterInterpolation.easeInOut, + context.l10n.easeInOut, + ), + ]) + AppMenuItem( + label: label, + onPressed: stack.keyed + ? () => keys( + action: KeyframeAction.set, + interpolation: mode, + ) + : null, + ), + AppMenuItem( + label: context.l10n.removeAllKeyframes, + onPressed: () => keys(action: KeyframeAction.clear), + ), + ], + ), + ], + ), + ReorderableListView( + shrinkWrap: true, + primary: false, + padding: EdgeInsets.zero, + physics: const NeverScrollableScrollPhysics(), + buildDefaultDragHandles: false, + onReorderItem: (oldIndex, newIndex) { + if (!enabled) return; + final ids = layers.map((l) => l.id).toList(); + ids.insert(newIndex, ids.removeAt(oldIndex)); + edit( + (c, t) => c.configureShadows( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + order: ids, + ), + ); + }, + proxyDecorator: (child, index, animation) => Material( + color: Theme.of(context).colorScheme.surfaceContainerLow, + child: child, + ), + children: [ + for (var i = 0; i < layers.length; i++) + Builder( + key: ValueKey((_identity, layers[i].id)), + builder: (context) { + final layer = layers[i]; + final s = layer.shadow; + final color = Color.from( + alpha: 1, + red: s.red, + green: s.green, + blue: s.blue, + ); + final hex = [s.red, s.green, s.blue] + .map( + (v) => (v * 255) + .round() + .toRadixString(16) + .padLeft(2, '0'), + ) + .join() + .toUpperCase(); + void reorder(int direction) { + final ids = layers.map((l) => l.id).toList(); + final other = i + direction; + final temp = ids[i]; + ids[i] = ids[other]; + ids[other] = temp; + edit( + (c, t) => c.configureShadows( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + order: ids, + ), + ); + } + + return _ShadowLayerRow( + key: ValueKey('shadow-layer-${layer.id}'), + id: layer.id, + index: i, + enabled: enabled, + visible: layer.enabled, + label: context.l10n.shadow, + tooltip: context.l10n.shadowLayer(i + 1), + onVisibility: () => edit( + (c, t) => c.configureShadows( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + shadowId: layer.id, + enabled: !layer.enabled, + ), + ), + onRemove: () => edit( + (c, t) => c.removeShadow( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + shadowId: layer.id, + ), + ), + menuItems: [ + AppMenuItem( + label: context.l10n.moveShadowUp, + onPressed: enabled && i > 0 + ? () => reorder(-1) + : null, + ), + AppMenuItem( + label: context.l10n.moveShadowDown, + onPressed: enabled && i < layers.length - 1 + ? () => reorder(1) + : null, + ), + ], + editor: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + context.l10n.position, + style: AppTheme.propertyLabelStyle(context), + ), + AppPropertyRow( + reserveTrailing: false, + children: [ + number( + layer, + 'x', + 'X', + s.x, + (s, v) => s.copyWith(x: v), + ), + number( + layer, + 'y', + 'Y', + s.y, + (s, v) => s.copyWith(y: v), + ), + ], + ), + const SizedBox(height: 4), + AppPropertyRow( + reserveTrailing: false, + children: [ + number( + layer, + 'blur', + context.l10n.shadowBlur, + s.blur, + (s, v) => s.copyWith(blur: v), + inlineLabel: false, + ), + number( + layer, + 'spread', + context.l10n.shadowSpread, + s.spread, + (s, v) => s.copyWith(spread: v), + inlineLabel: false, + ), + ], + ), + const SizedBox( + height: AppInspectorMetrics.rowGap, + ), + Text( + context.l10n.color, + style: AppTheme.propertyLabelStyle(context), + ), + AppPropertyRow( + reserveTrailing: false, + flexes: const [2, 1], + children: [ + _ShadowColorInput( + key: ValueKey('shadow-${layer.id}-color'), + value: hex, + color: color, + enabled: enabled && layer.enabled, + editContext: (_identity, layer.id), + submit: (v) => edit((c, t) { + final live = _current()!.stack.layers + .firstWhere((l) => l.id == layer.id) + .shadow; + c.setShadow( + sequence: widget.sequence, + clip: widget.clip, + tick: t, + shadowId: layer.id, + value: live.copyWith( + red: ((v >> 16) & 255) / 255, + green: ((v >> 8) & 255) / 255, + blue: (v & 255) / 255, + ), + ); + }), + ), + number( + layer, + 'opacity', + null, + s.opacity, + (s, v) => s.copyWith(opacity: v), + factor: 100, + unit: '%', + ), + ], + ), + ], + ), + ); + }, + ), + ], + ), + if (_error != null) + Text( + _error!, + style: TextStyle( + color: Theme.of(context).colorScheme.error, + ), + ), + ], + ), + ), + ); + }, + ); + } +} + +class _ShadowLayerRow extends StatefulWidget { + const _ShadowLayerRow({ + super.key, + required this.id, + required this.index, + required this.enabled, + required this.visible, + required this.label, + required this.tooltip, + required this.onVisibility, + required this.onRemove, + required this.menuItems, + required this.editor, + }); + final String id, label, tooltip; + final int index; + final bool enabled, visible; + final VoidCallback onVisibility, onRemove; + final List menuItems; + final Widget editor; + + @override + State<_ShadowLayerRow> createState() => _ShadowLayerRowState(); +} + +class _ShadowLayerRowState extends State<_ShadowLayerRow> { + final _menu = MenuController(); + final _focus = FocusNode(); + bool _hovered = false; + + @override + void dispose() { + _focus.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final colors = theme.colorScheme; + return MenuAnchor( + controller: _menu, + childFocusNode: _focus, + clipBehavior: Clip.none, + // Place the editor beside the inspector, as in Figma's effects panel. + alignmentOffset: Offset( + -240 - 8 - AppTheme.propertySectionPadding(context).left, + 0, + ), + style: const MenuStyle( + alignment: AlignmentDirectional.topStart, + padding: WidgetStatePropertyAll(EdgeInsets.zero), + backgroundColor: WidgetStatePropertyAll(Colors.transparent), + surfaceTintColor: WidgetStatePropertyAll(Colors.transparent), + elevation: WidgetStatePropertyAll(0), + side: WidgetStatePropertyAll(BorderSide.none), + shape: WidgetStatePropertyAll( + RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(8)), + ), + ), + ), + onOpen: () => setState(() {}), + onClose: () => setState(() {}), + menuChildren: [ + SizedBox( + key: ValueKey('shadow-editor-${widget.id}'), + width: 240, + child: Material( + color: colors.surfaceContainerLow, + surfaceTintColor: Colors.transparent, + elevation: 8, + shadowColor: colors.shadow.withValues(alpha: .25), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide(color: colors.outlineVariant), + ), + clipBehavior: Clip.antiAlias, + child: Focus( + autofocus: true, + onKeyEvent: (_, event) { + if (event is KeyDownEvent && + event.logicalKey == LogicalKeyboardKey.escape) { + _menu.close(); + return KeyEventResult.handled; + } + return KeyEventResult.ignored; + }, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 40, + child: Padding( + padding: const EdgeInsets.only(left: 16, right: 8), + child: Row( + children: [ + Expanded( + child: Text( + widget.label, + style: AppTheme.propertySectionTitleStyle( + context, + ), + ), + ), + AppDropdownMenu( + builder: (context, toggle, focus) => IconButton( + focusNode: focus, + tooltip: widget.tooltip, + icon: const Icon(AppIcons.more, size: 16), + onPressed: toggle, + ), + items: widget.menuItems, + ), + IconButton( + key: ValueKey('shadow-editor-close-${widget.id}'), + tooltip: context.l10n.close, + icon: const Icon(AppIcons.close, size: 16), + onPressed: _menu.close, + ), + ], + ), + ), + ), + Divider(height: 1, color: theme.dividerColor), + Padding( + padding: const EdgeInsets.fromLTRB(16, 12, 16, 12), + child: widget.editor, + ), + ], + ), + ), + ), + ), + ], + builder: (context, controller, child) => MouseRegion( + onEnter: (_) => setState(() => _hovered = true), + onExit: (_) => setState(() => _hovered = false), + child: SizedBox( + height: AppInspectorMetrics.row, + child: Row( + children: [ + ReorderableDragStartListener( + key: ValueKey('shadow-drag-${widget.id}'), + index: widget.index, + enabled: widget.enabled, + child: MouseRegion( + cursor: widget.enabled + ? SystemMouseCursors.grab + : SystemMouseCursors.basic, + child: SizedBox( + width: 16, + child: Icon( + AppIcons.dragHandle, + size: 12, + color: _hovered + ? colors.onSurfaceVariant + : Colors.transparent, + ), + ), + ), + ), + Expanded( + child: TextButton( + key: ValueKey('shadow-settings-${widget.id}'), + focusNode: _focus, + style: TextButton.styleFrom( + padding: const EdgeInsets.symmetric(horizontal: 4), + minimumSize: const Size(0, 24), + maximumSize: const Size(double.infinity, 24), + backgroundColor: controller.isOpen + ? theme.inputDecorationTheme.fillColor + : null, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5), + ), + foregroundColor: widget.visible + ? colors.onSurface + : colors.onSurfaceVariant, + textStyle: AppTheme.inputTextStyle(context), + ), + onPressed: () => controller.isOpen + ? controller.close() + : controller.open(), + child: Row( + children: [ + const Icon(PhosphorIconsRegular.sun, size: 16), + const SizedBox(width: 8), + Expanded( + child: Text( + widget.label, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + ), + ), + IconButton( + key: ValueKey('shadow-enabled-${widget.id}'), + tooltip: widget.visible + ? context.l10n.disable + : context.l10n.enable, + icon: Icon( + widget.visible + ? Icons.visibility_outlined + : Icons.visibility_off_outlined, + size: 16, + ), + onPressed: widget.enabled ? widget.onVisibility : null, + ), + IconButton( + key: ValueKey('shadow-remove-${widget.id}'), + tooltip: context.l10n.delete, + icon: const Icon(AppIcons.remove, size: 16), + onPressed: widget.enabled ? widget.onRemove : null, + ), + ], + ), + ), + ), + ); + } +} + +class _ShadowColorInput extends StatefulWidget { + const _ShadowColorInput({ + super.key, + required this.value, + required this.color, + required this.enabled, + required this.editContext, + required this.submit, + }); + final String value; + final Color color; + final bool enabled; + final Object editContext; + final Future Function(int) submit; + @override + State<_ShadowColorInput> createState() => _ShadowColorInputState(); +} + +class _ShadowColorInputState extends State<_ShadowColorInput> { + late final _text = TextEditingController(text: widget.value); + final _focus = FocusNode(); + bool _dirty = false; + String? _error; + late final _operations = OperationScope(widget.editContext); + @override + void initState() { + super.initState(); + _focus.addListener(_blur); + } + + void _blur() { + if (!_focus.hasFocus) _submit(); + } + + Future _submit() async { + if (!_dirty || !widget.enabled) return; + final value = _text.text.replaceFirst('#', ''); + if (!RegExp(r'^[A-Fa-f0-9]{6}$').hasMatch(value)) { + setState(() => _error = context.l10n.invalidNumber); + return; + } + _dirty = false; + final guard = _operations.begin(); + final ok = await widget.submit(int.parse(value, radix: 16)); + if (!mounted || !guard()) return; + setState(() { + _error = ok ? null : context.l10n.notApplied; + _text.text = widget.value; + }); + } + + @override + void didUpdateWidget(covariant _ShadowColorInput oldWidget) { + super.didUpdateWidget(oldWidget); + _operations.bind(widget.editContext); + if (oldWidget.editContext != widget.editContext || !widget.enabled) { + _dirty = false; + _error = null; + } + if (!_dirty && _text.text != widget.value) _text.text = widget.value; + } + + @override + void dispose() { + _operations.dispose(); + _focus.removeListener(_blur); + _focus.dispose(); + _text.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => AppTextField( + controller: _text, + focusNode: _focus, + enabled: widget.enabled, + errorText: _error, + leading: AppPopover( + width: 240, + borderRadius: 8, + padding: const EdgeInsets.all(16), + backgroundColor: Theme.of(context).colorScheme.surfaceContainerLow, + builder: (context, toggle) => IconButton( + key: const ValueKey('shadow-color-swatch'), + tooltip: context.l10n.color, + onPressed: widget.enabled ? toggle : null, + padding: EdgeInsets.zero, + icon: Container( + width: 14, + height: 14, + decoration: BoxDecoration( + color: widget.color, + borderRadius: BorderRadius.circular(2), + border: Border.all( + color: Theme.of(context).colorScheme.outlineVariant, + ), + ), + ), + ), + child: _ShadowColorPicker( + color: widget.color, + enabled: widget.enabled, + submit: (color) => widget.submit(color.toARGB32() & 0xFFFFFF), + ), + ), + onChanged: (_) { + _operations.invalidate(); + _dirty = true; + if (_error != null) setState(() => _error = null); + }, + onEditingComplete: () {}, + onSubmitted: (_) => _submit(), + ); +} + +class _ShadowColorPicker extends StatefulWidget { + const _ShadowColorPicker({ + required this.color, + required this.enabled, + required this.submit, + }); + final Color color; + final bool enabled; + final Future Function(Color) submit; + + @override + State<_ShadowColorPicker> createState() => _ShadowColorPickerState(); +} + +class _ShadowColorPickerState extends State<_ShadowColorPicker> { + late HSVColor _color = HSVColor.fromColor(widget.color); + + @override + void didUpdateWidget(covariant _ShadowColorPicker oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.color != oldWidget.color) { + _color = HSVColor.fromColor(widget.color); + } + } + + Future _commit() async { + if (!widget.enabled) return; + await widget.submit(_color.toColor()); + if (mounted) setState(() => _color = HSVColor.fromColor(widget.color)); + } + + @override + Widget build(BuildContext context) => Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + context.l10n.color, + style: AppTheme.propertySectionTitleStyle(context), + ), + const SizedBox(height: 12), + SizedBox( + height: 140, + child: LayoutBuilder( + builder: (context, constraints) { + final width = constraints.maxWidth; + const height = 140.0; + void update(Offset position) { + if (!widget.enabled) return; + setState( + () => _color = _color + .withSaturation((position.dx / width).clamp(0, 1)) + .withValue((1 - position.dy / height).clamp(0, 1)), + ); + } + + return Semantics( + label: context.l10n.color, + child: GestureDetector( + key: const ValueKey('shadow-color-plane'), + onTapDown: (details) => update(details.localPosition), + onTapUp: (_) => _commit(), + onPanStart: (details) => update(details.localPosition), + onPanUpdate: (details) => update(details.localPosition), + onPanEnd: (_) => _commit(), + child: ClipRRect( + borderRadius: BorderRadius.circular(5), + child: SizedBox( + height: height, + child: Stack( + children: [ + Positioned.fill( + child: ColoredBox( + color: HSVColor.fromAHSV( + 1, + _color.hue, + 1, + 1, + ).toColor(), + ), + ), + const Positioned.fill( + child: DecoratedBox( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [Colors.white, Color(0x00FFFFFF)], + ), + ), + ), + ), + const Positioned.fill( + child: DecoratedBox( + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [Colors.transparent, Colors.black], + ), + ), + ), + ), + Positioned( + left: (_color.saturation * width - 6).clamp( + 0, + width - 12, + ), + top: ((1 - _color.value) * height - 6).clamp( + 0, + height - 12, + ), + child: Container( + width: 12, + height: 12, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all(color: Colors.white, width: 2), + boxShadow: const [ + BoxShadow(color: Colors.black54, blurRadius: 2), + ], + ), + ), + ), + ], + ), + ), + ), + ), + ); + }, + ), + ), + const SizedBox(height: 8), + SizedBox( + height: 24, + child: Stack( + alignment: Alignment.center, + children: [ + Container( + height: 12, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(6), + gradient: const LinearGradient( + colors: [ + Color(0xFFFF0000), + Color(0xFFFFFF00), + Color(0xFF00FF00), + Color(0xFF00FFFF), + Color(0xFF0000FF), + Color(0xFFFF00FF), + Color(0xFFFF0000), + ], + ), + ), + ), + SliderTheme( + data: SliderTheme.of(context).copyWith( + padding: EdgeInsets.zero, + trackHeight: 12, + activeTrackColor: Colors.transparent, + inactiveTrackColor: Colors.transparent, + thumbColor: Colors.white, + thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 6), + overlayShape: SliderComponentShape.noOverlay, + ), + child: Slider( + key: const ValueKey('shadow-color-hue'), + min: 0, + max: 360, + value: _color.hue, + onChanged: widget.enabled + ? (hue) => setState(() => _color = _color.withHue(hue)) + : null, + onChangeEnd: (_) => _commit(), + ), + ), + ], + ), + ), + ], + ); +} diff --git a/lib/features/properties/speed_properties.dart b/lib/features/properties/speed_properties.dart index 8ca0484..a5a30c1 100644 --- a/lib/features/properties/speed_properties.dart +++ b/lib/features/properties/speed_properties.dart @@ -204,15 +204,14 @@ class _SpeedPropertiesState extends State { _version == null || identical(_version, view.version.kernelVersion) ? _timeline ?? saved ?? 1 : saved ?? 1; - return Padding( - padding: AppTheme.propertySectionPadding(context), + return AppPropertySection( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ConstrainedBox( constraints: BoxConstraints( minHeight: AppTheme.isDesktop(context) - ? AppInspectorMetrics.action + ? AppInspectorMetrics.sectionHeader : AppControlSize.propertyControl, ), child: Row( diff --git a/test/caption_edit_context_test.dart b/test/caption_edit_context_test.dart index 24df7c6..922d8e0 100644 --- a/test/caption_edit_context_test.dart +++ b/test/caption_edit_context_test.dart @@ -4,6 +4,7 @@ import 'package:cutdex/l10n/app_localizations.dart'; import 'package:cutdex/workspace/timeline_session.dart'; import 'package:cutdex_sdk/editor.dart'; import 'package:cutdex_sdk/timeline/model.dart'; +import 'package:cutdex_ui/theme.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -145,7 +146,7 @@ Widget _host( localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, theme: desktop - ? EditorTheme.desktop(EditorTheme.penDark) + ? AppTheme.propertiesPanelTheme(EditorTheme.desktop(EditorTheme.penDark)) : EditorTheme.penDark, home: Scaffold( body: CaptionProperties(session: session, sequence: _sequence, clipId: id), diff --git a/test/compact_inspector_test.dart b/test/compact_inspector_test.dart index 42b132b..f537bb5 100644 --- a/test/compact_inspector_test.dart +++ b/test/compact_inspector_test.dart @@ -1,4 +1,7 @@ import 'package:cutdex/app/editor_theme.dart'; +import 'package:cutdex/features/editor/layouts/bounded_editor_layout.dart'; +import 'package:cutdex/features/editor/editor_presentation_controller.dart'; +import 'package:cutdex/integrations/platform/device_experience.dart'; import 'package:cutdex/features/preview/preview_panel.dart'; import 'package:cutdex/features/properties/picture_properties.dart'; import 'package:cutdex/features/properties/audio_properties.dart'; @@ -15,6 +18,50 @@ import 'package:flutter_test/flutter_test.dart'; import 'support/preview_fixture.dart'; void main() { + testWidgets( + 'floating desktop inspector keeps the UI3 width in narrow windows', + (tester) async { + for (final width in [200.0, 320.0, 800.0]) { + await tester.pumpWidget( + MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + locale: const Locale('en'), + theme: EditorTheme.desktop(EditorTheme.penDark), + home: Scaffold( + body: Align( + alignment: Alignment.topRight, + child: SizedBox( + width: width, + height: 400, + child: BoundedEditorLayout( + experience: DeviceExperience.desktop, + editing: const SizedBox.expand(), + tool: EditorTool.properties, + media: const SizedBox.expand(), + properties: const SizedBox.expand(), + onCloseTool: () {}, + ), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + expect( + tester.getSize(find.byKey(const Key('editor-tool-surface'))).width, + width < 240 ? width : 240, + ); + final title = tester.widget( + find.byWidgetPredicate((w) => w is Text && w.style?.fontSize == 13), + ); + expect(title.style!.fontSize, 13); + expect(title.style!.height, 22 / 13); + expect(tester.takeException(), isNull); + } + }, + ); + testWidgets( 'audio and speed controls fit desktop group headers at narrow widths', (tester) async { @@ -74,10 +121,10 @@ void main() { of: find.byKey(const Key('audio-db')), matching: find.byType(TextField), ); - expect(tester.getSize(field).height, 28); + expect(tester.getSize(field).height, 24); expect( - tester.getRect(find.byKey(const Key('audio-key'))).bottom, - tester.getRect(field).top - 4, + tester.getRect(find.byKey(const Key('audio-key'))).center.dy, + tester.getRect(field).center.dy, ); expect(find.byType(AppPropertyGroup), findsNWidgets(2)); expect(tester.takeException(), isNull); @@ -120,6 +167,7 @@ void main() { for (final brightness in Brightness.values) { for (final (width, locale) in [ (220.0, 'de'), + (240.0, 'en'), (280.0, 'zh'), (360.0, 'en'), ]) { @@ -157,13 +205,34 @@ void main() { ); await tester.pumpAndSettle(); for (final name in ['x', 'y', 'scale-x', 'scale-y', 'rotation']) { - expect(tester.getSize(input(name)).height, 28); + expect(tester.getSize(input(name)).height, 24); } - expect(tester.getRect(input('x')).left, 12); - expect(tester.getRect(input('x')).width, (width - 28) / 2); + expect(tester.getRect(input('x')).left, 16); + expect(tester.getRect(input('x')).width, (width - 64) / 2); + expect(tester.getRect(input('rotation')).width, (width - 64) / 2); + expect(find.byType(AppPropertyGroup), findsNWidgets(4)); + expect( + tester.getRect(input('corner-radius')).width, + (width - 64) / 2, + ); + expect( + tester.getSize(find.byType(AppPropertySection).first).height, + 148, + ); + final align = find.byKey(const ValueKey('picture-align-left')); + final verticalAlign = find.byKey(const ValueKey('picture-align-top')); + expect( + tester.getCenter(align).dy, + tester.getCenter(verticalAlign).dy, + ); for (final name in ['x', 'y', 'scale-x', 'scale-y', 'rotation']) { final field = tester.widget(input(name)); expect(field.decoration!.prefixIcon, isNotNull); + final handle = find.descendant( + of: find.byKey(ValueKey('picture-$name')), + matching: find.byType(AppScrubLabel), + ); + expect(tester.getSize(handle).width, 24); } expect( find.descendant( @@ -194,12 +263,20 @@ void main() { ? 'scale-x' : 'rotation', ); - expect( - tester.getRect(action).bottom, - tester.getRect(field).top - 4, - ); + if (channel == 'scale') { + expect( + tester.getRect(action).bottom, + tester.getRect(field).top - 12, + ); + } else { + expect(tester.getCenter(action).dy, tester.getCenter(field).dy); + } } - expect(right, width - 12); + expect( + tester.getCenter(find.byKey(const Key('picture-lock'))).dy, + tester.getCenter(input('scale-x')).dy, + ); + expect(right, width - 8); expect( tester.getRect(input('x')).left, tester.getRect(input('rotation')).left, @@ -215,8 +292,8 @@ void main() { ); expect( tester.getRect(input('rotation')).top - - tester.getRect(input('scale-x')).bottom, - 40, + tester.getRect(input('x')).bottom, + 8, ); } expect( diff --git a/test/picture_corner_radius_test.dart b/test/picture_corner_radius_test.dart new file mode 100644 index 0000000..7fbaf54 --- /dev/null +++ b/test/picture_corner_radius_test.dart @@ -0,0 +1,226 @@ +import 'package:cutdex/app/editor_theme.dart'; +import 'package:cutdex/features/preview/preview_panel.dart'; +import 'package:cutdex/features/properties/picture_properties.dart'; +import 'package:cutdex/l10n/app_localizations.dart'; +import 'package:cutdex_sdk/editor.dart'; +import 'package:cutdex_sdk/runtime.dart'; +import 'package:cutdex_sdk/timeline/model.dart'; +import 'package:cutdex_ui/theme.dart'; +import 'package:cutdex_ui/widgets.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'support/preview_fixture.dart'; + +void main() { + testWidgets('corner radius edits, scrubs, animates and survives undo', ( + tester, + ) async { + final f = (await tester.runAsync( + () => createPreviewFixture( + Uri.file('/test/video.mov'), + clipDuration: RationalTime.seconds(5), + ), + ))!; + addTearDown( + () => tester.runAsync(() async { + await f.workspace.close(); + await f.directory.delete(recursive: true); + }), + ); + final sequence = SequenceId('one'); + final view = f.timeline.view(sequence); + final project = f.workspace.project!.info.id; + ClipAnimation current() { + final query = view.version.kernelVersion.query(); + return ClipAnimation.at( + query, + query.elementById(ElementId('clip'))!, + view.playheadTick, + TimelineClock.ticksPerSecond ~/ 30, + ); + } + + await tester.pumpWidget( + ProviderScope( + overrides: [ + editorPreviewProvider(project, 'project').overrideWith((ref) => null), + ], + child: MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + locale: const Locale('zh'), + theme: AppTheme.propertiesPanelTheme( + EditorTheme.desktop(EditorTheme.penDark), + ), + home: Scaffold( + body: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 240, + child: SingleChildScrollView( + child: PictureProperties( + projectId: project, + timelineId: 'project', + session: f.timeline, + sequence: sequence, + clip: current().record, + ), + ), + ), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + final input = find.descendant( + of: find.byKey(const ValueKey('picture-corner-radius')), + matching: find.byType(TextField), + ); + Future settle() async { + await tester.pump(); + await tester.runAsync(f.timeline.flush); + await tester.pumpAndSettle(); + expect(tester.takeException(), isNull); + } + + Future enter(String value) async { + await tester.ensureVisible(input); + await tester.enterText(input, value); + await tester.testTextInput.receiveAction(TextInputAction.done); + await settle(); + } + + expect(current().value.cornerRadius, 0); + await enter('48'); + expect(current().value.cornerRadius, 48); + expect(current().value.scale, 1); + expect(current().animated(TransformChannel.cornerRadius), isFalse); + view.undo(); + await settle(); + expect(current().value.cornerRadius, 0); + view.redo(); + await settle(); + expect(current().value.cornerRadius, 48); + await enter('-1'); + expect(current().value.cornerRadius, 48); + await enter('48'); + final label = find.descendant( + of: find.byKey(const ValueKey('picture-corner-radius')), + matching: find.byType(AppScrubLabel), + ); + await tester.drag(label, const Offset(20, 0)); + await settle(); + expect(current().value.cornerRadius, greaterThan(48)); + view.undo(); + await settle(); + expect(current().value.cornerRadius, 48); + final key = find.byKey(const ValueKey('picture-key-cornerRadius')); + await tester.ensureVisible(key); + await tester.tap(key); + await settle(); + expect(current().keyed(TransformChannel.cornerRadius), isTrue); + view.seekTo(2 * TimelineClock.ticksPerSecond); + await settle(); + await enter('96'); + expect(current().keyed(TransformChannel.cornerRadius), isTrue); + view.seekTo(TimelineClock.ticksPerSecond); + await settle(); + expect(current().value.cornerRadius, 72); + expect(tester.widget(input).controller!.text, '72'); + expect(current().record.parameters?['canvas.cornerRadius']?.length, 2); + final toggle = find.byKey(const ValueKey('picture-independent-corners')); + final beforeToggle = view.version.kernelVersion; + await tester.tap(toggle); + await settle(); + expect(identical(view.version.kernelVersion, beforeToggle), isTrue); + final topLeft = find.descendant( + of: find.byKey(const ValueKey('picture-corner-top-left')), + matching: find.byType(TextField), + ); + final topRight = find.descendant( + of: find.byKey(const ValueKey('picture-corner-top-right')), + matching: find.byType(TextField), + ); + expect(tester.getSize(topLeft), const Size(88, 24)); + expect(tester.getTopLeft(topRight).dx - tester.getTopRight(topLeft).dx, 8); + expect(tester.widget(topLeft).controller!.text, '72'); + await tester.enterText(topLeft, '120'); + await tester.testTextInput.receiveAction(TextInputAction.done); + await settle(); + expect(current().value.cornerRadii, [120, 72, 72, 72]); + expect(current().keyed(TransformChannel.cornerRadius), isTrue); + expect(tester.widget(input).controller!.text, '—'); + view.undo(); + await settle(); + expect(current().value.cornerRadii, [72, 72, 72, 72]); + view.redo(); + await settle(); + expect(current().value.cornerRadii, [120, 72, 72, 72]); + // Collapsing mixed corners is a presentation change, not a timeline edit. + await tester.tap(toggle); + await settle(); + expect(topLeft, findsNothing); + expect(tester.widget(input).controller!.text, '—'); + view.seekTo(TimelineClock.ticksPerSecond ~/ 2); + await settle(); + expect(current().value.cornerRadii, [84, 60, 60, 60]); + view.seekTo(TimelineClock.ticksPerSecond); + await settle(); + await enter('0'); + expect(current().value.cornerRadii, [0, 0, 0, 0]); + view.undo(); + await settle(); + final compiled = const ExecutionCompiler().compile( + ExecutionInput( + timeline: f.timeline.persistence.timeline(sequence), + renderSize: RenderSize(64, 64), + media: { + PayloadRef('source'): ExecutionMediaBinding( + media: MediaReference( + id: 'media', + uri: Uri.file('/test/video.mov'), + ), + videoTrackSelection: TrackSelection.index(0), + ), + }, + parameterTargets: ClipTransform.targets, + ), + ); + final curves = compiled.plan.visualLayers.single.automation; + expect( + curves.firstWhere((c) => c.target == 'cornerRadius.topLeft').keys.length, + 3, + ); + final saved = await tester.runAsync( + () => f.workspace.project!.loadTimeline('project'), + ); + expect( + saved!.sequences.first.elements.first.parameters.map( + (p) => p.definition.id, + ), + containsAll(ClipTransform.cornerIds), + ); + await tester.pumpWidget(const SizedBox()); + }); + + test('corner radius rejects nonfinite and negative values', () { + expect(const ClipTransform().cornerRadius, 0); + expect(const ClipTransform(cornerRadius: -1).isValid, isFalse); + expect(const ClipTransform(cornerRadius: double.nan).isValid, isFalse); + expect(const ClipTransform(bottomRightRadius: -1).isValid, isFalse); + expect( + const ClipTransform(topLeftRadius: double.infinity).isValid, + isFalse, + ); + final mixed = const ClipTransform(cornerRadius: 12, topLeftRadius: 30); + expect(mixed.copyWith(x: .2).cornerRadii, [30, 12, 12, 12]); + expect(mixed.copyWith(cornerRadius: 5).cornerRadii, [5, 5, 5, 5]); + expect( + const ClipTransform(cornerRadius: 40).copyWith(scale: 2).cornerRadius, + 40, + ); + }); +} diff --git a/test/picture_shadow_test.dart b/test/picture_shadow_test.dart new file mode 100644 index 0000000..51f2687 --- /dev/null +++ b/test/picture_shadow_test.dart @@ -0,0 +1,485 @@ +import 'package:cutdex/app/editor_theme.dart'; +import 'package:cutdex/features/preview/preview_panel.dart'; +import 'package:cutdex/features/properties/shadow_properties.dart'; +import 'package:cutdex/features/properties/picture_properties.dart'; +import 'package:cutdex/l10n/app_localizations.dart'; +import 'package:cutdex_sdk/editor.dart'; +import 'package:cutdex_sdk/runtime.dart'; +import 'package:cutdex_sdk/timeline/model.dart'; +import 'package:cutdex_sdk/timeline/engine.dart'; +import 'package:cutdex_ui/theme.dart'; +import 'package:cutdex_ui/widgets.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'support/preview_fixture.dart'; + +void main() { + testWidgets( + 'one shadow key captures all layers and structural edits preserve curves', + (tester) async { + final f = (await tester.runAsync( + () => createPreviewFixture( + Uri.file('/test/video.mov'), + clipDuration: RationalTime.seconds(5), + ), + ))!; + addTearDown( + () => tester.runAsync(() async { + await f.workspace.close(); + await f.directory.delete(recursive: true); + }), + ); + final seq = SequenceId('one'); + final clip = ElementId('clip'); + final view = f.timeline.view(seq); + final project = f.workspace.project!.info.id; + ClipShadowStack current() { + final q = view.version.kernelVersion.query(); + final h = q.elementById(clip)!; + return ClipShadowStack( + q.element(h), + view.playheadTick - q.absoluteStart(h), + ); + } + + await tester.pumpWidget( + ProviderScope( + overrides: [ + editorPreviewProvider( + project, + 'project', + ).overrideWith((ref) => null), + ], + child: MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + locale: const Locale('zh'), + theme: AppTheme.propertiesPanelTheme( + EditorTheme.desktop(EditorTheme.penDark), + ), + home: Scaffold( + body: Align( + alignment: Alignment.topRight, + child: SizedBox( + width: 240, + child: SingleChildScrollView( + child: ShadowProperties( + projectId: project, + timelineId: 'project', + session: f.timeline, + sequence: seq, + clip: clip, + ), + ), + ), + ), + ), + ), + ), + ); + Future settle() async { + await tester.pump(); + await tester.runAsync(f.timeline.flush); + await tester.pumpAndSettle(); + expect(tester.takeException(), isNull); + } + + Future closeEditor() async { + final close = find.byWidgetPredicate( + (w) => + w is IconButton && + w.key is ValueKey && + (w.key! as ValueKey).value.startsWith( + 'shadow-editor-close-', + ), + ); + if (close.evaluate().isNotEmpty) { + await tester.tap(close); + await settle(); + } + } + + Future tap(Key key) async { + await closeEditor(); + final w = find.byKey(key); + await tester.ensureVisible(w); + await tester.tap(w); + await settle(); + } + + Future enter(String id, String field, String value) async { + if (find.byKey(ValueKey('shadow-editor-$id')).evaluate().isEmpty) { + await closeEditor(); + await tester.tap(find.byKey(ValueKey('shadow-settings-$id'))); + await settle(); + } + final input = find.descendant( + of: find.byKey(ValueKey('shadow-$id-$field')), + matching: find.byType(TextField), + ); + await tester.ensureVisible(input); + await tester.enterText(input, value); + await tester.testTextInput.receiveAction(TextInputAction.done); + await settle(); + } + + await settle(); + expect(current().layers, isEmpty); + expect(tester.getSize(find.byType(AppPropertySection)).height, 40); + await tap(const ValueKey('shadow-add')); + final a = current().layers.single.id; + await tap(const ValueKey('shadow-add')); + final b = current().layers.last.id; + expect(find.byType(TextField), findsNothing); + expect( + tester.getSize(find.byKey(ValueKey('shadow-layer-$a'))).height, + 32, + ); + await enter(a, 'x', '12'); + expect( + tester.getSize(find.byKey(ValueKey('shadow-editor-$a'))).width, + 240, + ); + expect( + tester.getRect(find.byKey(ValueKey('shadow-editor-$a'))).right, + lessThan(tester.getRect(find.byKey(ValueKey('shadow-layer-$a'))).left), + ); + final xField = find.descendant( + of: find.byKey(ValueKey('shadow-$a-x')), + matching: find.byType(TextField), + ); + expect(tester.getSize(xField), const Size(100, 24)); + expect( + tester.getSize(find.byKey(ValueKey('shadow-editor-$a'))).height, + 225, + ); + final yField = find.descendant( + of: find.byKey(ValueKey('shadow-$a-y')), + matching: find.byType(TextField), + ); + expect(tester.getRect(yField).left - tester.getRect(xField).right, 8); + final blurInput = find.descendant( + of: find.byKey(ValueKey('shadow-$a-blur')), + matching: find.byType(TextField), + ); + final blurLabel = find.descendant( + of: find.byKey(ValueKey('shadow-$a-blur')), + matching: find.text('模糊'), + ); + final colorLabel = find.descendant( + of: find.byKey(ValueKey('shadow-editor-$a')), + matching: find.text('颜色'), + ); + expect(tester.getSize(blurLabel).height, 16); + expect( + tester.getRect(blurInput).top - tester.getRect(blurLabel).bottom, + 4, + ); + expect(tester.getRect(blurLabel).top - tester.getRect(xField).bottom, 12); + expect( + tester.getRect(colorLabel).top - tester.getRect(blurInput).bottom, + 12, + ); + expect(tester.widget(blurLabel).style!.fontSize, 11); + expect( + tester.widget(blurLabel).style!.color, + Colors.white.withValues(alpha: .7), + ); + expect(tester.widget(xField).style!.fontSize, 11); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await settle(); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await settle(); + expect(find.byKey(ValueKey('shadow-editor-$a')), findsNothing); + await enter(b, 'blur', '20'); + expect(current().animated, isFalse); + expect(current().layers[0].shadow.x, 12); + expect(current().layers[1].shadow.blur, 20); + await enter(a, 'color', 'FF8800'); + expect(current().layers.first.shadow.red, 1); + expect( + tester.getSize(find.byKey(ValueKey('shadow-$a-color'))).width, + closeTo( + 2 * tester.getSize(find.byKey(ValueKey('shadow-$a-opacity'))).width, + .01, + ), + ); + await tester.tap(find.byKey(const ValueKey('shadow-color-swatch'))); + await settle(); + final plane = tester.getRect( + find.byKey(const ValueKey('shadow-color-plane')), + ); + await tester.tapAt(plane.topCenter + const Offset(0, 2)); + await settle(); + expect(current().layers.first.shadow.blue, greaterThan(.45)); + expect(find.byKey(const ValueKey('shadow-color-plane')), findsOneWidget); + view.undo(); + await settle(); + expect(current().layers.first.shadow.green, closeTo(136 / 255, .001)); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await settle(); + expect(find.byKey(const ValueKey('shadow-color-plane')), findsNothing); + await enter(a, 'blur', '-1'); + expect(current().layers.first.shadow.blur, 8); + await tap(const ValueKey('shadow-key')); + expect(current().keyed, isTrue); + expect(current().parameterIds.length, 16); + expect( + current().parameterIds.every( + (id) => current().record.parameters?[id]?.length == 1, + ), + isTrue, + ); + view.seekTo(2 * TimelineClock.ticksPerSecond); + await settle(); + await enter(a, 'x', '32'); + await enter(b, 'blur', '40'); + expect( + current().parameterIds.every( + (id) => current().record.parameters?[id]?.length == 2, + ), + isTrue, + ); + view.seekTo(TimelineClock.ticksPerSecond); + await settle(); + expect(current().layers[0].shadow.x, 22); + expect(current().layers[1].shadow.blur, 30); + final blurField = find.descendant( + of: find.byKey(ValueKey('shadow-$b-blur')), + matching: find.byType(TextField), + ); + expect(tester.widget(blurField).controller!.text, '30'); + view.seekTo(0); + f.timeline.commands.editKeyframeChannel( + sequence: seq, + clip: clip, + tick: 0, + parameterIds: current().parameterIds, + action: KeyframeAction.set, + interpolation: ParameterInterpolation.hold, + ); + view.seekTo(TimelineClock.ticksPerSecond); + await settle(); + expect(current().layers.first.shadow.x, 12); + expect(current().layers.last.shadow.blur, 20); + view.undo(); + await settle(); + expect(current().layers.first.shadow.x, 22); + f.timeline.commands.editKeyframeChannel( + sequence: seq, + clip: clip, + tick: view.playheadTick, + parameterIds: current().parameterIds, + action: KeyframeAction.clear, + ); + await settle(); + expect(current().animated, isFalse); + expect(current().layers.first.shadow.x, 22); + view.undo(); + await settle(); + expect(current().animated, isTrue); + final before = current() + .record + .parameters?[ShadowParameterTarget(a, 'x').parameterId]; + await closeEditor(); + final dragWidget = find.byKey(ValueKey('shadow-drag-$a')); + expect( + tester.widget(dragWidget).enabled, + isTrue, + ); + final drag = tester.getCenter(dragWidget); + final gesture = await tester.startGesture(drag); + await tester.pump(); + await gesture.moveBy(const Offset(0, 12)); + await tester.pump(); + await gesture.moveBy(const Offset(0, 80)); + await tester.pump(const Duration(milliseconds: 300)); + await gesture.up(); + await settle(); + expect(current().layers.map((l) => l.id), [b, a]); + expect( + current().record.parameters?[ShadowParameterTarget(a, 'x').parameterId], + same(before), + ); + await tap(ValueKey('shadow-enabled-$b')); + expect(current().layers.first.enabled, isFalse); + await tap(ValueKey('shadow-remove-$a')); + expect(current().layers.length, 1); + expect( + current().record.parameters?[ShadowParameterTarget(a, 'x').parameterId], + isNull, + ); + view.undo(); + await settle(); + expect(current().layers.length, 2); + expect(current().layers.last.shadow.x, 22); + await tap(const ValueKey('shadow-add')); + final c = current().layers.last.id; + expect( + current() + .record + .parameters?[ShadowParameterTarget(c, 'x').parameterId] + ?.length, + 2, + ); + await tap(const ValueKey('shadow-add')); + expect(current().layers.length, 4); + expect( + tester + .widget(find.byKey(const ValueKey('shadow-add'))) + .onPressed, + isNull, + ); + expect( + () => f.timeline.commands.addShadow( + sequence: seq, + clip: clip, + tick: view.playheadTick, + shadowId: 'fifth', + ), + throwsA(isA()), + ); + await tester.tap(find.byKey(ValueKey('shadow-settings-$a'))); + await settle(); + await tester.tapAt(const Offset(50, 500)); + await settle(); + expect(find.byKey(ValueKey('shadow-editor-$a')), findsNothing); + await tester.tap(find.byKey(ValueKey('shadow-settings-$a'))); + await settle(); + f.timeline.commands.removeShadow( + sequence: seq, + clip: clip, + tick: view.playheadTick, + shadowId: a, + ); + await settle(); + expect(find.byKey(ValueKey('shadow-editor-$a')), findsNothing); + view.undo(); + await settle(); + expect(current().layers.length, 4); + final compiled = const ExecutionCompiler().compile( + ExecutionInput( + timeline: f.timeline.persistence.timeline(seq), + renderSize: RenderSize(64, 64), + media: { + PayloadRef('source'): ExecutionMediaBinding( + media: MediaReference( + id: 'media', + uri: Uri.file('/test/video.mov'), + ), + videoTrackSelection: TrackSelection.index(0), + ), + }, + parameterTargets: ClipTransform.targets, + ), + ); + expect( + compiled.plan.visualLayers.single.automation.map((a) => a.target), + contains(ShadowParameterTarget(a, 'x').parameterId), + ); + expect( + compiled.plan.visualLayers.single.automation + .firstWhere( + (c) => c.target == ShadowParameterTarget(a, 'x').parameterId, + ) + .keys + .length, + 2, + ); + // Existing persistence serializes all curves and feeds execution bindings unchanged. + final saved = await tester.runAsync( + () => f.workspace.project!.loadTimeline('project'), + ); + expect( + saved!.sequences.first.elements.first.parameters.map( + (p) => p.definition.id, + ), + contains(ShadowParameterTarget(a, 'x').parameterId), + ); + await tester.pumpWidget( + ProviderScope( + overrides: [ + editorPreviewProvider( + project, + 'project', + ).overrideWith((ref) => null), + ], + child: MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + locale: const Locale('zh'), + theme: AppTheme.propertiesPanelTheme( + EditorTheme.desktop(EditorTheme.penDark), + ), + home: Scaffold( + body: SizedBox( + width: 240, + child: SingleChildScrollView( + child: PictureProperties( + projectId: project, + timelineId: 'project', + session: f.timeline, + sequence: seq, + clip: current().record, + animationView: true, + ), + ), + ), + ), + ), + ), + ); + await settle(); + expect( + find.byKey(const ValueKey('picture-key-marker-shadow-0')), + findsOneWidget, + ); + expect( + find.byKey( + const ValueKey( + 'picture-key-marker-shadow-${2 * TimelineClock.ticksPerSecond}', + ), + ), + findsOneWidget, + ); + await tester.pumpWidget(const SizedBox()); + }, + ); + + test( + 'shadow validation and retimed group keys use the existing source clock', + () { + expect(const ClipShadow(blur: -1).isValid, isFalse); + expect(const ClipShadow(opacity: 2).isValid, isFalse); + expect(const ClipShadow(x: double.nan).isValid, isFalse); + expect(RenderShadowTarget.parse('shadow.a.color.r')?.field, 'color.r'); + expect(isRenderVisualTarget('shadow.a.blur'), isTrue); + expect(isRenderVisualTarget('shadow.a.invalid'), isFalse); + expect(ShadowParameterTarget.parse('shadow.中文.x'), isNull); + for (final delta in [8, -8]) { + final record = ElementRecord( + id: ElementId('clip'), + structure: ElementStructure.content, + duration: 4 * TimelineClock.ticksPerSecond, + sourceStart: 10 * TimelineClock.ticksPerSecond, + sourceDuration: 8 * TimelineClock.ticksPerSecond, + enabled: true, + retime: RetimeMapRecord([ + RetimeSegmentRecord( + projectDuration: 4 * TimelineClock.ticksPerSecond, + sourceStart: 10 * TimelineClock.ticksPerSecond, + sourceDelta: delta * TimelineClock.ticksPerSecond, + ), + ]), + ); + expect( + ClipShadowStack(record, TimelineClock.ticksPerSecond).sourceTick, + (10 + delta ~/ 4) * TimelineClock.ticksPerSecond, + ); + } + }, + ); +} diff --git a/test/project_properties_test.dart b/test/project_properties_test.dart index bcc243d..5351624 100644 --- a/test/project_properties_test.dart +++ b/test/project_properties_test.dart @@ -58,7 +58,7 @@ void main() { tester .getSize(find.byKey(const ValueKey('project-settings-edit'))) .height, - 28, + 24, ); final rows = find.byWidgetPredicate( (widget) => widget.runtimeType.toString() == '_Info', @@ -86,7 +86,7 @@ void main() { ); expect( tester.getRect(value).right, - panelRight - AppInspectorMetrics.padding, + panelRight - AppInspectorMetrics.trailingPadding, reason: '$locale at $width: ${tester.widget(value).data}', ); } @@ -144,8 +144,8 @@ void main() { of: find.byWidget(row.widget), matching: find.byType(Text), ); - expect(tester.getRect(texts.first).left, 12); - expect(tester.getRect(texts.last).right, width - 12); + expect(tester.getRect(texts.first).left, 16); + expect(tester.getRect(texts.last).right, width - 8); expect( tester.getTopLeft(texts.first).dy, closeTo(tester.getTopLeft(texts.last).dy, .01), diff --git a/test/property_number_input_test.dart b/test/property_number_input_test.dart index 6ff9415..af91a88 100644 --- a/test/property_number_input_test.dart +++ b/test/property_number_input_test.dart @@ -54,7 +54,7 @@ void main() { ), ); await tester.pumpAndSettle(); - expect(tester.getSize(find.byType(TextField)).height, 28); + expect(tester.getSize(find.byType(TextField)).height, 24); expect( tester .getRect( diff --git a/test/transcription_tools_test.dart b/test/transcription_tools_test.dart index c6af298..0d686be 100644 --- a/test/transcription_tools_test.dart +++ b/test/transcription_tools_test.dart @@ -2023,7 +2023,7 @@ void main() { matching: find.byType(ListView), ), ); - expect(row.left - list.left, desktop ? 12 : 14); + expect(row.left - list.left, desktop ? 16 : 14); expect(number.left - row.left, 0); expect(content.left - number.right, 6); expect(number.right, lessThan(content.left)); @@ -2045,7 +2045,7 @@ void main() { final wrapBounds = tester.getRect( find.byKey(const ValueKey('caption-wrap-toggle')), ); - expect(searchBounds.height, 28); + expect(searchBounds.height, desktop ? 24 : 28); expect(wrapBounds.height, desktop ? 24 : 28); expect(searchBounds.center.dy, wrapBounds.center.dy); await tester.enterText(search, ' searchable ');