feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s

This commit was merged in pull request #13.
This commit is contained in:
lingjhf committed 2026-10-08 18:17:12 +00:00
1 parent aa5255d1e4
commit abc1868550
260 files changed
+43964 -5591

No files matched your search

@@ -0,0 +1,43 @@
import 'package:cutdex_sdk/timeline_ui.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../settings/timeline_ruler_settings.dart';
class EditorTimelineViewport extends ConsumerWidget {
const EditorTimelineViewport({
required this.controller,
required this.child,
this.leadingPadding = 0,
this.rulerTimecodeLayout,
super.key,
});
final TimelineViewController controller;
final Widget child;
final double leadingPadding;
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
@override
Widget build(BuildContext context, WidgetRef ref) {
final desktop = AppTheme.isDesktop(context);
var layout = rulerTimecodeLayout ?? TimelineRulerTimecodeLayout.inline;
if (desktop && rulerTimecodeLayout == null) {
layout = ref.watch<TimelineRulerTimecodeLayout>(
timelineRulerSettingsProvider.select(
(value) => value.asData?.value ?? TimelineRulerTimecodeLayout.inline,
),
);
}
return TimelineViewport(
controller: controller,
leadingPadding: leadingPadding,
rulerStyle: desktop
? TimelineRulerStyle.timecode
: TimelineRulerStyle.elapsed,
rulerTimecodeLayout: layout,
child: child,
);
}
}
@@ -381,7 +381,15 @@ class TimelineExternalDropTargetState
@override
Widget build(BuildContext context) {
TickerMode.valuesOf(context);
ref.watch(projectsProvider);
ref.watch(
projectsProvider.select(
(value) => (
value.value?.activeProject?.id,
value.value?.projectBusy,
value.value?.timeline?.id,
),
),
);
ref.watch(_preparationProvider);
ref.listen(_preparationProvider.select((state) => state.preparation), (
_,
+463 -274
View File
@@ -1,3 +1,5 @@
import '../../shared/widgets/presentation_list.dart';
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import 'package:cutdex/l10n/l10n.dart';
import 'package:cutdex_sdk/timeline/engine.dart';
@@ -11,24 +13,30 @@ import 'package:cutdex_sdk/timeline_ui.dart';
import '../../shared/widgets/listenable_selector.dart';
import '../../workspace/timeline_provider.dart';
import '../../workspace/projects.dart';
import '../../workspace/project_state.dart';
import '../../integrations/runtime/timeline_thumbnails.dart';
import '../../integrations/runtime/timeline_waveforms.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.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 '../editor/editor_panel_defaults.dart';
import '../editor/timeline_operation_region.dart';
import '../media/transcription_dialog.dart';
import '../media/media_browser_controller.dart';
import '../media/background_removal_dialog.dart';
import '../projects/widgets/name_dialog.dart';
import '../../workspace/timeline_session.dart';
import '../../workspace/preview_target.dart';
import 'timeline_asset_drop_target.dart';
import 'editor_timeline_viewport.dart';
import 'timeline_speed_editor.dart';
class EditorTimelinePanel extends StatelessWidget {
@@ -38,12 +46,18 @@ class EditorTimelinePanel extends StatelessWidget {
required this.timelineId,
this.pending = false,
this.timelineLoading = false,
this.rulerTimecodeLayout,
});
final String projectId;
final String timelineId;
final bool pending;
/// Keeps the active surface visible while disabling edits during navigation.
final bool timelineLoading;
/// An override of the desktop ruler layout selected in settings.
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
@override
Widget build(BuildContext context) => Theme(
data: AppTheme.timelinePanelTheme(Theme.of(context)),
@@ -58,15 +72,15 @@ class EditorTimelinePanel extends StatelessWidget {
),
const Divider(height: 1),
Expanded(
child: timelineLoading
? const EditorTimelineDefaults(
key: Key('timeline-pending'),
showTabs: false,
)
: _TimelineSessionContent(
projectId: projectId,
timelineId: timelineId,
),
child: TimelineOperationRegion(
projectId: projectId,
loading: timelineLoading,
child: _TimelineSessionContent(
projectId: projectId,
timelineId: timelineId,
rulerTimecodeLayout: rulerTimecodeLayout,
),
),
),
],
),
@@ -82,16 +96,34 @@ class _TimelineTabsContent extends ConsumerWidget {
final String timelineId;
@override
Widget build(BuildContext context, WidgetRef ref) {
final projectState = ref.watch(projectsProvider).asData?.value;
final timelines = projectState?.activeProject?.id == projectId
? projectState!.timelines
: const <TimelineSummary>[];
final tabs = ref.watch(
projectsProvider.select((value) {
final state = value.asData?.value;
final active = state?.activeProject?.id == projectId;
return (
active
? PresentationList(
state!.timelines.map(
(timeline) => (timeline.id, timeline.name, timeline.pinned),
),
)
: PresentationList<(String, String, bool)>(const []),
active ? state?.visibleTimelineId : null,
active && state?.creatingTimeline == true,
active ? state?.openingTimelineId : null,
);
}),
);
return _TimelineTabsBar(
projectId: projectId,
timelineId: timelineId,
timelines: timelines,
creating: projectState?.creatingTimeline ?? false,
openingTimelineId: projectState?.openingTimelineId,
timelineId: tabs.$2 ?? timelineId,
timelines:
ref.read(projectsProvider).asData?.value.activeProject?.id ==
projectId
? ref.read(projectsProvider).asData!.value.timelines
: const <TimelineSummary>[],
creating: tabs.$3,
openingTimelineId: tabs.$4,
);
}
}
@@ -100,9 +132,19 @@ class _TimelineSessionContent extends ConsumerWidget {
const _TimelineSessionContent({
required this.projectId,
required this.timelineId,
required this.rulerTimecodeLayout,
});
final String projectId;
final String timelineId;
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
void _activateTimeline(WidgetRef ref) {
ref.read(mediaBrowserProvider(projectId)).selectedAssetId = null;
ref
.read(previewNavigationProvider(projectId, timelineId).notifier)
.showTimeline();
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = editorTimelineProvider(projectId, timelineId);
@@ -148,11 +190,14 @@ class _TimelineSessionContent extends ConsumerWidget {
'dart pointer-down',
);
}
ref
.read(previewNavigationProvider(projectId, timelineId).notifier)
.showTimeline();
_activateTimeline(ref);
},
child: _TimelineEditor(session: session, projectId: projectId),
child: _TimelineEditor(
session: session,
projectId: projectId,
rulerTimecodeLayout: rulerTimecodeLayout,
onSelectionActivated: () => _activateTimeline(ref),
),
),
);
}
@@ -178,7 +223,10 @@ class _TimelineTabsBar extends ConsumerStatefulWidget {
}
class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
static const _barHeight = 26.0;
double get _barHeight =>
AppTheme.isDesktop(context) ? AppDesktopMetrics.timelineTabs : 26.0;
double get _tabHeight =>
AppTheme.isDesktop(context) ? AppDesktopMetrics.timelineTabControl : 20;
static const _menuWidth = 220.0;
final _scrollController = ScrollController();
final _selectedMenuItemKey = GlobalKey();
@@ -320,117 +368,138 @@ class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
@override
Widget build(BuildContext context) {
final desktop = AppTheme.isDesktop(context);
final actionHeight = desktop ? _tabHeight : _barHeight;
final actionStyle = desktop ? AppTheme.timelineTabActionStyle : null;
final addButton = SizedBox.square(
dimension: actionHeight,
child: IconButton(
key: const Key('timeline-add-button'),
tooltip: context.l10n.createTimelineHint,
onPressed: _createTimeline,
style: actionStyle,
padding: EdgeInsets.zero,
constraints: BoxConstraints.tightFor(
width: actionHeight,
height: actionHeight,
),
icon: const Icon(AppIcons.add, size: AppIconSize.small),
),
);
final tabList = ScrollEdgeFade(
controller: _scrollController,
axis: Axis.horizontal,
child: Listener(
onPointerSignal: (event) {
if (event is! PointerScrollEvent || !_scrollController.hasClients) {
return;
}
final delta = event.scrollDelta.dy != 0
? event.scrollDelta.dy
: event.scrollDelta.dx;
if (delta == 0) return;
final position = _scrollController.position;
_scrollController.jumpTo(
(position.pixels + delta).clamp(
position.minScrollExtent,
position.maxScrollExtent,
),
);
},
child: SingleChildScrollView(
key: const Key('timeline-tabs-list'),
controller: _scrollController,
scrollDirection: Axis.horizontal,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.tiny),
child: Row(
children: [
for (
var index = 0;
index < widget.timelines.length;
index++
) ...[
if (index > 0) const SizedBox(width: AppSpacing.hairline),
_buildTab(context, widget.timelines[index]),
],
],
),
),
),
),
);
final listButton = SizedBox.square(
dimension: actionHeight,
child: AppPopover(
width: _menuWidth,
maxHeight: 320,
alignment: AlignmentDirectional.bottomEnd,
child: SingleChildScrollView(
primary: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final timeline in widget.timelines)
KeyedSubtree(
key: timeline.id == widget.timelineId
? _selectedMenuItemKey
: null,
child: AppMenuItem(
key: ValueKey('timeline-menu-${timeline.id}'),
label: timeline.name,
selected: timeline.id == widget.timelineId,
selectOption: true,
onPressed: () => _openTimeline(timeline),
),
),
],
),
),
builder: (context, toggle) => IconButton(
key: const Key('timeline-list-button'),
tooltip: context.l10n.timelines,
onPressed: () {
toggle();
_showSelectedMenuItem();
},
padding: EdgeInsets.zero,
style: actionStyle,
constraints: BoxConstraints.tightFor(
width: actionHeight,
height: actionHeight,
),
icon: const Icon(AppIcons.more, size: AppIconSize.small),
),
),
);
return ColoredBox(
color: Theme.of(context).colorScheme.surface,
key: const Key('timeline-tabs-background'),
color: AppTheme.timelineTabsBackground(context),
child: SizedBox(
key: const Key('timeline-tabs-bar'),
height: _barHeight,
child: Row(
children: [
SizedBox.square(
dimension: _barHeight,
child: IconButton(
key: const Key('timeline-add-button'),
tooltip: context.l10n.createTimelineHint,
onPressed: _createTimeline,
padding: EdgeInsets.zero,
constraints: const BoxConstraints.tightFor(
width: _barHeight,
height: _barHeight,
),
icon: const Icon(Icons.add, size: AppIconSize.small),
),
),
if (!desktop) addButton,
Expanded(
child: ScrollEdgeFade(
controller: _scrollController,
axis: Axis.horizontal,
child: Listener(
onPointerSignal: (event) {
if (event is! PointerScrollEvent ||
!_scrollController.hasClients) {
return;
}
final delta = event.scrollDelta.dy != 0
? event.scrollDelta.dy
: event.scrollDelta.dx;
if (delta == 0) return;
final position = _scrollController.position;
_scrollController.jumpTo(
(position.pixels + delta).clamp(
position.minScrollExtent,
position.maxScrollExtent,
),
);
},
child: SingleChildScrollView(
key: const Key('timeline-tabs-list'),
controller: _scrollController,
scrollDirection: Axis.horizontal,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.tiny,
),
child: desktop
? Align(
alignment: AlignmentDirectional.centerStart,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
for (
var index = 0;
index < widget.timelines.length;
index++
) ...[
if (index > 0)
const SizedBox(width: AppSpacing.hairline),
_buildTab(context, widget.timelines[index]),
],
Flexible(child: tabList),
addButton,
],
),
),
),
),
),
)
: tabList,
),
SizedBox.square(
dimension: _barHeight,
child: AppPopover(
width: _menuWidth,
maxHeight: 320,
alignment: AlignmentDirectional.bottomEnd,
child: SingleChildScrollView(
primary: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final timeline in widget.timelines)
KeyedSubtree(
key: timeline.id == widget.timelineId
? _selectedMenuItemKey
: null,
child: AppMenuItem(
key: ValueKey('timeline-menu-${timeline.id}'),
label: timeline.name,
selected: timeline.id == widget.timelineId,
selectOption: true,
onPressed: () => _openTimeline(timeline),
),
),
],
),
),
builder: (context, toggle) => IconButton(
key: const Key('timeline-list-button'),
tooltip: context.l10n.timelines,
onPressed: () {
toggle();
_showSelectedMenuItem();
},
padding: EdgeInsets.zero,
constraints: const BoxConstraints.tightFor(
width: _barHeight,
height: _barHeight,
),
icon: const Icon(Icons.more_horiz, size: AppIconSize.small),
),
Padding(
padding: EdgeInsetsDirectional.only(
end: desktop ? AppSpacing.tiny : 0,
),
child: listButton,
),
],
),
@@ -449,19 +518,19 @@ class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
label: timeline.pinned
? context.l10n.unpinTimeline
: context.l10n.pinTimeline,
icon: Icons.push_pin_outlined,
icon: AppIcons.pin,
onPressed: () => _setTimelinePinned(timeline),
),
AppMenuItem(
key: ValueKey('timeline-rename-${timeline.id}'),
label: context.l10n.rename,
icon: Icons.drive_file_rename_outline,
icon: AppIcons.rename,
onPressed: () => _renameTimeline(timeline),
),
AppMenuItem(
key: ValueKey('timeline-delete-${timeline.id}'),
label: context.l10n.delete,
icon: Icons.delete_outline,
icon: AppIcons.delete,
destructive: true,
onPressed: widget.timelines.length <= 1
? null
@@ -470,59 +539,33 @@ class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
],
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: TextButton(
key: ValueKey('timeline-tab-${timeline.id}'),
onPressed: () => _openTimeline(timeline),
style: ButtonStyle(
minimumSize: const WidgetStatePropertyAll(Size(0, 20)),
maximumSize: const WidgetStatePropertyAll(
Size(double.infinity, 20),
child: Semantics(
selected: selected,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: AppTheme.isDesktop(context) ? 180 : double.infinity,
),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
textStyle: WidgetStatePropertyAll(
Theme.of(context).textTheme.labelLarge?.copyWith(
fontSize: 12,
height: 1.3,
fontWeight: FontWeight.w400,
child: TextButton(
key: ValueKey('timeline-tab-${timeline.id}'),
onPressed: () => _openTimeline(timeline),
style: AppTheme.timelineTabStyle(context, selected: selected),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (timeline.pinned) ...[
const Icon(AppIcons.pinFilled, size: 10),
const SizedBox(width: AppSpacing.tiny),
],
Flexible(
child: Text(
timeline.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: AppSpacing.small),
),
foregroundColor: WidgetStatePropertyAll(
selected
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).colorScheme.onSurfaceVariant,
),
backgroundColor: WidgetStatePropertyAll(
selected
? Theme.of(context).colorScheme.onSurface
.withValues(alpha: .05)
: Colors.transparent,
),
overlayColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed)) {
return Theme.of(context).colorScheme.onSurface
.withValues(alpha: .078);
}
return Colors.transparent;
}),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (timeline.pinned) ...[
const Icon(Icons.push_pin, size: 10),
const SizedBox(width: AppSpacing.tiny),
],
Text(
timeline.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
@@ -532,9 +575,16 @@ class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
}
class _TimelineEditor extends StatefulWidget {
const _TimelineEditor({required this.session, required this.projectId});
const _TimelineEditor({
required this.session,
required this.projectId,
required this.onSelectionActivated,
required this.rulerTimecodeLayout,
});
final String projectId;
final EditorTimelineSession session;
final VoidCallback onSelectionActivated;
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
@override
State<_TimelineEditor> createState() => _TimelineEditorState();
@@ -545,6 +595,49 @@ class _TimelineEditorState extends State<_TimelineEditor> {
String get projectId => widget.projectId;
RuntimeTimelineThumbnails get _thumbnails => session.thumbnails;
RuntimeTimelineWaveforms get _waveforms => session.waveforms;
TimelineViewController? _selectionView;
Set<Object> _lastSelection = {};
@override
void initState() {
super.initState();
session.addListener(_bindSelectionView);
_bindSelectionView();
}
@override
void didUpdateWidget(covariant _TimelineEditor oldWidget) {
super.didUpdateWidget(oldWidget);
if (!identical(oldWidget.session, session)) {
oldWidget.session.removeListener(_bindSelectionView);
session.addListener(_bindSelectionView);
_bindSelectionView();
}
}
void _bindSelectionView() {
final sequence = session.activeSequenceId;
final next = sequence == null ? null : session.view(sequence);
if (identical(next, _selectionView)) return;
_selectionView?.editingChanges.removeListener(_selectionChanged);
_selectionView = next;
_lastSelection = next?.selectedIdentities.toSet() ?? {};
next?.editingChanges.addListener(_selectionChanged);
}
void _selectionChanged() {
final selected = _selectionView?.selectedIdentities.toSet() ?? {};
if (setEquals(selected, _lastSelection)) return;
_lastSelection = selected;
if (selected.isNotEmpty) widget.onSelectionActivated();
}
@override
void dispose() {
session.removeListener(_bindSelectionView);
_selectionView?.editingChanges.removeListener(_selectionChanged);
super.dispose();
}
@override
Widget build(BuildContext context) => ListenableSelector(
@@ -709,7 +802,9 @@ class _TimelineEditorState extends State<_TimelineEditor> {
}
final controller = session.view(sequenceId);
return WorkspacePanel(
headerHeight: 32,
headerHeight: AppTheme.isDesktop(context)
? AppDesktopMetrics.timelineToolbar
: 32,
headerPadding: EdgeInsets.zero,
controls: ListenableSelector(
listenable: Listenable.merge([
@@ -730,103 +825,191 @@ class _TimelineEditorState extends State<_TimelineEditor> {
builder: (context, _) {
final captionCues = _selectedCaptionCues(controller);
final canSplitCaption = _canSplitCaption(controller, captionCues);
return SizedBox(
key: const Key('timeline-toolbar'),
height: 32,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.gap),
child: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.maxWidth),
child: IntrinsicWidth(
child: Row(
children: [
Row(
mainAxisSize: MainAxisSize.min,
spacing: AppSpacing.tiny,
children: [
_toolbarButton(
tooltip: context.l10n.undo,
onPressed: controller.canUndo
? controller.undo
: null,
icon: Icons.undo,
),
_toolbarButton(
tooltip: context.l10n.redo,
onPressed: controller.canRedo
? controller.redo
: null,
icon: Icons.redo,
),
_toolbarButton(
tooltip: context.l10n.splitAtPlayhead,
onPressed: canSplitCaption
? () => _runCaptionEdit(
context,
() => _splitCaption(
sequenceId,
controller,
captionCues.single,
),
)
: controller.canCutSelection
? controller.cutSelectionAtPlayhead
: null,
icon: Icons.content_cut,
),
_toolbarButton(
key: const ValueKey('timeline-trim-left'),
tooltip: context.l10n.trimLeftTooltip,
onPressed: controller.canCutSelection
? controller.trimLeftAtPlayhead
: null,
icon: Icons.align_horizontal_left,
semanticLabel: context.l10n.trimLeft,
),
_toolbarButton(
key: const ValueKey('timeline-trim-right'),
tooltip: context.l10n.trimRightTooltip,
onPressed: controller.canCutSelection
? controller.trimRightAtPlayhead
: null,
icon: Icons.align_horizontal_right,
semanticLabel: context.l10n.trimRight,
),
_toolbarButton(
key: const ValueKey(
'timeline-delete-selection',
if (!AppTheme.isDesktop(context)) {
return SizedBox(
key: const Key('timeline-toolbar'),
height: 32,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.gap),
child: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: constraints.maxWidth,
),
child: IntrinsicWidth(
child: Row(
children: [
Row(
mainAxisSize: MainAxisSize.min,
spacing: AppSpacing.tiny,
children: [
_toolbarButton(
tooltip: context.l10n.undo,
onPressed: controller.canUndo
? controller.undo
: null,
icon: AppIcons.undo,
),
tooltip: context.l10n.deleteSelectedClips,
onPressed: () {
if (!controller.canDeleteSelection) return;
controller.deleteSelection();
},
icon: Icons.delete_outline,
),
],
),
const Spacer(),
_toolbarButton(
key: const ValueKey('timeline-fit'),
tooltip: context.l10n.fitTimeline,
semanticLabel: context.l10n.fitTimeline,
onPressed: controller.fitTimeline,
icon: Icons.fit_screen,
),
if (controller.commandRejection != null)
Tooltip(
message: controller.commandRejection!,
child: const Icon(Icons.info_outline),
_toolbarButton(
tooltip: context.l10n.redo,
onPressed: controller.canRedo
? controller.redo
: null,
icon: AppIcons.redo,
),
_toolbarButton(
tooltip: context.l10n.splitAtPlayhead,
onPressed: canSplitCaption
? () => _runCaptionEdit(
context,
() => _splitCaption(
sequenceId,
controller,
captionCues.single,
),
)
: controller.canCutSelection
? controller.cutSelectionAtPlayhead
: null,
icon: AppIcons.cut,
),
_toolbarButton(
key: const ValueKey('timeline-trim-left'),
tooltip: context.l10n.trimLeftTooltip,
onPressed: controller.canCutSelection
? controller.trimLeftAtPlayhead
: null,
icon: AppIcons.alignLeft,
semanticLabel: context.l10n.trimLeft,
),
_toolbarButton(
key: const ValueKey('timeline-trim-right'),
tooltip: context.l10n.trimRightTooltip,
onPressed: controller.canCutSelection
? controller.trimRightAtPlayhead
: null,
icon: AppIcons.alignRight,
semanticLabel: context.l10n.trimRight,
),
_toolbarButton(
key: const ValueKey(
'timeline-delete-selection',
),
tooltip: context.l10n.deleteSelectedClips,
onPressed: () {
if (!controller.canDeleteSelection) return;
controller.deleteSelection();
},
icon: AppIcons.delete,
),
],
),
],
const Spacer(),
_toolbarButton(
key: const ValueKey('timeline-fit'),
tooltip: context.l10n.fitTimeline,
semanticLabel: context.l10n.fitTimeline,
onPressed: controller.fitTimeline,
icon: AppIcons.fitContent,
),
if (controller.commandRejection != null)
Tooltip(
message: controller.commandRejection!,
child: const Icon(AppIcons.info),
),
],
),
),
),
),
),
),
);
}
return SizedBox(
key: const Key('timeline-toolbar'),
height: AppTheme.isDesktop(context)
? AppDesktopMetrics.timelineToolbar
: 32,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: AppCommandToolbar(
groups: [
[
AppToolbarCommand(
label: context.l10n.undo,
onPressed: controller.canUndo ? controller.undo : null,
icon: AppIcons.undo,
),
AppToolbarCommand(
label: context.l10n.redo,
onPressed: controller.canRedo ? controller.redo : null,
icon: AppIcons.redo,
),
],
[
AppToolbarCommand(
label: context.l10n.splitAtPlayhead,
onPressed: canSplitCaption
? () => _runCaptionEdit(
context,
() => _splitCaption(
sequenceId,
controller,
captionCues.single,
),
)
: controller.canCutSelection
? controller.cutSelectionAtPlayhead
: null,
icon: AppIcons.cut,
),
AppToolbarCommand(
key: const ValueKey('timeline-trim-left'),
label: context.l10n.trimLeftTooltip,
semanticLabel: context.l10n.trimLeft,
onPressed: controller.canCutSelection
? controller.trimLeftAtPlayhead
: null,
icon: AppIcons.alignLeft,
),
AppToolbarCommand(
key: const ValueKey('timeline-trim-right'),
label: context.l10n.trimRightTooltip,
semanticLabel: context.l10n.trimRight,
onPressed: controller.canCutSelection
? controller.trimRightAtPlayhead
: null,
icon: AppIcons.alignRight,
),
AppToolbarCommand(
key: const ValueKey('timeline-delete-selection'),
label: context.l10n.deleteSelectedClips,
onPressed: controller.canDeleteSelection
? controller.deleteSelection
: null,
icon: AppIcons.delete,
),
],
],
trailing: [
AppToolbarCommand(
key: const ValueKey('timeline-fit'),
label: context.l10n.fitTimeline,
semanticLabel: context.l10n.fitTimeline,
onPressed: controller.fitTimeline,
icon: AppIcons.fitContent,
),
],
status: controller.commandRejection == null
? null
: Tooltip(
message: controller.commandRejection!,
child: const Icon(AppIcons.info, size: 16),
),
),
),
);
},
@@ -863,9 +1046,7 @@ class _TimelineEditorState extends State<_TimelineEditor> {
label: restoreAudio
? context.l10n.restoreAudio
: context.l10n.detachAudio,
icon: restoreAudio
? Icons.volume_up_outlined
: Icons.audio_file_outlined,
icon: restoreAudio ? AppIcons.volume : AppIcons.audioFile,
onPressed:
session.acceptsEdits &&
detachTarget != null &&
@@ -895,12 +1076,12 @@ class _TimelineEditorState extends State<_TimelineEditor> {
),
AppMenuItem(
label: context.l10n.separateVocals,
icon: Icons.graphic_eq,
icon: AppIcons.audioWaveform,
onPressed: null,
),
AppMenuItem(
label: context.l10n.removeBackground,
icon: Icons.person_remove_outlined,
icon: AppIcons.removeBackground,
onPressed: backgroundRemovalTarget == null
? null
: () => showAppDialog<void>(
@@ -913,7 +1094,7 @@ class _TimelineEditorState extends State<_TimelineEditor> {
),
AppMenuItem(
label: context.l10n.generateCaptions,
icon: Icons.subtitles_outlined,
icon: AppIcons.subtitles,
onPressed: target == null
? null
: () => showAppDialog<void>(
@@ -926,7 +1107,7 @@ class _TimelineEditorState extends State<_TimelineEditor> {
),
AppMenuItem(
label: context.l10n.deleteSelectedClips,
icon: Icons.delete_outline,
icon: AppIcons.delete,
destructive: true,
onPressed: controller.canDeleteSelection
? controller.deleteSelection
@@ -941,9 +1122,10 @@ class _TimelineEditorState extends State<_TimelineEditor> {
Expanded(
child: Directionality(
textDirection: TextDirection.ltr,
child: TimelineViewport(
child: EditorTimelineViewport(
leadingPadding: AppSpacing.medium,
controller: controller,
rulerTimecodeLayout: widget.rulerTimecodeLayout,
child: TimelineAssetDropTarget(
projectId: projectId,
session: session,
@@ -975,8 +1157,15 @@ class _TimelineEditorState extends State<_TimelineEditor> {
controller: controller,
),
),
ListenableBuilder(
ListenableSelector<Object>(
listenable: controller.contentChanges,
select: () => (
controller.contentEndTick == 0,
controller.isDragging,
controller.geometry.primaryTop,
controller.geometry.primaryHeight,
controller.camera.verticalOffset,
),
builder: (context, _) =>
controller.contentEndTick == 0 &&
!controller.isDragging
@@ -0,0 +1,285 @@
import 'package:cutdex_sdk/timeline/engine.dart';
import 'package:cutdex_sdk/timeline/layout.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:cutdex_sdk/timeline_ui.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';
import '../../app/editor_theme.dart';
@Preview(
name: 'Full timecode — light',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget timecodeRulerLightPreview() => _preview(Brightness.light);
@Preview(
name: 'Full timecode — dark',
group: 'Desktop timeline',
size: Size(640, 152),
)
@Preview(
name: 'Full timecode — narrow',
group: 'Desktop timeline',
size: Size(320, 152),
)
Widget timecodeRulerDarkPreview() => _preview(Brightness.dark);
@Preview(
name: 'Full timecode — frame detail',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget timecodeRulerFramePreview() =>
_preview(Brightness.dark, frameDetail: true);
@Preview(
name: 'Full timecode — 29.97 drop frame',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget timecodeRulerDropFramePreview() => _preview(
Brightness.dark,
frameDetail: true,
format: TimelineFormat(
frameDuration: RationalTime(1001, 30000),
timecodeFormat: TimelineTimecodeFormat.dropFrame,
),
);
@Preview(
name: 'Centered timecode — light',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget centeredTimecodeRulerLightPreview() => _preview(
Brightness.light,
timecodeLayout: TimelineRulerTimecodeLayout.centered,
);
@Preview(
name: 'Centered timecode — dark',
group: 'Desktop timeline',
size: Size(640, 152),
)
@Preview(
name: 'Centered timecode — narrow',
group: 'Desktop timeline',
size: Size(320, 152),
)
Widget centeredTimecodeRulerDarkPreview() => _preview(
Brightness.dark,
timecodeLayout: TimelineRulerTimecodeLayout.centered,
);
@Preview(
name: 'Centered timecode — frame detail',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget centeredTimecodeRulerFramePreview() => _preview(
Brightness.dark,
frameDetail: true,
timecodeLayout: TimelineRulerTimecodeLayout.centered,
);
@Preview(
name: 'Overlay timecode — light',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget overlayTimecodeRulerLightPreview() => _preview(
Brightness.light,
timecodeLayout: TimelineRulerTimecodeLayout.overlay,
);
@Preview(
name: 'Overlay timecode — dark',
group: 'Desktop timeline',
size: Size(640, 152),
)
@Preview(
name: 'Overlay timecode — narrow',
group: 'Desktop timeline',
size: Size(320, 152),
)
Widget overlayTimecodeRulerDarkPreview() => _preview(
Brightness.dark,
timecodeLayout: TimelineRulerTimecodeLayout.overlay,
);
@Preview(
name: 'Overlay timecode — frame detail',
group: 'Desktop timeline',
size: Size(640, 152),
)
Widget overlayTimecodeRulerFramePreview() => _preview(
Brightness.dark,
frameDetail: true,
timecodeLayout: TimelineRulerTimecodeLayout.overlay,
);
Widget _preview(
Brightness brightness, {
bool frameDetail = false,
TimelineFormat? format,
TimelineRulerTimecodeLayout timecodeLayout =
TimelineRulerTimecodeLayout.inline,
}) => MaterialApp(
debugShowCheckedModeBanner: false,
theme: EditorTheme.desktop(
EditorTheme.forPalette(AppPalette.graphite, brightness),
),
home: Scaffold(
body: _RulerPreview(
format: format ?? TimelineFormat.fps30,
frameDetail: frameDetail,
timecodeLayout: timecodeLayout,
),
),
);
class _RulerPreview extends StatefulWidget {
const _RulerPreview({
required this.format,
required this.frameDetail,
required this.timecodeLayout,
});
final TimelineFormat format;
final bool frameDetail;
final TimelineRulerTimecodeLayout timecodeLayout;
@override
State<_RulerPreview> createState() => _RulerPreviewState();
}
class _RulerPreviewState extends State<_RulerPreview> {
late final TimelineViewController _controller;
static const _width = 640.0;
@override
void initState() {
super.initState();
final duration = RationalTime.seconds(widget.frameDetail ? 60 : 15);
final kernel = TimelineKernel.importDto(
TimelineDto(
id: SequenceId('ruler-preview'),
format: widget.format,
primaryStorylineId: StorylineId('primary'),
storylines: [
StorylineDto(
id: StorylineId('primary'),
elementIds: [ElementId('intro'), ElementId('main')],
),
],
elements: [
for (final (id, name) in [('intro', 'Intro'), ('main', 'Main shot')])
ElementDto(
id: ElementId(id),
name: name,
structure: ElementStructure.content,
sourceRange: TimeRange(
start: RationalTime.zero,
duration: duration,
),
duration: duration,
),
],
),
);
final projection = const TimelineLayoutSceneBuilder().project(
version: kernel.current,
stacks: const [],
appearance: (_, _, _) => throw StateError('no connections'),
);
final layout = TimelineLayoutEngine(kernel: kernel).initializeProjection(
kernel: kernel,
projection: projection,
policy: LayoutPolicy(version: 1, stacks: const []),
);
final camera = TimelineCamera(
baseTick: widget.frameDetail ? 59 * TimelineClock.ticksPerSecond : 0,
pixelsPerTick: widget.frameDetail
? 12 / widget.format.frameGrid.quantumTicks
: 30 / TimelineClock.ticksPerSecond,
);
_controller =
TimelineViewController(
version: layout.version,
storyline: kernel.current.query().primaryStoryline,
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 48),
format: widget.format,
camera: camera,
)..restoreViewState(
playheadTick: widget.frameDetail
? (widget.format.frameDuration.denominator /
widget.format.frameDuration.numerator)
.round() *
60 *
widget.format.frameGrid.quantumTicks
: 10 * TimelineClock.ticksPerSecond,
camera: camera,
);
}
void _zoom(double scale, double width) => _controller.zoomBy(
scale: scale,
viewport: TimelineViewportRect(width: width, height: 88),
);
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
final width = constraints.hasBoundedWidth ? constraints.maxWidth : _width;
return Column(
children: [
SizedBox(
height: AppDesktopMetrics.timelineToolbar,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: [
const Text('Timeline ruler'),
const Spacer(),
IconButton(
tooltip: 'Zoom out',
onPressed: () => _zoom(1 / 1.4, width),
icon: const Icon(AppIcons.remove, size: 16),
),
IconButton(
tooltip: 'Zoom in',
onPressed: () => _zoom(1.4, width),
icon: const Icon(AppIcons.add, size: 16),
),
IconButton(
tooltip: 'Fit timeline',
onPressed: _controller.fitTimeline,
icon: const Icon(AppIcons.fitContent, size: 16),
),
],
),
),
),
Expanded(
child: TimelineViewport(
controller: _controller,
rulerStyle: TimelineRulerStyle.timecode,
rulerTimecodeLayout: widget.timecodeLayout,
child: TimelineView(controller: _controller),
),
),
],
);
},
);
}
@@ -1,3 +1,5 @@
import '../../shared/widgets/listenable_selector.dart';
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import 'dart:math' as math;
@@ -89,87 +91,91 @@ class TimelineSpeedEditor extends StatelessWidget {
}
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: Listenable.merge([session, controller.contentChanges]),
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
final frame = controller.project(
TimelineViewportRect(
width: constraints.maxWidth,
height: constraints.maxHeight,
),
);
final query = frame.version.kernelVersion.query();
final viewportBounds =
Offset.zero & Size(constraints.maxWidth, constraints.maxHeight);
final bars = <Widget>[];
void addHeader(
ElementHandle handle,
TimelineClipLayout clipLayout, {
bool ghost = false,
}) {
final record = query.element(handle);
if (!session.isCustomSpeedEnabled(sequence, record.id)) return;
final segments = session.clipSpeedSegments(record);
if (segments == null) return;
final layout = TimelineSpeedLayout(
clip: clipLayout,
segments: segments,
pixelsPerTick: controller.camera.pixelsPerTick,
Widget build(BuildContext context) => ListenableSelector<Object>(
listenable: session,
select: () => (session.version, session.acceptsEdits),
builder: (context, _) => ListenableBuilder(
listenable: controller.contentChanges,
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
final frame = controller.project(
TimelineViewportRect(
width: constraints.maxWidth,
height: constraints.maxHeight,
),
);
final bounds = clipLayout.toViewport(layout.bounds);
if (bounds.isEmpty || !bounds.overlaps(viewportBounds)) {
return;
}
bars.add(
Positioned(
key: ValueKey((sequence, record.id)),
left: bounds.left,
top: bounds.top,
width: bounds.width,
height: bounds.height,
child: IgnorePointer(
ignoring: ghost,
child: _ClipSpeedEditor(
session: session,
sequence: sequence,
clip: record.id,
controller: controller,
layout: layout,
final query = frame.version.kernelVersion.query();
final viewportBounds =
Offset.zero & Size(constraints.maxWidth, constraints.maxHeight);
final bars = <Widget>[];
void addHeader(
ElementHandle handle,
TimelineClipLayout clipLayout, {
bool ghost = false,
}) {
final record = query.element(handle);
if (!session.isCustomSpeedEnabled(sequence, record.id)) return;
final segments = session.clipSpeedSegments(record);
if (segments == null) return;
final layout = TimelineSpeedLayout(
clip: clipLayout,
segments: segments,
pixelsPerTick: controller.camera.pixelsPerTick,
);
final bounds = clipLayout.toViewport(layout.bounds);
if (bounds.isEmpty || !bounds.overlaps(viewportBounds)) {
return;
}
bars.add(
Positioned(
key: ValueKey((sequence, record.id)),
left: bounds.left,
top: bounds.top,
width: bounds.width,
height: bounds.height,
child: IgnorePointer(
ignoring: ghost,
child: _ClipSpeedEditor(
session: session,
sequence: sequence,
clip: record.id,
controller: controller,
layout: layout,
),
),
),
),
);
}
for (var index = 0; index < frame.length; index++) {
if (frame.kindAt(index) == TimelineViewportItemKind.transition) {
continue;
);
}
final identity = frame.identityAt(index);
final handle = controller.elementForIdentity(identity);
if (handle == null) continue;
final bodyId = identity is LayoutBodyId
? identity
: LayoutBodyId.element(handle);
// The resident item is a landing reservation while the moving clip
// is painted separately at its pointer-following ghost coordinates.
if (controller.dragGhostFor(bodyId) != null) continue;
addHeader(handle, controller.clipLayoutAt(frame, index));
}
for (final ghost in controller.dragGhosts) {
final body = ghost.body;
addHeader(
body.id.owner,
controller.clipLayout(
controller.dragGhostBounds(ghost, frame.viewport),
owner: body.id.owner,
),
ghost: true,
);
}
return Stack(clipBehavior: Clip.none, children: bars);
},
for (var index = 0; index < frame.length; index++) {
if (frame.kindAt(index) == TimelineViewportItemKind.transition) {
continue;
}
final identity = frame.identityAt(index);
final handle = controller.elementForIdentity(identity);
if (handle == null) continue;
final bodyId = identity is LayoutBodyId
? identity
: LayoutBodyId.element(handle);
// The resident item is a landing reservation while the moving clip
// is painted separately at its pointer-following ghost coordinates.
if (controller.dragGhostFor(bodyId) != null) continue;
addHeader(handle, controller.clipLayoutAt(frame, index));
}
for (final ghost in controller.dragGhosts) {
final body = ghost.body;
addHeader(
body.id.owner,
controller.clipLayout(
controller.dragGhostBounds(ghost, frame.viewport),
owner: body.id.owner,
),
ghost: true,
);
}
return Stack(clipBehavior: Clip.none, children: bars);
},
),
),
);
}