Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
1671 lines
54 KiB
Dart
1671 lines
54 KiB
Dart
import 'dart:ui' as ui;
|
|
|
|
import 'package:cutdex_core/timeline/engine.dart';
|
|
import 'package:cutdex_core/timeline/layout.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:cutdex_timeline_ui/cutdex_timeline_ui.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
test('playback follows the playhead one visible page at a time', () {
|
|
final f = _fixture();
|
|
final ticksPerSecond = TimelineClock.ticksPerSecond;
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10 / ticksPerSecond),
|
|
);
|
|
addTearDown(c.dispose);
|
|
c.configureViewport(
|
|
width: 100,
|
|
height: 80,
|
|
end: 40 * ticksPerSecond,
|
|
top: 0,
|
|
bottom: 80,
|
|
);
|
|
|
|
c.seekTo(9 * ticksPerSecond);
|
|
c.followPlayback();
|
|
expect(c.camera.baseTick, 0);
|
|
c.seekTo(10 * ticksPerSecond);
|
|
c.followPlayback();
|
|
expect(c.camera.baseTick, 10 * ticksPerSecond);
|
|
c.followPlayback();
|
|
expect(c.camera.baseTick, 10 * ticksPerSecond);
|
|
c.seekTo(20 * ticksPerSecond);
|
|
c.followPlayback();
|
|
expect(c.camera.baseTick, 20 * ticksPerSecond);
|
|
|
|
c.beginScrubbing();
|
|
c.seekTo(30 * ticksPerSecond);
|
|
c.followPlayback();
|
|
expect(c.camera.baseTick, 20 * ticksPerSecond);
|
|
c.endScrubbing();
|
|
});
|
|
|
|
testWidgets('playhead ticks do not invalidate clip and ruler painters', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final painters = tester
|
|
.widgetList<CustomPaint>(find.byType(CustomPaint))
|
|
.map((widget) => widget.painter)
|
|
.whereType<CustomPainter>()
|
|
.where(
|
|
(painter) => [
|
|
'_TimelinePainter',
|
|
'_RulerPainter',
|
|
].contains(painter.runtimeType.toString()),
|
|
)
|
|
.toList();
|
|
expect(painters, hasLength(2));
|
|
var invalidations = 0;
|
|
var positions = 0;
|
|
var editing = 0;
|
|
c.editingChanges.addListener(() => editing++);
|
|
for (final painter in painters) {
|
|
painter.addListener(() => invalidations++);
|
|
}
|
|
c.addListener(() => positions++);
|
|
for (var tick = 1; tick <= 120; tick++) {
|
|
c.seekTo(tick);
|
|
}
|
|
expect(positions, 120);
|
|
expect(editing, 120);
|
|
expect(
|
|
invalidations,
|
|
0,
|
|
reason: 'Static content must remain retained during playback',
|
|
);
|
|
await tester.pump();
|
|
c.setCamera(TimelineCamera(baseTick: 1, pixelsPerTick: 11));
|
|
c.setHoveredIdentity('hover');
|
|
expect(
|
|
editing,
|
|
120,
|
|
reason: 'Camera and hover must not rebuild inspectors or preview',
|
|
);
|
|
c.setSelection(['selected']);
|
|
expect(editing, 121);
|
|
expect(
|
|
invalidations,
|
|
greaterThan(0),
|
|
reason: 'Camera changes still repaint content',
|
|
);
|
|
});
|
|
|
|
testWidgets('frame detail starts at eight pixels and retains second labels', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture();
|
|
final frame = TimelineFormat.fps30.frameGrid.quantumTicks;
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
format: TimelineFormat.fps30,
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 7.99 / frame),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: TimelineRuler(controller: c),
|
|
),
|
|
);
|
|
_FrameRulerCanvas paint() {
|
|
final canvas = _FrameRulerCanvas();
|
|
tester
|
|
.widget<CustomPaint>(find.byType(CustomPaint))
|
|
.painter!
|
|
.paint(canvas, const Size(640, 28));
|
|
return canvas;
|
|
}
|
|
|
|
expect(paint().frameTicks, isEmpty);
|
|
c.setCamera(TimelineCamera(baseTick: 0, pixelsPerTick: 8 / frame));
|
|
await tester.pump();
|
|
final detailed = paint();
|
|
expect(detailed.frameTicks, contains(8.0));
|
|
expect(detailed.seconds, [
|
|
closeTo(0, 1e-6),
|
|
closeTo(240, 1e-6),
|
|
closeTo(480, 1e-6),
|
|
]);
|
|
c.setCamera(TimelineCamera(baseTick: 0, pixelsPerTick: 7.99 / frame));
|
|
await tester.pump();
|
|
expect(paint().frameTicks, isEmpty);
|
|
});
|
|
|
|
testWidgets('maximum zoom draws every frame without subframe marks', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture();
|
|
final format = TimelineFormat(frameDuration: RationalTime(1001, 30000));
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
format: format,
|
|
camera: TimelineCamera(
|
|
baseTick: 0,
|
|
pixelsPerTick: 32 / format.frameGrid.quantumTicks,
|
|
),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: TimelineRuler(controller: c),
|
|
),
|
|
);
|
|
final canvas = _FrameRulerCanvas();
|
|
tester
|
|
.widget<CustomPaint>(find.byType(CustomPaint))
|
|
.painter!
|
|
.paint(canvas, const Size(640, 28));
|
|
final visible = canvas.ticks.where((x) => x >= 0 && x < 640).toList()
|
|
..sort();
|
|
expect(visible.length, 20);
|
|
for (var i = 0; i < visible.length; i++) {
|
|
expect(visible[i], closeTo(i * 32, 1e-6));
|
|
}
|
|
});
|
|
|
|
for (final rate in [
|
|
RationalTime(1, 24),
|
|
RationalTime(1, 30),
|
|
RationalTime(1, 60),
|
|
RationalTime(1001, 30000),
|
|
]) {
|
|
test('zoom caps at 32 pixels per frame for $rate', () {
|
|
final f = _fixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
format: TimelineFormat(frameDuration: rate),
|
|
camera: TimelineCamera(
|
|
baseTick: 0,
|
|
pixelsPerTick: 100 / TimelineClock.ticksPerSecond,
|
|
),
|
|
);
|
|
addTearDown(c.dispose);
|
|
final v = TimelineViewportRect(width: 600, height: 200);
|
|
c.seekTo(c.frameTicks * 2);
|
|
final x = c.camera.screenXForTick(c.playheadTick, v);
|
|
c.zoomBy(scale: 1e10, viewport: v);
|
|
expect(c.camera.pixelsPerTick * c.frameTicks, closeTo(32, 1e-9));
|
|
expect(c.camera.screenXForTick(c.playheadTick, v), closeTo(x, 1e-6));
|
|
final camera = c.camera;
|
|
c.zoomBy(scale: 2, viewport: v);
|
|
expect(c.camera, same(camera));
|
|
c.zoomAt(screenX: x, newPixelsPerTick: 1, viewport: v);
|
|
expect(c.camera.pixelsPerTick * c.frameTicks, closeTo(32, 1e-9));
|
|
});
|
|
}
|
|
|
|
testWidgets('playhead overlays external padding and its left half can drag', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(
|
|
baseTick: 0,
|
|
pixelsPerTick: 100 / TimelineClock.ticksPerSecond,
|
|
),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
leadingPadding: 16,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final overlay = find.byKey(const ValueKey('timeline-playhead-overlay'));
|
|
final canvas = _PlayheadCanvas();
|
|
tester
|
|
.widget<CustomPaint>(overlay)
|
|
.painter!
|
|
.paint(canvas, tester.getSize(overlay));
|
|
expect(canvas.pointer!.left, 11.5);
|
|
expect(canvas.pointer!.right, 20.5);
|
|
expect(canvas.pointer!.top, 0);
|
|
expect(canvas.pointer!.bottom, 12);
|
|
expect(canvas.lineStart!.dy, 12);
|
|
expect(canvas.clip!.left, 0);
|
|
expect(tester.getTopLeft(find.byType(TimelineView)).dx, 16);
|
|
expect(c.camera.baseTick, 0);
|
|
final origin = tester.getTopLeft(overlay);
|
|
final drag = await tester.startGesture(origin + const Offset(12, 20));
|
|
await drag.moveBy(const Offset(24, 0));
|
|
expect(c.isScrubbing, isTrue);
|
|
await drag.moveBy(const Offset(24, 0));
|
|
await drag.up();
|
|
await tester.pump();
|
|
expect(c.isScrubbing, isFalse);
|
|
expect(c.playheadTick, greaterThan(0));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('scrubbing keeps the marker painted at a viewport edge', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture(clipDuration: 300);
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 1),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 300,
|
|
height: 160,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
c.beginScrubbing();
|
|
c.seekTo(301);
|
|
await tester.pump();
|
|
final overlay = find.byKey(const ValueKey('timeline-playhead-overlay'));
|
|
final canvas = _PlayheadCanvas();
|
|
tester
|
|
.widget<CustomPaint>(overlay)
|
|
.painter!
|
|
.paint(canvas, tester.getSize(overlay));
|
|
expect(canvas.pointer, isNotNull);
|
|
expect(canvas.lineStart!.dx, 300);
|
|
c.endScrubbing();
|
|
});
|
|
|
|
testWidgets('ruler click seeks once and ruler drag marks scrubbing', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(
|
|
baseTick: 0,
|
|
pixelsPerTick: 100 / TimelineClock.ticksPerSecond,
|
|
),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final ruler = find.byType(TimelineRuler);
|
|
final origin = tester.getTopLeft(ruler);
|
|
await tester.tapAt(origin + const Offset(120, 10));
|
|
expect(c.playheadTick, greaterThan(0));
|
|
expect(c.isScrubbing, isFalse);
|
|
final drag = await tester.startGesture(origin + const Offset(220, 10));
|
|
await drag.moveBy(const Offset(30, 0));
|
|
expect(c.isScrubbing, isTrue);
|
|
await drag.up();
|
|
expect(c.isScrubbing, isFalse);
|
|
});
|
|
|
|
for (final dragHandle in [true, false]) {
|
|
testWidgets(
|
|
'${dragHandle ? 'playhead handle' : 'ruler'} drag scrolls at edge and stops on release',
|
|
(tester) async {
|
|
const second = TimelineClock.ticksPerSecond;
|
|
final f = _fixture(clipDuration: 20 * second);
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30 / second),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 300,
|
|
height: 160,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final origin = tester.getTopLeft(find.byType(TimelineRuler));
|
|
final drag = await tester.startGesture(
|
|
origin + Offset(dragHandle ? 8 : 100, dragHandle ? 20 : 10),
|
|
);
|
|
await drag.moveBy(Offset(dragHandle ? 305 : 215, 0));
|
|
expect(c.isScrubbing, isTrue);
|
|
final before = c.playheadTick;
|
|
for (var i = 0; i < 20; i++) {
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
final overlay = find.byKey(
|
|
const ValueKey('timeline-playhead-overlay'),
|
|
);
|
|
final canvas = _PlayheadCanvas();
|
|
tester
|
|
.widget<CustomPaint>(overlay)
|
|
.painter!
|
|
.paint(canvas, tester.getSize(overlay));
|
|
expect(
|
|
canvas.pointer,
|
|
isNotNull,
|
|
reason: 'The playhead must remain painted while edge scrolling',
|
|
);
|
|
}
|
|
expect(c.camera.baseTick, greaterThan(0));
|
|
expect(c.playheadTick, greaterThan(before));
|
|
expect(
|
|
c.camera.screenXForTick(
|
|
c.playheadTick,
|
|
TimelineViewportRect(width: 300, height: 132),
|
|
),
|
|
inInclusiveRange(0, 301),
|
|
);
|
|
await drag.up();
|
|
await tester.pump();
|
|
expect(c.isScrubbing, isFalse);
|
|
final stopped = c.camera.baseTick;
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
expect(c.camera.baseTick, stopped);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
}
|
|
|
|
test('default zoom anchors visible playhead and falls back to center', () {
|
|
final f = _fixture();
|
|
const second = TimelineClock.ticksPerSecond;
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(
|
|
baseTick: 10 * second,
|
|
pixelsPerTick: 100 / second,
|
|
),
|
|
);
|
|
addTearDown(c.dispose);
|
|
final viewport = TimelineViewportRect(left: 20, width: 600, height: 100);
|
|
final version = c.version.kernelVersion;
|
|
c.seekTo(12 * second);
|
|
c.zoomBy(scale: 2, viewport: viewport);
|
|
expect(
|
|
c.camera.screenXForTick(c.playheadTick, viewport),
|
|
closeTo(220, 1e-6),
|
|
);
|
|
c.zoomBy(scale: .5, viewport: viewport);
|
|
expect(c.camera.baseTick, 10 * second);
|
|
for (final tick in [0, 30 * second]) {
|
|
c.seekTo(tick);
|
|
final centerTick = c.camera.tickAtScreenX(
|
|
320,
|
|
viewport,
|
|
rounding: TimelineTickRounding.nearest,
|
|
);
|
|
c.zoomBy(scale: 2, viewport: viewport);
|
|
expect(c.camera.screenXForTick(centerTick, viewport), closeTo(320, 1e-6));
|
|
expect(c.playheadTick, tick);
|
|
}
|
|
expect(c.version.kernelVersion, same(version));
|
|
c.setCamera(TimelineCamera(baseTick: 0, pixelsPerTick: 100 / second));
|
|
c.seekTo(second);
|
|
c.zoomBy(scale: .5, viewport: viewport);
|
|
expect(c.camera.baseTick, 0);
|
|
expect(c.camera.fractionalTick, 0);
|
|
});
|
|
|
|
testWidgets('ruler retains the preceding interval while panning left', (
|
|
tester,
|
|
) async {
|
|
final f = _fixture();
|
|
const second = TimelineClock.ticksPerSecond;
|
|
const scale = 100 / second;
|
|
const size = Size(600, 28);
|
|
final controller = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: scale),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: size.width,
|
|
child: TimelineRuler(controller: controller),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
_RulerCanvas paint() {
|
|
final canvas = _RulerCanvas();
|
|
tester
|
|
.widget<CustomPaint>(find.byType(CustomPaint))
|
|
.painter!
|
|
.paint(canvas, size);
|
|
return canvas;
|
|
}
|
|
|
|
final initial = paint();
|
|
final step = initial.major[1] - initial.major[0];
|
|
expect(initial.minor, isNotEmpty);
|
|
for (final pan in [0.25, 1.0, 20.0, step - 0.25, step + 0.25]) {
|
|
final tick = pan / scale;
|
|
controller.setCamera(
|
|
TimelineCamera(
|
|
baseTick: tick.floor(),
|
|
fractionalTick: tick - tick.floor(),
|
|
pixelsPerTick: scale,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final result = paint();
|
|
final intervalStart = (pan / step).floor() * step - pan;
|
|
expect(result.major.first, closeTo(intervalStart, 1e-6));
|
|
expect(result.labels.first.dx, closeTo(intervalStart + 4, 1e-6));
|
|
for (final mark in initial.minor.where(
|
|
(x) => x >= pan && x - pan < size.width,
|
|
)) {
|
|
expect(result.minor, contains(closeTo(mark - pan, 1e-6)));
|
|
}
|
|
expect(result.major.length, lessThanOrEqualTo(initial.major.length + 1));
|
|
expect(result.clips, contains(Offset.zero & size));
|
|
}
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
test('empty viewport fits once and retains explicit zoom through resize', () {
|
|
final f = _fixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 1),
|
|
);
|
|
addTearDown(c.dispose);
|
|
c.configureViewport(width: 800, height: 300, end: 0, top: 0, bottom: 100);
|
|
c.reconcileViewport();
|
|
final initial = c.camera.pixelsPerTick;
|
|
expect(initial * 20 * TimelineClock.ticksPerSecond, closeTo(800, 0.001));
|
|
c.zoomAt(
|
|
screenX: 0,
|
|
newPixelsPerTick: initial * 2,
|
|
viewport: TimelineViewportRect(width: 800, height: 300),
|
|
);
|
|
expect(c.camera.pixelsPerTick, initial * 2);
|
|
c.configureViewport(width: 1200, height: 400, end: 0, top: 0, bottom: 100);
|
|
c.reconcileViewport();
|
|
expect(c.camera.pixelsPerTick, initial * 2);
|
|
expect(c.camera.baseTick, 0);
|
|
});
|
|
|
|
testWidgets(
|
|
'viewport overlays both bars without shrinking content or ruler',
|
|
(tester) async {
|
|
final f = _fixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 40),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
const surface = Key('review-viewport-content');
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 200,
|
|
height: 60,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
child: const SizedBox.expand(key: surface),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final rect = tester.getRect(find.byKey(surface));
|
|
final horizontal = tester.getRect(
|
|
find.byKey(const ValueKey('timeline-horizontal-scrollbar')),
|
|
);
|
|
final vertical = tester.getRect(
|
|
find.byKey(const ValueKey('timeline-vertical-scrollbar')),
|
|
);
|
|
expect(tester.getSize(find.byType(TimelineRuler)).width, rect.width);
|
|
expect(horizontal.bottom, rect.bottom);
|
|
expect(horizontal.top, lessThan(rect.bottom));
|
|
expect(vertical.right, rect.right);
|
|
expect(vertical.left, lessThan(rect.right));
|
|
expect(rect.width, 200);
|
|
expect(
|
|
rect.height,
|
|
60 - tester.getSize(find.byType(TimelineRuler)).height,
|
|
);
|
|
expect(horizontal.right, vertical.left);
|
|
expect(vertical.bottom, horizontal.top);
|
|
c.panBy(horizontalPixels: 100000);
|
|
await tester.pumpAndSettle();
|
|
final end = c.version.kernelVersion.query().storylineSpan(c.storyline);
|
|
final endpoint = c.camera.screenXForTick(
|
|
end,
|
|
TimelineViewportRect(width: rect.width, height: rect.height),
|
|
);
|
|
expect(endpoint, greaterThan(0));
|
|
expect(endpoint, lessThan(rect.width - 12));
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
},
|
|
);
|
|
|
|
test('viewport bounds retain tail space and preserve zoom when cleared', () {
|
|
final fixture = _fixture();
|
|
final c = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
c.configureViewport(width: 100, height: 80, end: 10, top: -20, bottom: 200);
|
|
c.reconcileViewport();
|
|
expect(c.camera.verticalOffset, -20);
|
|
c.panBy(verticalPixels: 50);
|
|
c.configureViewport(
|
|
width: 100,
|
|
height: 100,
|
|
end: 10,
|
|
top: -20,
|
|
bottom: 220,
|
|
);
|
|
c.setCamera(c.camera);
|
|
expect(
|
|
c.camera.verticalOffset,
|
|
30,
|
|
reason: 'resize and added content preserve the user position',
|
|
);
|
|
c.configureViewport(width: 100, height: 80, end: 10, top: -20, bottom: 200);
|
|
c.panBy(horizontalPixels: 10000, verticalPixels: 10000);
|
|
final viewport = TimelineViewportRect(width: 100, height: 80);
|
|
expect(c.camera.screenXForTick(12, viewport), closeTo(100, 0.001));
|
|
expect(c.camera.screenXForTick(10, viewport), lessThan(100));
|
|
expect(c.camera.verticalOffset, 120);
|
|
c.panBy(horizontalPixels: -10000, verticalPixels: -10000);
|
|
expect(c.camera.baseTick, 0);
|
|
expect(c.camera.verticalOffset, -20);
|
|
c.configureViewport(width: 400, height: 400, end: 10, top: 0, bottom: 200);
|
|
c.panBy(horizontalPixels: 10000, verticalPixels: 10000);
|
|
expect(c.camera.baseTick, greaterThan(0));
|
|
expect(c.camera.verticalOffset, -20);
|
|
final scale = c.camera.pixelsPerTick;
|
|
c.configureViewport(width: 400, height: 400, end: 0, top: 0, bottom: 200);
|
|
c.setCamera(c.camera);
|
|
expect(c.camera.pixelsPerTick, scale);
|
|
c.panBy(horizontalPixels: 10000, verticalPixels: 10000);
|
|
expect(c.camera.baseTick, 0);
|
|
expect(c.camera.verticalOffset, -20);
|
|
expect(c.version, same(fixture.version));
|
|
});
|
|
|
|
test('focus primary uses current geometry and actual content bounds', () {
|
|
final fixture = _fixture();
|
|
final c = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 80, primaryHeight: 50),
|
|
camera: TimelineCamera(baseTick: 2, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
c.configureViewport(width: 100, height: 100, end: 10, top: 0, bottom: 300);
|
|
c.reconcileViewport();
|
|
expect(c.camera.verticalOffset, 55);
|
|
expect(c.camera.baseTick, 2);
|
|
c.panBy(verticalPixels: 1000);
|
|
expect(c.camera.verticalOffset, 200);
|
|
c.reconcileViewport();
|
|
expect(c.camera.verticalOffset, 200);
|
|
c.configureViewport(
|
|
width: 100,
|
|
height: 120,
|
|
end: 10,
|
|
top: -100,
|
|
bottom: 400,
|
|
);
|
|
c.reconcileViewport();
|
|
expect(c.camera.verticalOffset, 200);
|
|
c.focusPrimary(resetHorizontal: true);
|
|
expect(c.camera.verticalOffset, 45);
|
|
expect(c.camera.baseTick, 0);
|
|
c.panBy(verticalPixels: -1000);
|
|
expect(c.camera.verticalOffset, -100);
|
|
expect(c.version, same(fixture.version));
|
|
});
|
|
|
|
testWidgets(
|
|
'floating bars reveal on hover and scroll and yield to clip drags',
|
|
(tester) async {
|
|
final f = _richFixture();
|
|
final c = TimelineViewController(
|
|
version: f.version,
|
|
storyline: f.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
var taps = 0;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 200,
|
|
height: 100,
|
|
child: TimelineViewport(
|
|
showRuler: false,
|
|
controller: c,
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () => taps++,
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final bar = find.byKey(const ValueKey('timeline-horizontal-scrollbar'));
|
|
double opacity() => tester
|
|
.widget<AnimatedOpacity>(
|
|
find.descendant(of: bar, matching: find.byType(AnimatedOpacity)),
|
|
)
|
|
.opacity;
|
|
await tester.pumpAndSettle();
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pumpAndSettle();
|
|
expect(opacity(), 0.25);
|
|
final mouse = await tester.createGesture(
|
|
kind: ui.PointerDeviceKind.mouse,
|
|
);
|
|
await mouse.addPointer(location: const Offset(300, 200));
|
|
await mouse.moveTo(tester.getCenter(bar));
|
|
await tester.pumpAndSettle();
|
|
expect(opacity(), 1);
|
|
await mouse.moveTo(const Offset(300, 200));
|
|
await tester.pumpAndSettle();
|
|
c.panBy(horizontalPixels: 20);
|
|
await tester.pump();
|
|
expect(opacity(), 1);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pumpAndSettle();
|
|
expect(opacity(), 0.25);
|
|
final before = tester.getSize(find.byType(TimelineViewport));
|
|
final q = c.version.kernelVersion.query();
|
|
c.showIncomingClip(
|
|
c.version,
|
|
element: q.elementById(ElementId('connected'))!,
|
|
start: 0,
|
|
top: 10,
|
|
audioOnly: false,
|
|
position: const Offset(100, 90),
|
|
viewport: TimelineViewportRect(width: 200, height: 100),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(opacity(), 0);
|
|
await tester.tapAt(tester.getCenter(bar));
|
|
expect(taps, 1);
|
|
expect(c.isDragging, isTrue);
|
|
c.clearIncomingClip();
|
|
await tester.pumpAndSettle();
|
|
expect(opacity(), greaterThan(0));
|
|
expect(tester.getSize(find.byType(TimelineViewport)), before);
|
|
final thumb = find.byKey(const ValueKey('timeline-horizontal-thumb'));
|
|
final camera = c.camera.baseTick;
|
|
await tester.dragFrom(tester.getCenter(thumb), const Offset(35, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(c.camera.baseTick, greaterThan(camera));
|
|
await mouse.removePointer();
|
|
await tester.pumpWidget(const SizedBox());
|
|
},
|
|
);
|
|
|
|
testWidgets('horizontal scrollbar starts at zero with no leading space', (
|
|
tester,
|
|
) async {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 100,
|
|
height: 80,
|
|
child: TimelineViewport(
|
|
showRuler: false,
|
|
controller: controller,
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final track = find.byKey(const ValueKey('timeline-horizontal-scrollbar'));
|
|
final thumb = find.byKey(const ValueKey('timeline-horizontal-thumb'));
|
|
expect(tester.getTopLeft(thumb).dx, tester.getTopLeft(track).dx);
|
|
controller.panBy(horizontalPixels: 60);
|
|
await tester.pump();
|
|
expect(
|
|
tester.getTopLeft(thumb).dx,
|
|
greaterThan(tester.getTopLeft(track).dx),
|
|
);
|
|
controller.panBy(horizontalPixels: -1000);
|
|
await tester.pump();
|
|
expect(tester.getTopLeft(thumb).dx, tester.getTopLeft(track).dx);
|
|
controller.setCamera(TimelineCamera(baseTick: 0, pixelsPerTick: 1));
|
|
await tester.pumpAndSettle();
|
|
expect(track, findsNothing);
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-vertical-scrollbar')),
|
|
findsNothing,
|
|
);
|
|
});
|
|
|
|
testWidgets(
|
|
'primary-only viewport stays centered through resize without vertical scroll',
|
|
(tester) async {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 48, primaryHeight: 72),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 1),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
final height = ValueNotifier(200.0);
|
|
addTearDown(height.dispose);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: ValueListenableBuilder<double>(
|
|
valueListenable: height,
|
|
builder: (context, value, child) => SizedBox(
|
|
width: 400,
|
|
height: value,
|
|
child: TimelineViewport(
|
|
showRuler: false,
|
|
controller: controller,
|
|
child: child!,
|
|
),
|
|
),
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(controller.camera.verticalOffset, -16);
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-vertical-scrollbar')),
|
|
findsNothing,
|
|
);
|
|
|
|
controller.panBy(verticalPixels: 1000);
|
|
expect(controller.camera.verticalOffset, -16);
|
|
|
|
height.value = 300;
|
|
await tester.pumpAndSettle();
|
|
expect(controller.camera.verticalOffset, -66);
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-vertical-scrollbar')),
|
|
findsNothing,
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets('connected content reserves vertical drag space', (tester) async {
|
|
final fixture = _richFixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 30, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 1),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 400,
|
|
height: 60,
|
|
child: TimelineViewport(
|
|
showRuler: false,
|
|
controller: controller,
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-vertical-scrollbar')),
|
|
findsOneWidget,
|
|
);
|
|
controller.panBy(verticalPixels: -1000);
|
|
final top = controller.camera.verticalOffset;
|
|
controller.panBy(verticalPixels: 2000);
|
|
expect(controller.camera.verticalOffset, greaterThan(top));
|
|
});
|
|
|
|
test('viewport stops at zero for initialization, pan and zoom', () {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(
|
|
baseTick: -1,
|
|
fractionalTick: 0.5,
|
|
pixelsPerTick: 10,
|
|
verticalOffset: 12,
|
|
),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
expect(controller.camera.baseTick, 0);
|
|
expect(controller.camera.fractionalTick, 0);
|
|
expect(controller.camera.verticalOffset, 12);
|
|
controller.panBy(horizontalPixels: -100, verticalPixels: 8);
|
|
expect(controller.camera.baseTick, 0);
|
|
expect(controller.camera.verticalOffset, 20);
|
|
controller.panBy(horizontalPixels: 20);
|
|
expect(controller.camera.baseTick, 2);
|
|
controller.zoomAt(
|
|
screenX: 100,
|
|
newPixelsPerTick: 1,
|
|
viewport: TimelineViewportRect(width: 400, height: 100),
|
|
);
|
|
expect(controller.camera.baseTick, 0);
|
|
expect(controller.camera.fractionalTick, 0);
|
|
expect(controller.camera.pixelsPerTick, controller.maxPixelsPerTick);
|
|
expect(controller.version, same(fixture.version));
|
|
});
|
|
|
|
test('clip header theme tokens copy, interpolate and compare', () {
|
|
const a = TimelineThemeData.dark();
|
|
final b = a.copyWith(
|
|
clipHeaderHeight: 24,
|
|
clipHeaderPadding: 9,
|
|
clipNameTextStyle: const TextStyle(
|
|
color: Color(0xfffedcba),
|
|
fontSize: 15,
|
|
),
|
|
);
|
|
expect(a.copyWith(), a);
|
|
expect(b.copyWith().hashCode, b.hashCode);
|
|
expect(a, isNot(b));
|
|
final middle = a.lerp(b, .5);
|
|
expect(middle.clipHeaderHeight, 21);
|
|
expect(a.clipHeaderPadding, 2);
|
|
expect(middle.clipHeaderPadding, 5.5);
|
|
expect(middle.clipNameTextStyle.fontSize, 13);
|
|
});
|
|
|
|
test(
|
|
'frame element resolution covers clips and gaps and skips transitions',
|
|
() {
|
|
final fixture = _richFixture();
|
|
final c = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 30, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
final frame = c.project(TimelineViewportRect(width: 600, height: 80));
|
|
final query = frame.version.kernelVersion.query();
|
|
final ids = <String>[];
|
|
var transitions = 0;
|
|
for (var index = 0; index < frame.length; index++) {
|
|
final handle = c.elementForFrameItem(frame, index);
|
|
if (frame.kindAt(index) == TimelineViewportItemKind.transition) {
|
|
transitions++;
|
|
expect(handle, isNull);
|
|
} else {
|
|
ids.add(query.element(handle!).id.value);
|
|
}
|
|
}
|
|
expect(transitions, 1);
|
|
expect(
|
|
ids,
|
|
unorderedEquals(['left', 'right', 'gap', 'container', 'connected']),
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'visible media headers paint names while an unnamed gap stays blank',
|
|
(tester) async {
|
|
final fixture = _richFixture();
|
|
final c = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 30, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
_themeFixture(controller: c, inherited: const TimelineThemeData.dark()),
|
|
);
|
|
final canvas = _NameCanvas();
|
|
_painter(tester).paint(canvas, const Size(600, 80));
|
|
expect(
|
|
canvas.labels.length,
|
|
4,
|
|
reason: 'gap ID and transition boundary are not named clips',
|
|
);
|
|
expect(
|
|
canvas.labels.map((l) => l.width),
|
|
unorderedEquals([
|
|
for (final name in ['Video', 'Sound', 'Compound', 'Linked audio'])
|
|
_nameWidth(name),
|
|
]),
|
|
);
|
|
expect(c.version, same(fixture.version));
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'blank names fall back to IDs and stay anchored to cropped clip beginnings',
|
|
(tester) async {
|
|
final fixture = _fixture(name: ' ');
|
|
final c = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 2, pixelsPerTick: 30),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
_themeFixture(controller: c, inherited: const TimelineThemeData.dark()),
|
|
);
|
|
final canvas = _NameCanvas();
|
|
_painter(tester).paint(canvas, const Size(240, 40));
|
|
expect(canvas.labels.first.offset.dx, -57);
|
|
expect(canvas.labels.map((l) => l.width), [
|
|
_nameWidth('left'),
|
|
_nameWidth('right'),
|
|
]);
|
|
c.setCamera(TimelineCamera(baseTick: 3, pixelsPerTick: 30));
|
|
await tester.pump();
|
|
final panned = _NameCanvas();
|
|
_painter(tester).paint(panned, const Size(240, 40));
|
|
expect(panned.labels.first.offset.dx, -87);
|
|
expect(
|
|
panned.paragraphs.first,
|
|
same(canvas.paragraphs.first),
|
|
reason: 'Panning must reuse shaped clip labels',
|
|
);
|
|
expect(
|
|
panned.labels.map((l) => l.width),
|
|
canvas.labels.map((l) => l.width),
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'long names ellipsize and narrow clips cannot spill into neighbors',
|
|
(tester) async {
|
|
final fixture = _fixture(name: 'A very long clip name that cannot fit');
|
|
final c = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10),
|
|
);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
_themeFixture(controller: c, inherited: const TimelineThemeData.dark()),
|
|
);
|
|
final canvas = _NameCanvas();
|
|
_painter(tester).paint(canvas, const Size(100, 40));
|
|
expect(canvas.labels.length, 2);
|
|
expect(canvas.labels.every((l) => l.truncated && l.width <= 44), isTrue);
|
|
expect(
|
|
canvas.rectangles,
|
|
[
|
|
const Rect.fromLTWH(0, 0, 100, 40),
|
|
const Rect.fromLTWH(0, 10, 100, 20),
|
|
],
|
|
reason:
|
|
'canvas and primary lane backgrounds are filled, not clip headers',
|
|
);
|
|
c.setCamera(TimelineCamera(baseTick: 2, pixelsPerTick: 10));
|
|
await tester.pump();
|
|
final panned = _NameCanvas();
|
|
_painter(tester).paint(panned, const Size(100, 40));
|
|
expect(panned.labels.first.offset.dx, -17);
|
|
expect(
|
|
panned.labels.map((l) => l.width),
|
|
canvas.labels.map((l) => l.width),
|
|
);
|
|
c.setCamera(TimelineCamera(baseTick: 0, pixelsPerTick: 0.8));
|
|
final narrow = _NameCanvas();
|
|
_painter(tester).paint(narrow, const Size(100, 40));
|
|
expect(
|
|
narrow.labels,
|
|
isEmpty,
|
|
reason: 'no readable space inside a 4px clip',
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets('paints a projected frame and reuses it while panning', (
|
|
tester,
|
|
) async {
|
|
final fixture = _fixture();
|
|
final metrics = TimelineViewportMetrics();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10),
|
|
viewportEngine: TimelineViewportEngine(overscanScreens: 1),
|
|
metrics: metrics,
|
|
);
|
|
addTearDown(controller.dispose);
|
|
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 100,
|
|
height: 40,
|
|
child: TimelineView(controller: controller),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byType(CustomPaint), findsOneWidget);
|
|
expect(metrics.cacheRebuilds, 1);
|
|
expect(metrics.candidatesWritten, 2);
|
|
|
|
controller.panBy(horizontalPixels: 10);
|
|
await tester.pump();
|
|
|
|
expect(controller.camera.baseTick, 1);
|
|
expect(metrics.cacheHits, greaterThanOrEqualTo(1));
|
|
expect(metrics.cacheRebuilds, 1);
|
|
});
|
|
|
|
test('camera zoom remains presentation-only and cursor anchored', () {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(
|
|
baseTick: 0,
|
|
pixelsPerTick: 100 / TimelineClock.ticksPerSecond,
|
|
),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
final before = controller.version.kernelVersion;
|
|
final viewport = TimelineViewportRect(width: 100, height: 40);
|
|
|
|
controller.zoomAt(
|
|
screenX: 50,
|
|
newPixelsPerTick: 200 / TimelineClock.ticksPerSecond,
|
|
viewport: viewport,
|
|
);
|
|
|
|
expect(
|
|
controller.camera.screenXForTick(
|
|
TimelineClock.ticksPerSecond ~/ 2,
|
|
viewport,
|
|
),
|
|
closeTo(50, 1e-6),
|
|
);
|
|
expect(controller.version.kernelVersion, same(before));
|
|
});
|
|
|
|
testWidgets('resolves global theme once and honors a local override', (
|
|
tester,
|
|
) async {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
const inheritedA = TimelineThemeData.dark();
|
|
final inheritedB = inheritedA.copyWith(
|
|
backgroundColor: const Color(0xff000000),
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
_themeFixture(controller: controller, inherited: inheritedA),
|
|
);
|
|
final inheritedPainterA = _painter(tester);
|
|
await tester.pumpWidget(
|
|
_themeFixture(controller: controller, inherited: inheritedB),
|
|
);
|
|
final inheritedPainterB = _painter(tester);
|
|
expect(inheritedPainterB.shouldRepaint(inheritedPainterA), isTrue);
|
|
|
|
const local = TimelineThemeData.dark();
|
|
await tester.pumpWidget(
|
|
_themeFixture(
|
|
controller: controller,
|
|
inherited: inheritedA,
|
|
local: local,
|
|
),
|
|
);
|
|
final localPainterA = _painter(tester);
|
|
await tester.pumpWidget(
|
|
_themeFixture(
|
|
controller: controller,
|
|
inherited: inheritedB,
|
|
local: local,
|
|
),
|
|
);
|
|
final localPainterB = _painter(tester);
|
|
expect(localPainterB.shouldRepaint(localPainterA), isFalse);
|
|
});
|
|
|
|
testWidgets(
|
|
'renders structural and connected items without reclassification',
|
|
(tester) async {
|
|
final fixture = _richFixture();
|
|
final metrics = TimelineViewportMetrics();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 30, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 5),
|
|
metrics: metrics,
|
|
);
|
|
addTearDown(controller.dispose);
|
|
final classified = <ElementId>{};
|
|
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: SizedBox(
|
|
width: 100,
|
|
height: 80,
|
|
child: TimelineView(
|
|
controller: controller,
|
|
classifyContent: (element) {
|
|
classified.add(element.id);
|
|
return element.id.value == 'right'
|
|
? LayoutMediaLeafClass.audioOnly
|
|
: LayoutMediaLeafClass.nonAudio;
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(classified, {ElementId('left'), ElementId('right')});
|
|
expect(metrics.candidatesWritten, 6);
|
|
},
|
|
);
|
|
|
|
testWidgets('connection starts at the connected clip leading edge', (
|
|
tester,
|
|
) async {
|
|
final fixture = _richFixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 30, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 5),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
final theme = const TimelineThemeData.dark().copyWith(
|
|
connectionLineWidth: 3,
|
|
);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: SizedBox(
|
|
width: 100,
|
|
height: 100,
|
|
child: TimelineView(controller: controller, theme: theme),
|
|
),
|
|
),
|
|
);
|
|
|
|
final viewport = TimelineViewportRect(width: 100, height: 100);
|
|
final frame = controller.project(viewport);
|
|
final index = Iterable<int>.generate(frame.length).singleWhere(
|
|
(index) => frame.kindAt(index) == TimelineViewportItemKind.connected,
|
|
);
|
|
final clipLeft = controller.presentationBoundsAt(frame, index).left;
|
|
final canvas = _ConnectionCanvas();
|
|
_painter(tester).paint(canvas, const Size(100, 100));
|
|
expect(canvas.connections, hasLength(1));
|
|
expect(
|
|
canvas.connections.single.dx - theme.connectionLineWidth / 2,
|
|
closeTo(clipLeft, 0.001),
|
|
);
|
|
});
|
|
|
|
test('hit testing and interaction state stay presentation-only', () {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(primaryTop: 10, primaryHeight: 20),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
final before = controller.version.kernelVersion;
|
|
final query = before.query();
|
|
final left = query.elementById(ElementId('left'))!;
|
|
final right = query.elementById(ElementId('right'))!;
|
|
final viewport = TimelineViewportRect(width: 100, height: 40);
|
|
|
|
final leftHit = controller.hitTest(
|
|
viewport: viewport,
|
|
position: const Offset(25, 20),
|
|
);
|
|
final boundaryHit = controller.hitTest(
|
|
viewport: viewport,
|
|
position: const Offset(50, 20),
|
|
);
|
|
|
|
expect(leftHit?.identity, left);
|
|
expect(leftHit?.kind, TimelineViewportItemKind.primary);
|
|
expect(leftHit?.bounds, const Rect.fromLTWH(0, 10, 50, 20));
|
|
expect(boundaryHit?.identity, right);
|
|
expect(
|
|
controller.hitTest(viewport: viewport, position: const Offset(100, 20)),
|
|
isNull,
|
|
);
|
|
|
|
controller.setSelection([left]);
|
|
controller.setHoveredIdentity(right);
|
|
expect(controller.selectedIdentities, {left});
|
|
expect(controller.isSelected(left), isTrue);
|
|
expect(controller.hoveredIdentity, right);
|
|
expect(controller.version.kernelVersion, same(before));
|
|
});
|
|
|
|
test('Primary clips are centered independently inside their band', () {
|
|
final fixture = _fixture();
|
|
final controller = TimelineViewController(
|
|
version: fixture.version,
|
|
storyline: fixture.primary,
|
|
geometry: TimelineViewportGeometry(
|
|
primaryTop: 10,
|
|
primaryHeight: 20,
|
|
primaryClipHeight: 12,
|
|
),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10),
|
|
);
|
|
addTearDown(controller.dispose);
|
|
final frame = controller.project(
|
|
TimelineViewportRect(width: 100, height: 40),
|
|
);
|
|
final primary = List.generate(frame.length, (index) => index)
|
|
.where(
|
|
(index) => frame.kindAt(index) == TimelineViewportItemKind.primary,
|
|
)
|
|
.toList();
|
|
expect(primary, isNotEmpty);
|
|
expect(frame.screenTopAt(primary.first), 14);
|
|
expect(frame.screenHeightAt(primary.first), 12);
|
|
});
|
|
}
|
|
|
|
class _FrameRulerCanvas extends TestRecordingCanvas {
|
|
final ticks = <double>[];
|
|
final frameTicks = <double>[];
|
|
final seconds = <double>[];
|
|
@override
|
|
void drawLine(Offset first, Offset second, Paint paint) {
|
|
if (first.dx == second.dx) ticks.add(first.dx);
|
|
if (first.dy == 25) frameTicks.add(first.dx);
|
|
if (second.dy == 6) seconds.add(first.dx);
|
|
}
|
|
}
|
|
|
|
class _PlayheadCanvas extends TestRecordingCanvas {
|
|
Rect? pointer, clip;
|
|
Offset? lineStart;
|
|
@override
|
|
void drawPath(Path path, Paint paint) => pointer = path.getBounds();
|
|
@override
|
|
void drawLine(Offset first, Offset second, Paint paint) => lineStart = first;
|
|
@override
|
|
void clipRect(
|
|
Rect rect, {
|
|
ui.ClipOp clipOp = ui.ClipOp.intersect,
|
|
bool doAntiAlias = true,
|
|
}) => clip = rect;
|
|
}
|
|
|
|
class _ConnectionCanvas extends TestRecordingCanvas {
|
|
final connections = <Offset>[];
|
|
|
|
@override
|
|
void drawLine(Offset first, Offset second, Paint paint) {
|
|
if (first.dx == second.dx && paint.strokeWidth == 3) {
|
|
connections.add(first);
|
|
}
|
|
super.drawLine(first, second, paint);
|
|
}
|
|
}
|
|
|
|
class _RulerCanvas extends TestRecordingCanvas {
|
|
final major = <double>[];
|
|
final minor = <double>[];
|
|
final labels = <Offset>[];
|
|
final clips = <Rect>[];
|
|
@override
|
|
void drawLine(Offset a, Offset b, Paint paint) {
|
|
if (b.dy == 6) major.add(a.dx);
|
|
if (b.dy == 3) minor.add(a.dx);
|
|
super.drawLine(a, b, paint);
|
|
}
|
|
|
|
@override
|
|
void drawParagraph(ui.Paragraph paragraph, Offset offset) {
|
|
labels.add(offset);
|
|
super.drawParagraph(paragraph, offset);
|
|
}
|
|
|
|
@override
|
|
void clipRect(
|
|
Rect rect, {
|
|
ui.ClipOp clipOp = ui.ClipOp.intersect,
|
|
bool doAntiAlias = true,
|
|
}) {
|
|
clips.add(rect);
|
|
super.clipRect(rect, clipOp: clipOp, doAntiAlias: doAntiAlias);
|
|
}
|
|
}
|
|
|
|
Widget _themeFixture({
|
|
required TimelineViewController controller,
|
|
required TimelineThemeData inherited,
|
|
TimelineThemeData? local,
|
|
}) => Theme(
|
|
data: ThemeData(extensions: [inherited]),
|
|
child: SizedBox(
|
|
width: 100,
|
|
height: 40,
|
|
child: TimelineView(controller: controller, theme: local),
|
|
),
|
|
);
|
|
|
|
CustomPainter _painter(WidgetTester tester) =>
|
|
tester.widget<CustomPaint>(find.byType(CustomPaint)).painter!;
|
|
|
|
final class _NameCanvas extends TestRecordingCanvas {
|
|
final paragraphs = <ui.Paragraph>[];
|
|
final rectangles = <Rect>[];
|
|
|
|
@override
|
|
void drawRect(Rect rect, Paint paint) {
|
|
rectangles.add(rect);
|
|
super.drawRect(rect, paint);
|
|
}
|
|
|
|
final labels = <({double width, Offset offset, bool truncated})>[];
|
|
|
|
@override
|
|
void drawParagraph(ui.Paragraph paragraph, Offset offset) {
|
|
paragraphs.add(paragraph);
|
|
labels.add((
|
|
width: paragraph.longestLine,
|
|
offset: offset,
|
|
truncated: paragraph.didExceedMaxLines,
|
|
));
|
|
super.drawParagraph(paragraph, offset);
|
|
}
|
|
}
|
|
|
|
double _nameWidth(String name) {
|
|
final text = TextPainter(
|
|
textDirection: TextDirection.ltr,
|
|
text: TextSpan(
|
|
text: name,
|
|
style: const TimelineThemeData.dark().clipNameTextStyle,
|
|
),
|
|
)..layout();
|
|
final width = text.width;
|
|
text.dispose();
|
|
return width;
|
|
}
|
|
|
|
({LayoutVersion version, StorylineHandle primary}) _fixture({
|
|
String? name,
|
|
int clipDuration = 5,
|
|
}) {
|
|
final kernel = TimelineKernel.importDto(
|
|
TimelineDto(
|
|
id: SequenceId('ui-test'),
|
|
format: TimelineFormat.fps24,
|
|
primaryStorylineId: StorylineId('primary'),
|
|
storylines: [
|
|
StorylineDto(
|
|
id: StorylineId('primary'),
|
|
elementIds: [ElementId('left'), ElementId('right')],
|
|
),
|
|
],
|
|
elements: [
|
|
for (final id in ['left', 'right'])
|
|
ElementDto(
|
|
id: ElementId(id),
|
|
name: name,
|
|
structure: ElementStructure.content,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.timelineTicks(clipDuration),
|
|
),
|
|
duration: RationalTime.timelineTicks(clipDuration),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final projection = const TimelineLayoutSceneBuilder().project(
|
|
version: kernel.current,
|
|
stacks: const [],
|
|
appearance: (_, _, _) => throw StateError('fixture has no connections'),
|
|
);
|
|
final result = TimelineLayoutEngine(kernel: kernel).initializeProjection(
|
|
kernel: kernel,
|
|
projection: projection,
|
|
policy: LayoutPolicy(version: 1, stacks: const []),
|
|
);
|
|
return (
|
|
version: result.version,
|
|
primary: kernel.current.query().primaryStoryline,
|
|
);
|
|
}
|
|
|
|
({LayoutVersion version, StorylineHandle primary}) _richFixture() {
|
|
final kernel = TimelineKernel.importDto(
|
|
TimelineDto(
|
|
id: SequenceId('ui-rich-test'),
|
|
format: TimelineFormat.fps24,
|
|
primaryStorylineId: StorylineId('primary'),
|
|
storylines: [
|
|
StorylineDto(
|
|
id: StorylineId('primary'),
|
|
elementIds: [
|
|
ElementId('left'),
|
|
ElementId('right'),
|
|
ElementId('gap'),
|
|
ElementId('container'),
|
|
],
|
|
),
|
|
StorylineDto(
|
|
id: StorylineId('child'),
|
|
elementIds: [ElementId('child-content')],
|
|
),
|
|
],
|
|
elements: [
|
|
for (final id in ['left', 'right', 'child-content', 'connected'])
|
|
ElementDto(
|
|
id: ElementId(id),
|
|
name: switch (id) {
|
|
'left' => 'Video',
|
|
'right' => 'Sound',
|
|
'connected' => 'Linked audio',
|
|
_ => 'Inner clip',
|
|
},
|
|
structure: ElementStructure.content,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.timelineTicks(5),
|
|
),
|
|
duration: RationalTime.timelineTicks(5),
|
|
),
|
|
ElementDto(
|
|
id: ElementId('gap'),
|
|
structure: ElementStructure.gap,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.timelineTicks(5),
|
|
),
|
|
duration: RationalTime.timelineTicks(5),
|
|
),
|
|
ElementDto(
|
|
id: ElementId('container'),
|
|
name: 'Compound',
|
|
structure: ElementStructure.container,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.timelineTicks(5),
|
|
),
|
|
duration: RationalTime.timelineTicks(5),
|
|
containerStorylineId: StorylineId('child'),
|
|
),
|
|
],
|
|
connections: [
|
|
ConnectionDto(
|
|
id: ConnectionId('connected'),
|
|
anchorId: ElementId('left'),
|
|
targetId: ElementId('connected'),
|
|
anchorTime: RationalTime.timelineTicks(2),
|
|
targetTime: RationalTime.zero,
|
|
side: ConnectionSide.below,
|
|
),
|
|
],
|
|
transitions: [
|
|
TransitionDto(
|
|
id: TransitionId('transition'),
|
|
storylineId: StorylineId('primary'),
|
|
leftId: ElementId('left'),
|
|
rightId: ElementId('right'),
|
|
duration: RationalTime.timelineTicks(2),
|
|
timing: TransitionTiming.overlap,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final primary = kernel.current.query().primaryStoryline;
|
|
final stack = LayoutStackKey(scope: primary, side: ConnectionSide.below);
|
|
const domain = LayoutDomainId('audio');
|
|
final projection = const TimelineLayoutSceneBuilder().project(
|
|
version: kernel.current,
|
|
stacks: [stack],
|
|
appearance: (_, _, _) => const LayoutBodyAppearance(
|
|
height: 10,
|
|
domain: domain,
|
|
placementClass: LayoutPlacementClass.audioOnly,
|
|
),
|
|
);
|
|
final result = TimelineLayoutEngine(kernel: kernel).initializeProjection(
|
|
kernel: kernel,
|
|
projection: projection,
|
|
policy: LayoutPolicy(
|
|
version: 1,
|
|
stacks: [
|
|
LayoutStackPolicy(
|
|
stack: stack,
|
|
primaryBoundary: 50,
|
|
domains: const [domain],
|
|
innerGap: 5,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return (version: result.version, primary: primary);
|
|
}
|