import 'dart:async'; import 'package:cutdex/l10n/l10n.dart'; import 'dart:math' as math; import 'package:cutdex/features/properties/animation_labels.dart'; import 'package:cutdex_core/editor.dart'; import 'package:cutdex_preview/cutdex_preview.dart'; import 'package:cutdex_core/timeline/engine.dart'; import 'package:cutdex_core/timeline/model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:cutdex_ui/icons.dart'; import 'package:cutdex_ui/theme.dart'; import 'package:cutdex_ui/widgets.dart'; import '../../workspace/timeline_session.dart'; import '../../shared/widgets/listenable_selector.dart'; import '../../shared/state/operation_scope.dart'; import '../preview/preview_panel.dart'; import 'property_number_input.dart'; import 'picture_edits.dart'; import 'effect_properties.dart'; import 'stroke_properties.dart'; import 'distortion_properties.dart'; import 'effect_labels.dart'; class PictureProperties extends ConsumerStatefulWidget { const PictureProperties({ super.key, required this.projectId, required this.timelineId, required this.session, required this.sequence, required this.clip, this.animationView = false, }); final String projectId; final String timelineId; final EditorTimelineSession session; final SequenceId sequence; final ElementRecord clip; final bool animationView; @override ConsumerState createState() => _PicturePropertiesState(); } class _PicturePropertiesState extends ConsumerState { Object get _editIdentity => ( widget.projectId, widget.timelineId, widget.session, widget.sequence, widget.clip.id, ); PreviewController? _boundPreview; Object get _operationContext => (_editIdentity, _boundPreview); late final _operations = OperationScope(_operationContext); late final _seeks = OperationScope(_operationContext); bool _locked = true; bool? _independentCorners; bool _hasFocusedControl = false; PictureEditsProvider get _editProvider => pictureEditsProvider(widget.session, widget.sequence, widget.clip.id); PictureEdits get _edits => ref.read(_editProvider.notifier); bool get _saving => ref.read(_editProvider).isLoading; bool Function() _guard() { final isCurrent = _operations.capture(); final session = widget.session; final sequence = widget.sequence; final clip = widget.clip.id; return () => mounted && isCurrent() && _scrubBase == null && identical(widget.session, session) && widget.sequence == sequence && widget.clip.id == clip; } @override void didUpdateWidget(covariant PictureProperties oldWidget) { super.didUpdateWidget(oldWidget); final previousIdentity = ( oldWidget.projectId, oldWidget.timelineId, oldWidget.session, oldWidget.sequence, oldWidget.clip.id, ); if (previousIdentity != _editIdentity) { _independentCorners = null; final edit = _clearScrub(); if (edit != null) scheduleMicrotask(edit.cancel); } _operations.bind(_operationContext); _seeks.bind(_operationContext); } Future _seek(PreviewController? preview, int tick) async { final isCurrent = _guard(); final isLatest = _seeks.begin(); final session = widget.session; final sequence = widget.sequence; final view = session.view(sequence); final version = view.version.kernelVersion; final position = view.playheadTick; await preview?.pauseForCanvasInteraction(); if (!isCurrent() || !isLatest() || session.activeSequenceId != sequence || view.playheadTick != position || !identical(view.version.kernelVersion, version)) { return; } view.seekTo(tick); } String? get _error => switch (ref.read(_editProvider).error) { PictureEditException(:final failure) => switch (failure) { PictureEditFailure.keyframes => context.l10n.updateKeyframesFailed, PictureEditFailure.alignment => context.l10n.alignClipFailed, PictureEditFailure.invalidTransform => context.l10n.invalidTransform, PictureEditFailure.transform => context.l10n.updatePictureFailed, }, _ => null, }; PreviewTransformEdit? _scrubEdit; ClipTransform? _scrubBase; ClipTransform? _scrubTimeline; TimelineVersion? _scrubVersion; int? _scrubTick; String? _scrubField; ClipTransform Function(ClipTransform, double)? _scrubChange; PreviewTransformEdit? _clearScrub() { final edit = _scrubEdit; _scrubEdit = null; _scrubBase = null; _scrubTimeline = null; _scrubField = null; _scrubChange = null; _scrubVersion = null; _scrubTick = null; return edit; } bool _startScrub( PreviewController? preview, String field, ClipTransform Function(ClipTransform, double) change, ) { if (_scrubBase != null || _saving || preview?.transforms.hasPending == true || widget.session.activeSequenceId != widget.sequence) { return false; } final base = _current(); if (base == null) return false; _scrubBase = base; _scrubField = field; _scrubChange = change; _scrubVersion = widget.session.view(widget.sequence).version.kernelVersion; _scrubTick = widget.session.view(widget.sequence).playheadTick; if (preview != null) { final visual = preview.visualForProperties(widget.clip.id); if (visual == null || (_scrubEdit = preview.transforms.begin(visual)) == null) { _scrubBase = null; _scrubField = null; _scrubChange = null; _scrubVersion = null; return false; } _scrubBase = _scrubEdit!.value; } return true; } bool get _scrubValid => _scrubBase != null && _scrubEdit?.released != true && _scrubTick == widget.session.view(widget.sequence).playheadTick && widget.session.activeSequenceId == widget.sequence && identical( _scrubVersion, widget.session.view(widget.sequence).version.kernelVersion, ); void _updateScrub(double distance) { if (!_scrubValid) { _cancelScrub(); return; } final value = _scrubChange!(_scrubBase!, distance); if (!value.isValid) return; setState(() => _scrubTimeline = value); _scrubEdit?.update(value); } void _endScrub(PreviewController? preview) { final value = _scrubTimeline; if (!_scrubValid || value == null || (value.x == _scrubBase!.x && value.y == _scrubBase!.y && value.rotation == _scrubBase!.rotation && value.scale == _scrubBase!.scale && value.scaleY == _scrubBase!.scaleY && value.sameCorners(_scrubBase!) && value.distortion.same(_scrubBase!.distortion))) { _cancelScrub(); return; } final edit = _clearScrub(); setState(() {}); if (edit != null) { unawaited(edit.end()); } else { unawaited(_commit(preview, (_) => value)); } } void _cancelScrub() { final edit = _clearScrub(); if (mounted) setState(() {}); edit?.cancel(); } @override void dispose() { _operations.dispose(); _seeks.dispose(); final edit = _clearScrub(); if (edit != null) scheduleMicrotask(edit.cancel); super.dispose(); } ClipAnimation? _animation() => _edits.animation(); ClipTransform? _current() => _animation()?.value; Object _presentation(PreviewController? preview) { final view = widget.session.view(widget.sequence); final animation = _animation(); final live = preview?.activeSequence() == widget.sequence ? preview?.transforms.valueFor(widget.clip.id) : null; final value = (_scrubValid ? _scrubTimeline : null) ?? live ?? animation?.value ?? ClipTransform.fromRecord(widget.clip); final timeDependent = widget.animationView || TransformChannel.values.any( (channel) => animation?.animated(channel) == true, ); return ( widget.session.activeSequenceId, animation?.record, animation?.start, animation?.frameTicks, _hasFocusedControl || _scrubBase != null ? view.version.kernelVersion : null, widget.session.canvas, animation?.containsPlayhead, timeDependent || _hasFocusedControl ? animation?.playhead : null, value.x, value.y, value.scale, value.scaleY, value.rotation, value.distortion.topLeft, value.distortion.topRight, value.distortion.bottomRight, value.distortion.bottomLeft, value.cornerRadius, value.topLeftRadius, value.topRightRadius, value.bottomRightRadius, value.bottomLeftRadius, _independentCorners, _scrubValid, _scrubBase != null, _saving, _error, preview?.aspectRatioLocked ?? _locked, preview?.transforms.hasPending == true && _scrubEdit == null, ); } Future _editKeys( PreviewController? preview, TransformChannel channel, { KeyframeAction? action, ParameterInterpolation? interpolation, }) { FocusManager.instance.primaryFocus?.unfocus(); FocusManager.instance.applyFocusChangesIfNeeded(); return _edits.editKeys( preview, channel, action: action, interpolation: interpolation, isCurrent: _guard(), ); } Future _align(PreviewController preview, CanvasAlignment alignment) => _edits.align(preview, alignment, isCurrent: _guard()); Future _commit( PreviewController? preview, ClipTransform Function(ClipTransform) change, ) => _edits.commit(preview, change, isCurrent: _guard()); @override Widget build(BuildContext context) { ref.watch(_editProvider); final preview = ref .watch(editorPreviewProvider(widget.projectId, widget.timelineId)) .asData ?.value; if (!identical(_boundPreview, preview)) { final edit = _clearScrub(); if (edit != null) scheduleMicrotask(edit.cancel); _boundPreview = preview; _operations.bind(_operationContext); _seeks.bind(_operationContext); } Widget contents() { final animation = _animation(); final live = preview?.activeSequence() == widget.sequence ? preview?.transforms.valueFor(widget.clip.id) : null; final value = (_scrubValid ? _scrubTimeline : null) ?? live ?? animation?.value ?? ClipTransform.fromRecord(widget.clip); final locked = preview?.aspectRatioLocked ?? _locked; final canvas = widget.session.canvas; final enabled = !_saving; final canvasDragging = preview?.transforms.hasPending == true && _scrubEdit == null; Widget keyButton(TransformChannel channel) { final keyed = animation?.keyed(channel) == true; final animated = animation?.animated(channel) == true; return IconButton( key: ValueKey('picture-key-${channel.name}'), tooltip: context.l10n.toggleKeyframe( keyed ? context.l10n.delete : context.l10n.addKeyframeAction, channel.label(context), ), isSelected: keyed, color: animated ? Theme.of(context).colorScheme.primary : null, icon: Transform.rotate( angle: math.pi / 4, child: Icon( keyed ? AppIcons.squareFilled : AppIcons.square, size: 12, ), ), onPressed: enabled && _scrubBase == null && !canvasDragging && animation != null ? () => _editKeys(preview, channel) : null, ); } final desktop = AppTheme.isDesktop(context); final gap = AppTheme.propertyRowGap(context); Widget axes( TransformChannel channel, Widget first, Widget second, { Widget? trailing, }) => LayoutBuilder( builder: (context, constraints) { if (desktop) { return AppPropertyRow( trailing: channel == TransformChannel.position ? keyButton(channel) : trailing, children: [first, second], ); } final pair = constraints.maxWidth < 240 ? Column( children: [ first, SizedBox(height: gap), second, ], ) : Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(child: first), SizedBox(width: gap), Expanded(child: second), ], ); return Row( children: [ Expanded(child: pair), SizedBox(width: gap), keyButton(channel), ], ); }, ); Widget keyTools(TransformChannel channel) { if (animation == null || !animation.animated(channel)) { return const SizedBox.shrink(); } final times = animation.keyTimes(channel); final tick = animation.playhead; final previous = times.where((t) => t < tick).lastOrNull; final next = times.where((t) => t > tick).firstOrNull; final canEdit = enabled && _scrubBase == null && !canvasDragging; Future seek(int target) => _seek(preview, target); return SizedBox( height: AppTheme.isDesktop(context) ? AppInspectorMetrics.action : AppControlSize.standard, child: Row( children: [ Text( context.l10n.keyframeCount(times.length), style: Theme.of(context).textTheme.bodySmall, ), const Spacer(), IconButton( key: ValueKey('picture-key-previous-${channel.name}'), tooltip: context.l10n.previousKeyframe(channel.label(context)), onPressed: canEdit && previous != null ? () => seek(previous) : null, icon: const Icon(AppIcons.chevronLeft, size: 16), ), IconButton( key: ValueKey('picture-key-next-${channel.name}'), tooltip: context.l10n.nextKeyframe(channel.label(context)), onPressed: canEdit && next != null ? () => seek(next) : null, icon: const Icon(AppIcons.chevronRight, size: 16), ), AppDropdownMenu( key: ValueKey('picture-key-menu-${channel.name}'), enabled: canEdit, builder: (context, toggle, focus) => IconButton( tooltip: context.l10n.keyframeSettings( channel.label(context), ), focusNode: focus, onPressed: toggle, icon: const Icon(AppIcons.more, size: 16), ), items: [ for (final (mode, label) in [ (ParameterInterpolation.linear, context.l10n.linear), (ParameterInterpolation.hold, context.l10n.hold), (ParameterInterpolation.easeIn, context.l10n.easeIn), (ParameterInterpolation.easeOut, context.l10n.easeOut), (ParameterInterpolation.easeInOut, context.l10n.easeInOut), ]) AppMenuItem( label: label, selected: animation.interpolation(channel) == mode, onPressed: animation.keyed(channel) ? () => _editKeys( preview, channel, action: KeyframeAction.set, interpolation: mode, ) : null, ), const AppMenuSeparator(), AppMenuItem( label: context.l10n.removeAllKeyframes, destructive: true, onPressed: animation.animated(channel) ? () => _editKeys( preview, channel, action: KeyframeAction.clear, ) : null, ), ], ), ], ), ); } Widget number( String id, String? label, double value, ClipTransform Function(ClipTransform, double) change, { String? unit, double min = double.negativeInfinity, double max = double.infinity, bool wrapRotation = false, bool inlineLabel = false, String? prefix, IconData? prefixIcon, int prefixQuarterTurns = 0, String? valueText, }) => PropertyNumberInput( key: ValueKey(id), label: label, inlineLabel: inlineLabel, prefix: prefix, prefixIcon: prefixIcon, prefixQuarterTurns: prefixQuarterTurns, valueText: valueText, unit: unit, value: value, enabled: !_saving, readOnly: _scrubBase != null || preview?.transforms.hasPending == true, submit: (v) => v < min || v > max ? Future.value(false) : _commit(preview, (current) => change(current, v)), onScrubStart: () => _startScrub( preview, id, (base, distance) => change( base, wrapRotation ? normalizeRotationDegrees(value + distance) : (value + distance).clamp(min, max), ), ), onScrubUpdate: _updateScrub, onScrubEnd: () => _endScrub(preview), onScrubCancel: _cancelScrub, scrubbing: _scrubField == id, editContext: ( _editIdentity, preview, widget.session.view(widget.sequence).version.kernelVersion, widget.session.view(widget.sequence).playheadTick, ), ); Widget section(List children) => AppPropertySection( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: children, ), ); final position = axes( TransformChannel.position, number( 'picture-x', 'X', value.x * canvas.width, (c, v) => c.copyWith(x: v / canvas.width), inlineLabel: true, ), number( 'picture-y', 'Y', value.y * canvas.height, (c, v) => c.copyWith(y: v / canvas.height), inlineLabel: true, ), ); final rotationInput = number( 'picture-rotation', context.l10n.rotation, value.rotation, (c, v) => c.copyWith(rotation: v), unit: '°', wrapRotation: true, inlineLabel: desktop, prefixIcon: desktop ? AppIcons.angle : null, ); final rotation = desktop ? AppPropertyRow( trailing: keyButton(TransformChannel.rotation), children: [rotationInput, const SizedBox.shrink()], ) : Row( children: [ Expanded(child: rotationInput), SizedBox(width: gap), keyButton(TransformChannel.rotation), ], ); Widget scaleControls({Widget? trailing}) => axes( TransformChannel.scale, number( 'picture-scale-x', 'W', value.scale * 100, (c, v) => c.copyWith( scale: v / 100, scaleY: locked ? c.scaleY * v / 100 / c.scale : c.scaleY, ), unit: '%', min: locked ? math.max(1.0, value.scale / value.scaleY) : 1, max: locked ? math.min(10000.0, 10000 * value.scale / value.scaleY) : 10000, inlineLabel: true, ), number( 'picture-scale-y', 'H', value.scaleY * 100, (c, v) => c.copyWith( scaleY: v / 100, scale: locked ? c.scale * v / 100 / c.scaleY : c.scale, ), unit: '%', min: locked ? math.max(1.0, value.scaleY / value.scale) : 1, max: locked ? math.min(10000.0, 10000 * value.scaleY / value.scale) : 10000, inlineLabel: true, ), trailing: trailing, ); final lock = IconButton( key: const Key('picture-lock'), tooltip: context.l10n.keepAspectRatio, icon: const Icon(AppIcons.unlock), selectedIcon: const Icon(AppIcons.lockFilled), isSelected: locked, onPressed: enabled ? () { if (preview?.transforms.hasPending == true) return; preview?.setAspectRatioLocked(!locked); setState(() => _locked = !locked); } : null, ); final scale = scaleControls(); final alignmentControls = LayoutBuilder( builder: (context, constraints) { final groups = [ for (final group in [ [ ( CanvasAlignment.left, context.l10n.alignLeft, AppIcons.alignLeft, ), ( CanvasAlignment.horizontalCenter, context.l10n.alignHorizontalCenter, AppIcons.alignHorizontalCenter, ), ( CanvasAlignment.right, context.l10n.alignRight, AppIcons.alignRight, ), ], [ (CanvasAlignment.top, context.l10n.alignTop, AppIcons.alignTop), ( CanvasAlignment.verticalCenter, context.l10n.alignVerticalCenter, AppIcons.alignVerticalCenter, ), ( CanvasAlignment.bottom, context.l10n.alignBottom, AppIcons.alignBottom, ), ], ]) SizedBox( width: desktop ? null : constraints.maxWidth < 200 ? constraints.maxWidth : (constraints.maxWidth - AppSpacing.small) / 2, child: AppButtonGroup( expanded: true, label: context.l10n.alignment, children: [ for (final (alignment, label, icon) in group) IconButton( key: ValueKey('picture-align-${alignment.name}'), tooltip: label, icon: Icon(icon, size: AppIconSize.standard), onPressed: () { if (!enabled || canvasDragging || preview == null || preview.busy || preview.visualForProperties(widget.clip.id) == null) { return; } unawaited(_align(preview, alignment)); }, ), ], ), ), ]; if (desktop) return AppPropertyRow(children: groups); return Wrap( spacing: AppSpacing.small, runSpacing: AppSpacing.small, children: groups, ); }, ); final radiusInput = number( 'picture-corner-radius', context.l10n.cornerRadius, value.topLeftRadius, (c, v) => c.copyWith(cornerRadius: v), min: 0, max: 1000000, inlineLabel: desktop, prefix: desktop ? '' : null, prefixIcon: desktop ? AppIcons.cornerRadius : null, valueText: value.hasMixedCorners ? '—' : null, ); final independent = _independentCorners ?? value.hasMixedCorners; final cornerToggle = IconButton( key: const ValueKey('picture-independent-corners'), tooltip: context.l10n.independentCorners, icon: const Icon(AppIcons.independentCorners), isSelected: independent, onPressed: enabled && _scrubBase == null && preview?.transforms.hasPending != true ? () => setState(() => _independentCorners = !independent) : null, ); final cornerInputs = [ number( 'picture-corner-top-left', context.l10n.cornerTopLeft, value.topLeftRadius, (c, v) => c.copyWith(topLeftRadius: v), min: 0, max: 1000000, inlineLabel: true, prefix: '', prefixIcon: Icons.rounded_corner, prefixQuarterTurns: 3, ), number( 'picture-corner-top-right', context.l10n.cornerTopRight, value.topRightRadius, (c, v) => c.copyWith(topRightRadius: v), min: 0, max: 1000000, inlineLabel: true, prefix: '', prefixIcon: Icons.rounded_corner, ), number( 'picture-corner-bottom-left', context.l10n.cornerBottomLeft, value.bottomLeftRadius, (c, v) => c.copyWith(bottomLeftRadius: v), min: 0, max: 1000000, inlineLabel: true, prefix: '', prefixIcon: Icons.rounded_corner, prefixQuarterTurns: 2, ), number( 'picture-corner-bottom-right', context.l10n.cornerBottomRight, value.bottomRightRadius, (c, v) => c.copyWith(bottomRightRadius: v), min: 0, max: 1000000, inlineLabel: true, prefix: '', prefixIcon: Icons.rounded_corner, prefixQuarterTurns: 1, ), ]; final content = Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ if (widget.animationView && animation != null) ...[ section([ _KeyframeTimeline( animation: animation, enabled: enabled && !canvasDragging && _scrubBase == null, onSeek: (tick) => _seek(preview, tick), ), ]), ], if (!widget.animationView && !desktop) section([ Text( context.l10n.alignment, style: AppTheme.propertySectionTitleStyle(context), ), SizedBox(height: gap), alignmentControls, ]), if (desktop) ...[ section([ AppPropertyGroup( label: context.l10n.position, padChild: false, child: Column( children: [ if (!widget.animationView) alignmentControls, position, keyTools(TransformChannel.position), rotation, keyTools(TransformChannel.rotation), ], ), ), ]), section([ AppPropertyGroup( label: context.l10n.scale, actions: [keyButton(TransformChannel.scale)], padChild: false, child: Column( children: [ scaleControls(trailing: lock), keyTools(TransformChannel.scale), ], ), ), ]), ] else ...[ section([ Text( context.l10n.position, style: AppTheme.propertySectionTitleStyle(context), ), SizedBox(height: gap), position, keyTools(TransformChannel.position), ]), section([rotation, keyTools(TransformChannel.rotation)]), section([ Row( children: [ Expanded( child: Text( context.l10n.scale, style: AppTheme.propertySectionTitleStyle(context), ), ), lock, ], ), SizedBox(height: gap), scale, keyTools(TransformChannel.scale), ]), ], DistortionProperties( projectId: widget.projectId, timelineId: widget.timelineId, session: widget.session, sequence: widget.sequence, clip: widget.clip.id, ), section([ if (desktop) AppPropertyGroup( label: context.l10n.cornerRadius, padChild: false, child: Column( children: [ AppPropertyRow( trailing: keyButton(TransformChannel.cornerRadius), children: [ radiusInput, Align( alignment: Alignment.centerRight, child: cornerToggle, ), ], ), if (independent) ...[ AppPropertyRow(children: cornerInputs.sublist(0, 2)), AppPropertyRow(children: cornerInputs.sublist(2, 4)), ], keyTools(TransformChannel.cornerRadius), ], ), ) else ...[ Row( children: [ Expanded(child: radiusInput), SizedBox(width: gap), cornerToggle, keyButton(TransformChannel.cornerRadius), ], ), if (independent) ...[ SizedBox(height: gap), Row( children: [ Expanded(child: cornerInputs[0]), SizedBox(width: gap), Expanded(child: cornerInputs[1]), ], ), SizedBox(height: gap), Row( children: [ Expanded(child: cornerInputs[2]), SizedBox(width: gap), Expanded(child: cornerInputs[3]), ], ), ], keyTools(TransformChannel.cornerRadius), ], ]), StrokeProperties( projectId: widget.projectId, timelineId: widget.timelineId, session: widget.session, sequence: widget.sequence, clip: widget.clip.id, ), EffectProperties( projectId: widget.projectId, timelineId: widget.timelineId, session: widget.session, sequence: widget.sequence, clip: widget.clip.id, ), if (_error != null) section([ Text( _error!, style: TextStyle(color: Theme.of(context).colorScheme.error), ), ]), ], ); // Canvas gestures own edits temporarily, without changing control colors. return ExcludeFocus( excluding: canvasDragging, child: IgnorePointer(ignoring: canvasDragging, child: content), ); } return Focus( onFocusChange: (focused) { if (mounted && focused != _hasFocusedControl) { setState(() => _hasFocusedControl = focused); } }, child: ListenableSelector( listenable: Listenable.merge([ widget.session.view(widget.sequence), if (preview != null) ...[preview, preview.transforms], ]), select: () => _presentation(preview), builder: (_, _) => contents(), ), ); } } class _KeyframeTimeline extends StatelessWidget { const _KeyframeTimeline({ required this.animation, required this.enabled, required this.onSeek, }); final ClipAnimation animation; final bool enabled; final ValueChanged onSeek; @override Widget build(BuildContext context) { final colors = Theme.of(context).colorScheme; final end = animation.lastTick; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Row( children: [ Text( context.l10n.keyframes, style: AppTheme.propertySectionTitleStyle(context), ), const Spacer(), Text( '${(animation.localTick / TimelineClock.ticksPerSecond).toStringAsFixed(2)} s', style: Theme.of(context).textTheme.bodySmall, ), ], ), const SizedBox(height: AppSpacing.small), for (final (id, label, times) in [ for (final channel in TransformChannel.values) (channel.name, channel.label(context), animation.keyTimes(channel)), for (final layer in ClipStrokeStack( animation.record, animation.localTick, ).layers) ( 'stroke-${layer.id}', context.l10n.stroke, ClipStrokeStack(animation.record, animation.localTick) .keyOffsets(layer.parameterIds) .map((t) => animation.start + t) .toList(), ), for (final layer in ClipEffectStack( animation.record, animation.localTick, ).layers) ( layer.id, layer.type.label(context), ClipEffectStack(animation.record, animation.localTick) .keyOffsets(layer.parameterIds) .map((t) => animation.start + t) .toList(), ), ]) SizedBox( height: 32, child: Row( children: [ SizedBox( width: 36, child: Text( label, style: Theme.of(context).textTheme.bodySmall, ), ), Expanded( child: LayoutBuilder( builder: (context, constraints) { final extent = (constraints.maxWidth - 20).clamp( 1.0, double.infinity, ); double x(int tick) => 10 + (end == 0 ? 0 : (tick - animation.start) / end).clamp( 0.0, 1.0, ) * extent; return GestureDetector( key: ValueKey('picture-key-track-$id'), behavior: HitTestBehavior.opaque, onTapDown: !enabled ? null : (details) { final fraction = ((details.localPosition.dx - 10) / extent) .clamp(0.0, 1.0); final tick = ((fraction * end / animation.frameTicks) .round() * animation.frameTicks) .clamp(0, end); onSeek(animation.start + tick); }, child: Stack( children: [ Positioned( left: 10, right: 10, top: 15, height: 1, child: ColoredBox(color: colors.outlineVariant), ), if (animation.containsPlayhead) Positioned( left: x(animation.playhead), top: 3, bottom: 3, width: 1, child: ColoredBox(color: colors.primary), ), for (final tick in times) Positioned( left: x(tick) - AppControlSize.compact / 2, top: 4, width: AppControlSize.compact, height: AppControlSize.compact, child: IconButton( key: ValueKey('picture-key-marker-$id-$tick'), tooltip: '$label ${((tick - animation.start) / TimelineClock.ticksPerSecond).toStringAsFixed(2)} s', padding: EdgeInsets.zero, onPressed: enabled ? () => onSeek(tick) : null, icon: Transform.rotate( angle: math.pi / 4, child: Icon( AppIcons.squareFilled, size: 9, color: tick == animation.playhead ? colors.primary : colors.onSurfaceVariant, ), ), ), ), ], ), ); }, ), ), ], ), ), ], ); } }