feat(inspector): add animated independent corners and layered shadow controls
This commit is contained in:
1 parent
77dbb1897f
commit
8d1f8db7e8
23 files changed
+2375
-228
No files matched your search
@@ -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<void> settle() async {
|
||||
await tester.pump();
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
Future<void> closeEditor() async {
|
||||
final close = find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is IconButton &&
|
||||
w.key is ValueKey<String> &&
|
||||
(w.key! as ValueKey<String>).value.startsWith(
|
||||
'shadow-editor-close-',
|
||||
),
|
||||
);
|
||||
if (close.evaluate().isNotEmpty) {
|
||||
await tester.tap(close);
|
||||
await settle();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> tap(Key key) async {
|
||||
await closeEditor();
|
||||
final w = find.byKey(key);
|
||||
await tester.ensureVisible(w);
|
||||
await tester.tap(w);
|
||||
await settle();
|
||||
}
|
||||
|
||||
Future<void> 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<Text>(blurLabel).style!.fontSize, 11);
|
||||
expect(
|
||||
tester.widget<Text>(blurLabel).style!.color,
|
||||
Colors.white.withValues(alpha: .7),
|
||||
);
|
||||
expect(tester.widget<TextField>(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<TextField>(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<ReorderableDragStartListener>(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<IconButton>(find.byKey(const ValueKey('shadow-add')))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
() => f.timeline.commands.addShadow(
|
||||
sequence: seq,
|
||||
clip: clip,
|
||||
tick: view.playheadTick,
|
||||
shadowId: 'fifth',
|
||||
),
|
||||
throwsA(isA<CommandRejected>()),
|
||||
);
|
||||
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,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user