Move editor UI into the app and release verified Core dependencies #14
No files matched your search
@@ -621,6 +621,22 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
final PreviewController? controller;
|
||||
final SourcePreviewController? source;
|
||||
|
||||
ButtonStyle? _compactButtonStyle(BuildContext context) =>
|
||||
AppTheme.isDesktop(context)
|
||||
? IconButton.styleFrom(
|
||||
fixedSize: const Size.square(AppInspectorMetrics.action),
|
||||
minimumSize: const Size.square(AppInspectorMetrics.action),
|
||||
maximumSize: const Size.square(AppInspectorMetrics.action),
|
||||
padding: EdgeInsets.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(AppInspectorMetrics.radius),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (PreviewFullscreenScope.of(context)?.fullscreen == true) {
|
||||
@@ -661,7 +677,7 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
try {
|
||||
final time = CommandTime(tick, TimelineClock.ticksPerSecond);
|
||||
if (source case final source?) {
|
||||
await source.control(SourcePreviewAction.seek, at: time);
|
||||
await source.seekInteractive(tick);
|
||||
} else if (preview?.activeSequence() case final sequence?) {
|
||||
await preview!.controlPreview(sequence, PreviewAction.seek, at: time);
|
||||
}
|
||||
@@ -705,12 +721,25 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
icon: Icon(direction < 0 ? AppIcons.previousFrame : AppIcons.nextFrame),
|
||||
style: _compactButtonStyle(context),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _build(BuildContext context) {
|
||||
final preview = controller;
|
||||
final playing = source?.playing ?? preview?.playing ?? false;
|
||||
final timeTextStyle = AppTheme.isDesktop(context)
|
||||
? Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontFamily: 'packages/cutdex_ui/Inter',
|
||||
fontSize: AppInspectorMetrics.fontSize,
|
||||
height:
|
||||
AppInspectorMetrics.lineHeight / AppInspectorMetrics.fontSize,
|
||||
fontVariations: const [FontVariation('wght', 450)],
|
||||
letterSpacing: AppInspectorMetrics.fontSize * .005,
|
||||
fontFeatures: [const FontFeature.tabularFigures()],
|
||||
)
|
||||
: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(fontFeatures: [const FontFeature.tabularFigures()]);
|
||||
final frameDuration =
|
||||
source?.frameDuration ??
|
||||
preview?.frameDuration ??
|
||||
@@ -762,7 +791,9 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
? AppDesktopMetrics.playbackBar
|
||||
: AppControlSize.panelHeader,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.compact),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppInspectorMetrics.padding,
|
||||
),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final controls = Row(
|
||||
@@ -803,13 +834,14 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontFeatures: [const FontFeature.tabularFigures()],
|
||||
),
|
||||
style: timeTextStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (AppTheme.isDesktop(context)) _frameButton(context, -1),
|
||||
if (AppTheme.isDesktop(context)) ...[
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
_frameButton(context, -1),
|
||||
],
|
||||
ListenableSelector(
|
||||
listenable: source ?? preview,
|
||||
select: () => (
|
||||
@@ -826,10 +858,14 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
? preview.togglePlayback
|
||||
: null,
|
||||
icon: Icon(playing ? AppIcons.pause : AppIcons.play),
|
||||
style: _compactButtonStyle(context),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (AppTheme.isDesktop(context)) _frameButton(context, 1),
|
||||
if (AppTheme.isDesktop(context)) ...[
|
||||
_frameButton(context, 1),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
],
|
||||
Expanded(
|
||||
child: ListenableSelector(
|
||||
listenable: source ?? preview,
|
||||
@@ -854,8 +890,9 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
tooltip: context.l10n.retryPreview,
|
||||
onPressed: preview.busy ? null : preview.retry,
|
||||
icon: const Icon(AppIcons.refresh),
|
||||
style: _compactButtonStyle(context),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.gap),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
],
|
||||
if (source == null &&
|
||||
PreviewFullscreenScope.of(context)?.fullscreen !=
|
||||
@@ -865,6 +902,25 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
label: context.l10n.canvasRatio,
|
||||
outlined: false,
|
||||
controlHeight: AppTheme.isDesktop(context)
|
||||
? AppInspectorMetrics.input
|
||||
: null,
|
||||
textStyle: AppTheme.isDesktop(context)
|
||||
? Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium?.copyWith(
|
||||
fontFamily: 'packages/cutdex_ui/Inter',
|
||||
fontSize: AppInspectorMetrics.fontSize,
|
||||
height:
|
||||
AppInspectorMetrics.lineHeight /
|
||||
AppInspectorMetrics.fontSize,
|
||||
fontVariations: const [
|
||||
FontVariation('wght', 450),
|
||||
],
|
||||
letterSpacing:
|
||||
AppInspectorMetrics.fontSize * .005,
|
||||
)
|
||||
: null,
|
||||
value:
|
||||
preview?.canvas ?? ProjectCanvas.widescreen,
|
||||
onChanged: preview?.setCanvas,
|
||||
@@ -894,6 +950,7 @@ class _PreviewToolbar extends StatelessWidget {
|
||||
? AppIcons.exitFullscreen
|
||||
: AppIcons.fullscreen,
|
||||
),
|
||||
style: _compactButtonStyle(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -16,6 +16,7 @@ import 'package:cutdex/features/properties/mask_properties.dart';
|
||||
import 'package:cutdex/features/properties/property_number_input.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
@@ -208,6 +209,177 @@ void main() {
|
||||
messenger.setMockMethodCallHandler(events, null);
|
||||
});
|
||||
|
||||
testWidgets('alignment refreshes selection when the native scene settles', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/align.mov')),
|
||||
))!;
|
||||
final timeline = fixture.timeline;
|
||||
final sequence = SequenceId('one');
|
||||
final clip = ElementId('clip');
|
||||
await tester.runAsync(() async {
|
||||
timeline.commands.setTransform(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
change: (_) => const ClipTransform(x: .1, scale: .5, scaleY: .5),
|
||||
);
|
||||
await timeline.flush();
|
||||
});
|
||||
final preview = PreviewController(
|
||||
timeline: timeline,
|
||||
activeSequence: () => timeline.activeSequenceId,
|
||||
viewForSequence: timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.runAsync(() async {
|
||||
await preview.initialize();
|
||||
await until(() => calls.any((c) => c.method == 'seek'));
|
||||
});
|
||||
expect(tester.takeException(), isNull, reason: 'initialize');
|
||||
preview.selectVisual(clip);
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'project',
|
||||
).overrideWith((ref) async => preview),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penLight,
|
||||
home: const Scaffold(
|
||||
body: EditorPreviewPanel(
|
||||
projectId: 'project',
|
||||
timelineId: 'project',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final selection = find.descendant(
|
||||
of: find.byType(PreviewInteractionOverlay),
|
||||
matching: find.byType(CustomPaint),
|
||||
);
|
||||
final before = tester.widget<CustomPaint>(selection).painter!;
|
||||
final cachedVisual = preview.visualsForSelection({clip}).single;
|
||||
for (var i = 0; i < 100; i++) {
|
||||
expect(preview.visualsForSelection({clip}).single, same(cachedVisual));
|
||||
expect(preview.visuals.single, same(cachedVisual));
|
||||
}
|
||||
final canvasBefore = tester.widget<PreviewCanvas>(
|
||||
find.byType(PreviewCanvas),
|
||||
);
|
||||
final seeks = calls.where((c) => c.method == 'seek').length;
|
||||
final patch = blockedPatch = Completer<void>();
|
||||
await tester.runAsync(() async {
|
||||
await timeline.alignClip(
|
||||
sequence,
|
||||
AlignClip(
|
||||
clipId: 'clip',
|
||||
at: CommandTime(0, 1),
|
||||
alignment: CanvasAlignment.left,
|
||||
),
|
||||
);
|
||||
await until(() => calls.any((c) => c.method == 'applyPatch'));
|
||||
});
|
||||
expect(tester.takeException(), isNull, reason: 'align');
|
||||
await tester.pump();
|
||||
expect(preview.busy, isTrue);
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(before),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
patch.complete();
|
||||
await tester.runAsync(() => until(() => !preview.busy));
|
||||
expect(tester.takeException(), isNull, reason: 'native acknowledgement');
|
||||
await tester.pump();
|
||||
final aligned = tester.widget<CustomPaint>(selection).painter!;
|
||||
expect(aligned.shouldRepaint(before), isTrue);
|
||||
expect(
|
||||
preview.visualsForSelection({clip}).single,
|
||||
isNot(same(cachedVisual)),
|
||||
);
|
||||
expect(preview.visuals.single.geometry.bounds.left, closeTo(0, 1e-6));
|
||||
expect(
|
||||
tester.widget<PreviewCanvas>(find.byType(PreviewCanvas)),
|
||||
same(canvasBefore),
|
||||
);
|
||||
expect(preview.positionTick, 0);
|
||||
expect(preview.selectedVisualIds, {clip});
|
||||
|
||||
blockedPatch = null;
|
||||
await tester.runAsync(() async {
|
||||
timeline.view(sequence).undo();
|
||||
await until(() => !preview.busy);
|
||||
});
|
||||
expect(tester.takeException(), isNull, reason: 'undo');
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(aligned),
|
||||
isTrue,
|
||||
);
|
||||
final undone = tester.widget<CustomPaint>(selection).painter!;
|
||||
expect(preview.selectedVisualIds, isEmpty);
|
||||
await tester.runAsync(() async {
|
||||
timeline.view(sequence).redo();
|
||||
await until(() => !preview.busy);
|
||||
});
|
||||
await tester.pump();
|
||||
expect(preview.visuals.single.geometry.bounds.left, closeTo(0, 1e-6));
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(undone),
|
||||
isFalse,
|
||||
);
|
||||
expect(preview.selectedVisualIds, isEmpty);
|
||||
preview.selectVisual(clip);
|
||||
await tester.pump();
|
||||
for (final transform in [
|
||||
const ClipTransform(x: .2, y: .1),
|
||||
const ClipTransform(x: .2, y: .1, scale: .75, scaleY: .5),
|
||||
const ClipTransform(x: .2, y: .1, scale: .75, scaleY: .5, rotation: 30),
|
||||
]) {
|
||||
final previous = tester.widget<CustomPaint>(selection).painter!;
|
||||
await tester.runAsync(() async {
|
||||
timeline.commands.setTransform(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
change: (_) => transform,
|
||||
);
|
||||
await until(() => !preview.busy);
|
||||
});
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(previous),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
expect(calls.where((c) => c.method == 'seek'), hasLength(seeks));
|
||||
expect(
|
||||
calls.where((c) => c.method == 'beginInteractiveTransform'),
|
||||
isEmpty,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
test('alignment tools share geometry, preserve rotation and undo, and never seek', () async {
|
||||
final fixture = await createPreviewFixture(Uri.file('/align.mov'));
|
||||
final timeline = fixture.timeline;
|
||||
@@ -754,6 +926,136 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
for (final animated in [false, true]) {
|
||||
testWidgets('mask inspector follows playback with animated=$animated', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/mask-playback.mov')),
|
||||
))!;
|
||||
final timeline = fixture.timeline;
|
||||
final sequence = SequenceId('one');
|
||||
final clip = ElementId('clip');
|
||||
const maskId = 'playback-mask';
|
||||
await tester.runAsync(() async {
|
||||
timeline.commands.addMask(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
maskId: maskId,
|
||||
shape: ClipMaskShape.rectangle,
|
||||
);
|
||||
timeline.commands.setMask(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
maskId: maskId,
|
||||
value: const ClipMask(x: .25),
|
||||
);
|
||||
if (animated) {
|
||||
timeline.commands.editKeyframeChannel(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
parameterIds: ['mask.$maskId.center.x'],
|
||||
);
|
||||
timeline.commands.setMask(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: TimelineClock.ticksPerSecond,
|
||||
maskId: maskId,
|
||||
value: const ClipMask(x: .75),
|
||||
);
|
||||
}
|
||||
await timeline.flush();
|
||||
});
|
||||
final preview = PreviewController(
|
||||
timeline: timeline,
|
||||
activeSequence: () => timeline.activeSequenceId,
|
||||
viewForSequence: timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.runAsync(() async {
|
||||
await preview.initialize();
|
||||
await until(() => calls.any((c) => c.method == 'seek'));
|
||||
});
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'project',
|
||||
).overrideWith((ref) async => preview),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: MaskProperties(
|
||||
projectId: 'project',
|
||||
timelineId: 'project',
|
||||
element: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final xField = find.byWidgetPredicate(
|
||||
(widget) => widget is PropertyNumberInput && widget.label == 'X',
|
||||
);
|
||||
expect(tester.widget<PropertyNumberInput>(xField).value, 25);
|
||||
Future<void> advance(int seconds) async {
|
||||
await tester.runAsync(() async {
|
||||
emit({
|
||||
'state': 'playing',
|
||||
'revision': revision,
|
||||
'position': MediaTime(seconds, 1).toMap(),
|
||||
'rate': 1.0,
|
||||
});
|
||||
await until(
|
||||
() =>
|
||||
preview.playing &&
|
||||
preview.positionTick == seconds * TimelineClock.ticksPerSecond,
|
||||
);
|
||||
});
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
await advance(0);
|
||||
final before = tester.widget<PropertyNumberInput>(xField);
|
||||
var controlNotifications = 0;
|
||||
preview.addListener(() => controlNotifications++);
|
||||
await advance(1);
|
||||
expect(
|
||||
controlNotifications,
|
||||
0,
|
||||
reason: 'Playback ticks only notify position listeners',
|
||||
);
|
||||
expect(preview.maskFor(clip)!.x, animated ? .75 : .25);
|
||||
expect(
|
||||
tester.widget<PropertyNumberInput>(xField).value,
|
||||
animated ? 75 : 25,
|
||||
);
|
||||
if (!animated) {
|
||||
expect(tester.widget<PropertyNumberInput>(xField), same(before));
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('mask inspector adds a shape and grouped keys at compact width', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -12,6 +12,195 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('mask painting follows geometry and skips unchanged ticks', (
|
||||
tester,
|
||||
) async {
|
||||
final preview = _MaskPreview();
|
||||
addTearDown(preview.dispose);
|
||||
Widget host({
|
||||
double pixelRatio = 1,
|
||||
Rect rect = const Rect.fromLTWH(0, 0, 500, 300),
|
||||
}) => MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(devicePixelRatio: pixelRatio),
|
||||
child: MaskInteractionOverlay(controller: preview, canvasRect: rect),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(host());
|
||||
final paint = find.descendant(
|
||||
of: find.byType(MaskInteractionOverlay),
|
||||
matching: find.byType(CustomPaint),
|
||||
);
|
||||
CustomPainter current() => tester.widget<CustomPaint>(paint).painter!;
|
||||
var previous = current();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
preview.notifyListeners();
|
||||
await tester.pump();
|
||||
expect(current().shouldRepaint(previous), isFalse);
|
||||
previous = current();
|
||||
}
|
||||
for (final mask in [
|
||||
preview.mask.copyWith(x: .6),
|
||||
preview.mask.copyWith(width: .7),
|
||||
preview.mask.copyWith(rotation: 30),
|
||||
preview.mask.copyWith(shape: ClipMaskShape.ellipse),
|
||||
]) {
|
||||
preview.mask = mask;
|
||||
preview.notifyListeners();
|
||||
await tester.pump();
|
||||
expect(current().shouldRepaint(previous), isTrue);
|
||||
previous = current();
|
||||
}
|
||||
preview.value = const ClipTransform(x: .1);
|
||||
preview.notifyListeners();
|
||||
await tester.pump();
|
||||
expect(current().shouldRepaint(previous), isTrue);
|
||||
previous = current();
|
||||
await tester.pumpWidget(host(pixelRatio: 2));
|
||||
expect(current().shouldRepaint(previous), isTrue);
|
||||
previous = current();
|
||||
await tester.pumpWidget(
|
||||
host(pixelRatio: 2, rect: const Rect.fromLTWH(20, 10, 250, 150)),
|
||||
);
|
||||
expect(current().shouldRepaint(previous), isTrue);
|
||||
previous = current();
|
||||
await tester.binding.handleSystemMessage({'type': 'fontsChange'});
|
||||
await tester.pump();
|
||||
expect(current().shouldRepaint(previous), isTrue);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('empty selection skips geometry on playback ticks', (
|
||||
tester,
|
||||
) async {
|
||||
final preview = _Preview();
|
||||
addTearDown(preview.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: PreviewInteractionOverlay(
|
||||
controller: preview,
|
||||
canvasRect: const Rect.fromLTWH(0, 0, 500, 300),
|
||||
),
|
||||
),
|
||||
);
|
||||
for (var i = 0; i < 100; i++) {
|
||||
preview.notifyListeners();
|
||||
await tester.pump();
|
||||
}
|
||||
expect(preview.visualQueries, 0);
|
||||
preview.selectVisual(ElementId('upper'));
|
||||
await tester.pump();
|
||||
expect(preview.visualQueries, greaterThan(0));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('selection and controller changes update the decoration', (
|
||||
tester,
|
||||
) async {
|
||||
final first = _Preview(lowerOffset: const Offset(-100, 0))
|
||||
..selectVisual(ElementId('upper'));
|
||||
final second = _Preview(size: const Size(100, 100))
|
||||
..selectVisual(ElementId('upper'));
|
||||
addTearDown(first.dispose);
|
||||
addTearDown(second.dispose);
|
||||
Widget host(_Preview preview) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 600,
|
||||
height: 400,
|
||||
child: PreviewInteractionOverlay(
|
||||
controller: preview,
|
||||
canvasRect: const Rect.fromLTWH(40, 40, 500, 300),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final selection = find.descendant(
|
||||
of: find.byType(PreviewInteractionOverlay),
|
||||
matching: find.byType(CustomPaint),
|
||||
);
|
||||
await tester.pumpWidget(host(first));
|
||||
final upper = tester.widget<CustomPaint>(selection).painter!;
|
||||
first.selectVisual(ElementId('lower'));
|
||||
await tester.pump();
|
||||
final lower = tester.widget<CustomPaint>(selection).painter!;
|
||||
expect(lower.shouldRepaint(upper), isTrue);
|
||||
first.selectVisual(null);
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(lower),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(host(second));
|
||||
final replacement = tester.widget<CustomPaint>(selection);
|
||||
first.selectVisual(ElementId('upper'));
|
||||
first.transforms.presentation.value++;
|
||||
await tester.pump();
|
||||
expect(tester.widget<CustomPaint>(selection), same(replacement));
|
||||
second.value = const ClipTransform(x: .1);
|
||||
second.notifyListeners();
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester
|
||||
.widget<CustomPaint>(selection)
|
||||
.painter!
|
||||
.shouldRepaint(replacement.painter!),
|
||||
isTrue,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
first.notifyListeners();
|
||||
second.notifyListeners();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('selection follows scene edits without a parent rebuild', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final preview = _Preview()..selectVisual(ElementId('upper'));
|
||||
addTearDown(preview.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 600,
|
||||
height: 400,
|
||||
child: PreviewInteractionOverlay(
|
||||
controller: preview,
|
||||
canvasRect: const Rect.fromLTWH(40, 40, 500, 300),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final selection = find.descendant(
|
||||
of: find.byType(PreviewInteractionOverlay),
|
||||
matching: find.byType(CustomPaint),
|
||||
);
|
||||
final before = tester.widget<CustomPaint>(selection).painter!;
|
||||
preview.value = const ClipTransform(x: -.35);
|
||||
preview.notifyListeners();
|
||||
await tester.pump();
|
||||
final after = tester.widget<CustomPaint>(selection).painter!;
|
||||
expect(after.shouldRepaint(before), isTrue);
|
||||
expect(
|
||||
tester.renderObject<RenderCustomPaint>(selection),
|
||||
paints..rect(rect: const Rect.fromLTRB(36, 136, 44, 144)),
|
||||
);
|
||||
preview.value = const ClipTransform();
|
||||
preview.notifyListeners();
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(after),
|
||||
isTrue,
|
||||
);
|
||||
expect(preview.commits, 0);
|
||||
expect(preview.pauses, 0);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
Future<void> mount(
|
||||
WidgetTester tester,
|
||||
_Preview preview, {
|
||||
@@ -905,11 +1094,25 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
class _MaskPreview extends _Preview {
|
||||
@override
|
||||
bool get canPlay => true;
|
||||
ClipMask mask = const ClipMask();
|
||||
@override
|
||||
ElementId? get maskEditingElement => ElementId('upper');
|
||||
@override
|
||||
ClipMask? maskFor(ElementId id) => mask;
|
||||
}
|
||||
|
||||
class _Preview extends ChangeNotifier implements PreviewController {
|
||||
@override
|
||||
Listenable get positionChanges => this;
|
||||
|
||||
@override
|
||||
bool aspectRatioLocked = true;
|
||||
_Preview({this.size = const Size(300, 200)});
|
||||
_Preview({this.size = const Size(300, 200), this.lowerOffset = Offset.zero});
|
||||
final Size size;
|
||||
final Offset lowerOffset;
|
||||
@override
|
||||
final canvas = const ProjectCanvas(1000, 600);
|
||||
ClipTransform value = const ClipTransform();
|
||||
@@ -960,20 +1163,30 @@ class _Preview extends ChangeNotifier implements PreviewController {
|
||||
bool transforming = false;
|
||||
@override
|
||||
Set<ElementId> selectedVisualIds = {};
|
||||
int visualQueries = 0;
|
||||
@override
|
||||
List<PreviewVisual> get visuals => transforms.project([
|
||||
for (final (id, lane) in [('lower', 0), ('upper', 1)])
|
||||
PreviewVisual(
|
||||
layerId: id,
|
||||
elementId: ElementId(id),
|
||||
lane: lane,
|
||||
transform: value,
|
||||
geometry: PreviewGeometry(
|
||||
center: const Offset(500, 300),
|
||||
size: size,
|
||||
).changed(const ClipTransform(), value, const Size(1000, 600)),
|
||||
),
|
||||
], const Size(1000, 600));
|
||||
List<PreviewVisual> visualsForSelection(Set<ElementId> elements) =>
|
||||
visuals.where((v) => elements.contains(v.elementId)).toList();
|
||||
@override
|
||||
List<PreviewVisual> get visuals {
|
||||
visualQueries++;
|
||||
return transforms.project([
|
||||
for (final (id, lane) in [('lower', 0), ('upper', 1)])
|
||||
PreviewVisual(
|
||||
layerId: id,
|
||||
elementId: ElementId(id),
|
||||
lane: lane,
|
||||
transform: value,
|
||||
geometry: PreviewGeometry(
|
||||
center:
|
||||
const Offset(500, 300) +
|
||||
(id == 'lower' ? lowerOffset : Offset.zero),
|
||||
size: size,
|
||||
).changed(const ClipTransform(), value, const Size(1000, 600)),
|
||||
),
|
||||
], const Size(1000, 600));
|
||||
}
|
||||
|
||||
@override
|
||||
void selectVisual(ElementId? id) {
|
||||
selectedVisualIds = {?id};
|
||||
|
||||
@@ -17,6 +17,9 @@ import 'package:cutdex/features/timeline/timeline_asset_drop_target.dart';
|
||||
import 'package:cutdex/features/media/media_asset_drag.dart';
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'package:cutdex/workspace/timeline_provider.dart';
|
||||
|
||||
@@ -131,6 +134,94 @@ void main() {
|
||||
await root.delete(recursive: true);
|
||||
});
|
||||
|
||||
for (final direction in [-1.0, 1.0]) {
|
||||
testWidgets('single primary clip stays painted off axis $direction', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(
|
||||
() => _ViewProjects(session, projectId),
|
||||
),
|
||||
editorTimelineProvider(
|
||||
projectId,
|
||||
'project',
|
||||
).overrideWith((ref) => session),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: EditorTimelinePanel(
|
||||
projectId: projectId,
|
||||
timelineId: 'project',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final surface = find.byKey(const Key('editor-timeline-surface'));
|
||||
final origin = tester.getTopLeft(surface);
|
||||
final size = tester.getSize(surface);
|
||||
final viewport = TimelineViewportRect(
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
);
|
||||
final controller = session.view(session.activeSequenceId!);
|
||||
final base = controller.version;
|
||||
final frame = controller.project(viewport);
|
||||
final clipBounds = controller.presentationBoundsAt(frame, 0);
|
||||
final start = Offset(clipBounds.left + 30, clipBounds.center.dy);
|
||||
final gesture = await tester.startGesture(
|
||||
origin + start,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await gesture.moveTo(origin + start + Offset(0, 100 * direction));
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(controller.isDragging, isTrue);
|
||||
expect(controller.dragRejection, isNull);
|
||||
expect(controller.dragGhost, isNotNull);
|
||||
expect(controller.version, same(base));
|
||||
final ghostBounds = controller.dragGhostBounds(
|
||||
controller.dragGhost!,
|
||||
viewport,
|
||||
);
|
||||
final boundary = tester.renderObject<RenderRepaintBoundary>(
|
||||
find.descendant(of: surface, matching: find.byType(RepaintBoundary)),
|
||||
);
|
||||
await tester.runAsync(() async {
|
||||
final image = await boundary.toImage(pixelRatio: 1);
|
||||
try {
|
||||
final bytes = (await image.toByteData(
|
||||
format: ui.ImageByteFormat.rawRgba,
|
||||
))!;
|
||||
final point = Offset(ghostBounds.left + 30, ghostBounds.bottom - 10);
|
||||
final color = TimelineThemeData.of(tester.element(surface))
|
||||
.visualClipColor
|
||||
.toARGB32();
|
||||
expect(
|
||||
bytes.getUint32(
|
||||
(point.dy.toInt() * image.width + point.dx.toInt()) * 4,
|
||||
),
|
||||
((color & 0xffffff) << 8) | (color >> 24),
|
||||
);
|
||||
} finally {
|
||||
image.dispose();
|
||||
}
|
||||
});
|
||||
await gesture.cancel();
|
||||
expect(controller.version, same(base));
|
||||
expect(controller.canUndo, isFalse);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
for (final connected in [false, true]) {
|
||||
test('detach audio is independent and atomic (connected=$connected)', () async {
|
||||
final id = SequenceId('two');
|
||||
|
||||
Reference in new issue
Block a user