feat(workspace): add workflow navigation and resizable desktop panels
This commit is contained in:
1 parent
02413383d8
commit
1acfe4a005
17 files changed
+1893
-162
No files matched your search
@@ -0,0 +1,264 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex/app/app.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/integrations/platform/device_experience.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/settings/view_settings_repositories.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/view_settings.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
import '../test/support/empty_conversation_repository.dart';
|
||||
import '../test/support/preview_fixture.dart';
|
||||
|
||||
/// Run with flutter drive --profile on macOS and test_driver/integration_test.dart.
|
||||
/// Define CUTDEX_RESIZE_SOURCE (an image) and CUTDEX_RESIZE_REPORT (JSON output).
|
||||
/// Widget-test timings are not comparable to these real-engine measurements.
|
||||
void main() {
|
||||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
||||
const source = String.fromEnvironment('CUTDEX_RESIZE_SOURCE');
|
||||
const output = String.fromEnvironment('CUTDEX_RESIZE_REPORT');
|
||||
const rounds = int.fromEnvironment('CUTDEX_RESIZE_ROUNDS', defaultValue: 3);
|
||||
const inputHz = 120;
|
||||
const inputCount = 240;
|
||||
const clipCount = 64;
|
||||
const assetCount = 100;
|
||||
|
||||
testWidgets('profile full desktop workspace split and junction dragging', (
|
||||
tester,
|
||||
) async {
|
||||
expect(kProfileMode, isTrue, reason: 'Use flutter drive --profile');
|
||||
expect(Platform.isMacOS, isTrue);
|
||||
expect(await File(source).exists(), isTrue);
|
||||
final ids = List.generate(clipCount, (i) => ElementId('clip-$i'));
|
||||
final fixture = await createPreviewFixture(
|
||||
File(source).uri,
|
||||
mediaType: 'image',
|
||||
renderSize: {'width': 1280, 'height': 720},
|
||||
timelineOverride: TimelineDto(
|
||||
id: SequenceId('one'),
|
||||
name: 'Resize profiling',
|
||||
format: TimelineFormat.fps30,
|
||||
primaryStorylineId: StorylineId('primary'),
|
||||
storylines: [StorylineDto(id: StorylineId('primary'), elementIds: ids)],
|
||||
elements: [
|
||||
for (final (i, id) in ids.indexed)
|
||||
ElementDto(
|
||||
id: id,
|
||||
name: 'Clip $i',
|
||||
structure: ElementStructure.content,
|
||||
payloadRef: PayloadRef('source'),
|
||||
duration: RationalTime.seconds(2),
|
||||
sourceRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(2),
|
||||
),
|
||||
mediaRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(2),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
for (var i = 0; i < assetCount; i++) {
|
||||
await fixture.workspace.project!.saveAsset(
|
||||
AssetDocument(
|
||||
id: i == 0 ? 'media' : 'media-$i',
|
||||
name: 'Image $i',
|
||||
storage: AssetStorage.external,
|
||||
location: File(source).uri.toString(),
|
||||
metadata: {'kind': 'image'},
|
||||
),
|
||||
);
|
||||
}
|
||||
final projectPath = '${fixture.directory.path}/Preview.cutdex';
|
||||
await fixture.workspace.close();
|
||||
final database = AppDatabase(
|
||||
NativeDatabase(File('${fixture.directory.path}/settings.sqlite')),
|
||||
);
|
||||
final workspaceWrites = _CountWorkspaceWrites(
|
||||
DriftWorkspaceViewSettingsRepository(database),
|
||||
);
|
||||
final projectWrites = _CountProjectWrites(
|
||||
DriftProjectViewSettingsRepository(database),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
appDatabaseProvider.overrideWithValue(database),
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
workspaceViewSettingsRepositoryProvider.overrideWithValue(
|
||||
workspaceWrites,
|
||||
),
|
||||
projectViewSettingsRepositoryProvider.overrideWithValue(projectWrites),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(() async {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await container.read(projectsProvider.notifier).prepareToQuit();
|
||||
container.dispose();
|
||||
await database.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
});
|
||||
await container.read(workspaceViewSettingsProvider.future);
|
||||
container
|
||||
.read(workspaceViewSettingsProvider.notifier)
|
||||
.setMode(WorkspaceMode.cut);
|
||||
expect(
|
||||
await container.read(projectsProvider.notifier).open(projectPath),
|
||||
isTrue,
|
||||
);
|
||||
// This is the normal app/router/editor, with only isolated storage and chat.
|
||||
// ignore: riverpod_lint/provider_scope_placement
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
||||
);
|
||||
await const MethodChannel('cutdex_native/window')
|
||||
.invokeMethod<void>('toggleMaximize');
|
||||
final readyClock = Stopwatch()..start();
|
||||
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
|
||||
while (junction.evaluate().isEmpty) {
|
||||
if (readyClock.elapsed.inSeconds > 60) {
|
||||
throw TimeoutException('Desktop editor did not open');
|
||||
}
|
||||
await tester.pump();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 16));
|
||||
}
|
||||
await Future<void>.delayed(const Duration(seconds: 3));
|
||||
final size = tester.view.physicalSize / tester.view.devicePixelRatio;
|
||||
expect(size.width, greaterThan(1100));
|
||||
final results = <String, dynamic>{
|
||||
'mode': 'profile',
|
||||
'platform': Platform.operatingSystemVersion,
|
||||
'logicalSize': [size.width, size.height],
|
||||
'pixelRatio': tester.view.devicePixelRatio,
|
||||
'displayRefreshHz': tester.view.display.refreshRate,
|
||||
'inputHz': inputHz,
|
||||
'inputsPerDrag': inputCount,
|
||||
'clips': clipCount,
|
||||
'assets': assetCount,
|
||||
'scope': 'Full app, native still-image preview, file-backed SQLite; synthetic mouse input',
|
||||
'runs': <Map<String, dynamic>>[],
|
||||
};
|
||||
final report = File(output);
|
||||
await report.parent.create(recursive: true);
|
||||
Future<void> save() => report.writeAsString(
|
||||
const JsonEncoder.withIndent(' ').convert(results),
|
||||
);
|
||||
await save();
|
||||
const scenarios = {
|
||||
'sidebar': ('project-sidebar-resize', Offset(55, 0)),
|
||||
'media': ('editor-media-resize', Offset(65, 0)),
|
||||
'timeline': ('editor-timeline-resize', Offset(0, 80)),
|
||||
'mediaJunction': ('editor-media-timeline-junction', Offset(65, 80)),
|
||||
'chatJunction': ('desktop-chat-timeline-junction', Offset(55, 80)),
|
||||
};
|
||||
for (var round = 0; round < rounds; round++) {
|
||||
for (final entry in scenarios.entries) {
|
||||
final (key, amplitude) = entry.value;
|
||||
final reportKey = '${entry.key}-$round';
|
||||
final start = tester.getCenter(find.byKey(Key(key)));
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: start);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
final writesBefore = workspaceWrites.count;
|
||||
final projectWritesBefore = projectWrites.count;
|
||||
final dispatchTimes = <int>[];
|
||||
await binding.watchPerformance(() async {
|
||||
await mouse.down(start);
|
||||
final clock = Stopwatch()..start();
|
||||
for (var i = 1; i <= inputCount; i++) {
|
||||
final dueUs = (i * 1000000 / inputHz).round();
|
||||
final waitUs = dueUs - clock.elapsedMicroseconds;
|
||||
if (waitUs > 0) {
|
||||
await Future<void>.delayed(Duration(microseconds: waitUs));
|
||||
}
|
||||
final dispatch = Stopwatch()..start();
|
||||
await mouse.moveTo(
|
||||
start + amplitude * math.sin(2 * math.pi * i / inputCount),
|
||||
);
|
||||
dispatchTimes.add(dispatch.elapsedMicroseconds);
|
||||
}
|
||||
await mouse.up();
|
||||
await mouse.removePointer();
|
||||
}, reportKey: reportKey);
|
||||
// Allow queued persistence writes and batched engine timings to arrive.
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
final timings = Map<String, dynamic>.from(
|
||||
binding.reportData![reportKey] as Map,
|
||||
);
|
||||
final build = List<int>.from(timings['frame_build_times'] as List);
|
||||
final raster = List<int>.from(
|
||||
timings['frame_rasterizer_times'] as List,
|
||||
);
|
||||
int overBudget(int budgetUs) => List.generate(
|
||||
build.length,
|
||||
(i) => i,
|
||||
).where((i) => build[i] > budgetUs || raster[i] > budgetUs).length;
|
||||
final row = <String, dynamic>{
|
||||
'scenario': entry.key,
|
||||
'round': round,
|
||||
'workspaceWrites': workspaceWrites.count - writesBefore,
|
||||
'projectWrites': projectWrites.count - projectWritesBefore,
|
||||
'over16ms': overBudget(16667),
|
||||
'over8ms': overBudget(8333),
|
||||
'dispatchUs': dispatchTimes,
|
||||
'timings': timings,
|
||||
};
|
||||
(results['runs'] as List).add(row);
|
||||
await save();
|
||||
debugPrint(
|
||||
'RESIZE_PROFILE ${entry.key} $round frames=${build.length} '
|
||||
'over16ms=${row['over16ms']} writes=${row['workspaceWrites']}',
|
||||
);
|
||||
}
|
||||
}
|
||||
results['status'] = 'passed';
|
||||
await save();
|
||||
expect(tester.takeException(), isNull);
|
||||
}, skip: !Platform.isMacOS || source.isEmpty || output.isEmpty);
|
||||
}
|
||||
|
||||
class _CountWorkspaceWrites implements WorkspaceViewSettingsRepository {
|
||||
_CountWorkspaceWrites(this.delegate);
|
||||
final WorkspaceViewSettingsRepository delegate;
|
||||
int count = 0;
|
||||
@override
|
||||
Future<WorkspaceViewSettingsData> load() => delegate.load();
|
||||
@override
|
||||
Future<void> save(WorkspaceViewSettingsData settings) {
|
||||
count++;
|
||||
return delegate.save(settings);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountProjectWrites implements ProjectViewSettingsRepository {
|
||||
_CountProjectWrites(this.delegate);
|
||||
final ProjectViewSettingsRepository delegate;
|
||||
int count = 0;
|
||||
@override
|
||||
Future<ProjectViewSettingsData> load(String id) => delegate.load(id);
|
||||
@override
|
||||
Future<void> save(String id, ProjectViewSettingsData settings) {
|
||||
count++;
|
||||
return delegate.save(id, settings);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
enum DesktopContent { workspace, library, resourceLibrary, settings }
|
||||
enum DesktopContent { workspace, library, resourceLibrary, workflow, settings }
|
||||
|
||||
typedef DesktopContentSelection = ({
|
||||
DesktopContent surface,
|
||||
|
||||
@@ -17,9 +17,9 @@ class DesktopWindowFrame extends StatelessWidget {
|
||||
this.projectTabs,
|
||||
this.headerTrailing = const SizedBox.shrink(),
|
||||
this.settingsSelected = false,
|
||||
this.resourceLibrarySelected = false,
|
||||
this.onResourceLibraryPressed,
|
||||
this.workflowSelected = false,
|
||||
required this.onHomePressed,
|
||||
required this.onWorkflowPressed,
|
||||
required this.onSettingsPressed,
|
||||
required this.child,
|
||||
});
|
||||
@@ -35,9 +35,9 @@ class DesktopWindowFrame extends StatelessWidget {
|
||||
final Widget? projectTabs;
|
||||
final Widget headerTrailing;
|
||||
final bool settingsSelected;
|
||||
final bool resourceLibrarySelected;
|
||||
final VoidCallback? onResourceLibraryPressed;
|
||||
final bool workflowSelected;
|
||||
final VoidCallback onHomePressed;
|
||||
final VoidCallback onWorkflowPressed;
|
||||
final VoidCallback onSettingsPressed;
|
||||
final Widget child;
|
||||
|
||||
@@ -119,69 +119,87 @@ class DesktopWindowFrame extends StatelessWidget {
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
if (projectTabs == null)
|
||||
SizedBox(
|
||||
key: const Key('desktop-navigation-rail'),
|
||||
width: railWidth,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.maxHeight,
|
||||
),
|
||||
child: IntrinsicHeight(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final section in [0, 2])
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: IconButton.filledTonal(
|
||||
key: ValueKey(switch (section) {
|
||||
0 => 'desktop-rail-home',
|
||||
_ => 'desktop-rail-resources',
|
||||
}),
|
||||
tooltip: switch (section) {
|
||||
0 => context.l10n.navigationHome,
|
||||
_ => context.l10n.navigationLibrary,
|
||||
},
|
||||
IconButton.filledTonal(
|
||||
key: const ValueKey('desktop-rail-home'),
|
||||
tooltip: context.l10n.navigationHome,
|
||||
isSelected:
|
||||
!settingsSelected &&
|
||||
(section == 2
|
||||
? resourceLibrarySelected
|
||||
: !resourceLibrarySelected),
|
||||
!settingsSelected && !workflowSelected,
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(railButtonSize),
|
||||
maximumSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(
|
||||
railButtonSize,
|
||||
),
|
||||
maximumSize: const Size.square(
|
||||
railButtonSize,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: railIconSize,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
tapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
backgroundColor:
|
||||
!settingsSelected &&
|
||||
(section == 2
|
||||
? resourceLibrarySelected
|
||||
: !resourceLibrarySelected)
|
||||
settingsSelected || workflowSelected
|
||||
? Colors.transparent
|
||||
: null,
|
||||
),
|
||||
onPressed: onHomePressed,
|
||||
icon: const Icon(AppIcons.home),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
IconButton.filledTonal(
|
||||
key: const ValueKey('desktop-rail-workflow'),
|
||||
tooltip: context.l10n.workflow,
|
||||
isSelected: workflowSelected,
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(
|
||||
railButtonSize,
|
||||
),
|
||||
maximumSize: const Size.square(
|
||||
railButtonSize,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: railIconSize,
|
||||
tapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
backgroundColor: workflowSelected
|
||||
? null
|
||||
: Colors.transparent,
|
||||
),
|
||||
onPressed: switch (section) {
|
||||
0 => onHomePressed,
|
||||
_ => onResourceLibraryPressed,
|
||||
},
|
||||
icon: Icon(switch (section) {
|
||||
0 => AppIcons.home,
|
||||
_ => AppIcons.folder,
|
||||
}),
|
||||
),
|
||||
onPressed: onWorkflowPressed,
|
||||
icon: const Icon(AppIcons.timeline),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
key: const Key('project-settings-button'),
|
||||
key: const Key('desktop-rail-settings'),
|
||||
tooltip: context.l10n.settings,
|
||||
isSelected: settingsSelected,
|
||||
onPressed: onSettingsPressed,
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(railButtonSize),
|
||||
maximumSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(
|
||||
railButtonSize,
|
||||
),
|
||||
maximumSize: const Size.square(
|
||||
railButtonSize,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: railIconSize,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
tapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
icon: const Icon(AppIcons.settings),
|
||||
),
|
||||
@@ -189,20 +207,21 @@ class DesktopWindowFrame extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: projectTabs == null ? 0 : contentInset,
|
||||
padding: const EdgeInsets.only(
|
||||
left: contentInset,
|
||||
right: contentInset,
|
||||
bottom: contentInset,
|
||||
),
|
||||
child: SizedBox(
|
||||
key: const Key('desktop-content-container'),
|
||||
child: WindowHeaderPane(
|
||||
offset: Offset(
|
||||
projectTabs == null ? railWidth : contentInset,
|
||||
headerHeight,
|
||||
),
|
||||
offset: const Offset(railWidth + contentInset, headerHeight),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
constraints.maxWidth < 200
|
||||
|
||||
@@ -32,6 +32,11 @@ class DesktopWorkspaceShell extends StatefulWidget {
|
||||
required this.scaffoldKey,
|
||||
required this.navigationDrawer,
|
||||
this.projectTabsLayout = false,
|
||||
this.timelineHeight,
|
||||
this.onTimelineHeightChanged,
|
||||
this.onJunctionResizeEnd,
|
||||
this.onSidebarResizeEnd,
|
||||
this.sidebarCanExpand = true,
|
||||
});
|
||||
|
||||
static const gutterWidth = WorkspaceLayoutMetrics.desktopSpacing;
|
||||
@@ -47,12 +52,53 @@ class DesktopWorkspaceShell extends StatefulWidget {
|
||||
final GlobalKey<ScaffoldState> scaffoldKey;
|
||||
final Widget navigationDrawer;
|
||||
final bool projectTabsLayout;
|
||||
final double? timelineHeight;
|
||||
final ValueChanged<double>? onTimelineHeightChanged;
|
||||
final VoidCallback? onJunctionResizeEnd;
|
||||
final VoidCallback? onSidebarResizeEnd;
|
||||
final bool sidebarCanExpand;
|
||||
|
||||
@override
|
||||
State<DesktopWorkspaceShell> createState() => _DesktopWorkspaceShellState();
|
||||
}
|
||||
|
||||
class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
double? _sidebarRestoreWidth;
|
||||
bool _sidebarJunctionDragging = false;
|
||||
|
||||
void _startSidebarResize(double width, {bool junction = false}) {
|
||||
_sidebarRestoreWidth = width;
|
||||
if (junction) setState(() => _sidebarJunctionDragging = true);
|
||||
}
|
||||
|
||||
void _resizeSidebar(double requestedWidth, double maximum) {
|
||||
if (!widget.sidebarCanExpand || widget.controller.agentFloating) return;
|
||||
if (requestedWidth < WorkspaceLayoutMetrics.sidebarSnapThreshold) {
|
||||
if (!widget.sidebarCollapsed) {
|
||||
final restoreWidth = _sidebarRestoreWidth;
|
||||
if (restoreWidth != null && widget.sidebarWidth != restoreWidth) {
|
||||
widget.onSidebarWidthChanged(restoreWidth);
|
||||
}
|
||||
widget.onSidebarCollapsedChanged(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (widget.sidebarCollapsed) widget.onSidebarCollapsedChanged(false);
|
||||
widget.onSidebarWidthChanged(
|
||||
requestedWidth.clamp(WorkspaceLayoutMetrics.sidebarMinimumWidth, maximum),
|
||||
);
|
||||
}
|
||||
|
||||
void _finishSidebarResize() {
|
||||
_sidebarRestoreWidth = null;
|
||||
if (_sidebarJunctionDragging) {
|
||||
setState(() => _sidebarJunctionDragging = false);
|
||||
widget.onJunctionResizeEnd?.call();
|
||||
} else {
|
||||
widget.onSidebarResizeEnd?.call();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -64,6 +110,11 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
@override
|
||||
void didUpdateWidget(covariant DesktopWorkspaceShell oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.controller.agentFloating ||
|
||||
!widget.sidebarCanExpand ||
|
||||
widget.onTimelineHeightChanged == null) {
|
||||
_sidebarJunctionDragging = false;
|
||||
}
|
||||
if (oldWidget.controller != widget.controller) {
|
||||
oldWidget.controller.removeListener(_changed);
|
||||
widget.controller.addListener(_changed);
|
||||
@@ -85,6 +136,9 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
required ValueChanged<double> onResize,
|
||||
double direction = 1,
|
||||
VoidCallback? onEnd,
|
||||
VoidCallback? onStart,
|
||||
Set<WorkspaceResizeBoundary> highlightTargets = const {},
|
||||
Offset highlightOffset = Offset.zero,
|
||||
}) => SizedBox(
|
||||
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
height: double.infinity,
|
||||
@@ -95,11 +149,17 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
direction: direction,
|
||||
onResize: onResize,
|
||||
onEnd: onEnd,
|
||||
onStart: onStart,
|
||||
highlightTargets: highlightTargets,
|
||||
highlightOffset: highlightOffset,
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => widget.projectTabsLayout
|
||||
Widget build(BuildContext context) =>
|
||||
WorkspaceResizeHighlightScope(child: _workspace(context));
|
||||
|
||||
Widget _workspace(BuildContext context) => widget.projectTabsLayout
|
||||
? _projectWorkspace(context)
|
||||
: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
@@ -164,6 +224,7 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
|
||||
return Scaffold(
|
||||
key: widget.scaffoldKey,
|
||||
drawerEnableOpenDragGesture: false,
|
||||
backgroundColor: Colors.transparent,
|
||||
drawer: Drawer(
|
||||
width: 320,
|
||||
@@ -317,6 +378,12 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
.toDouble();
|
||||
final floating = widget.controller.agentFloating;
|
||||
final collapsed = widget.sidebarCollapsed || floating;
|
||||
double resolveTimelineHeight(double? height) =>
|
||||
WorkspaceLayoutMetrics.resolveTimelineHeight(
|
||||
constraints.maxHeight,
|
||||
height,
|
||||
);
|
||||
final timelineHeight = resolveTimelineHeight(widget.timelineHeight);
|
||||
final geometry = DesktopWorkspaceGeometry(
|
||||
sidebarWidth: sidebarWidth,
|
||||
agentWidth: 0,
|
||||
@@ -324,6 +391,7 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
);
|
||||
return Scaffold(
|
||||
key: widget.scaffoldKey,
|
||||
drawerEnableOpenDragGesture: false,
|
||||
backgroundColor: Colors.transparent,
|
||||
drawer: Drawer(
|
||||
width: 320,
|
||||
@@ -356,20 +424,64 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!collapsed)
|
||||
if (!floating &&
|
||||
widget.sidebarCanExpand &&
|
||||
WorkspaceLayoutPolicy.desktopNavigationFits(width))
|
||||
Positioned(
|
||||
left: sidebarWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
left: collapsed
|
||||
? 0
|
||||
: sidebarWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
child: _gutter(
|
||||
name: 'project-sidebar',
|
||||
initialWidth: sidebarWidth,
|
||||
onResize: (value) => widget.onSidebarWidthChanged(
|
||||
value.clamp(
|
||||
WorkspaceLayoutMetrics.sidebarMinimumWidth,
|
||||
maximum,
|
||||
highlightTargets: const {WorkspaceResizeBoundary.sidebar},
|
||||
highlightOffset: collapsed
|
||||
? const Offset(
|
||||
-WorkspaceLayoutMetrics.desktopResizeHitExtent / 2,
|
||||
0,
|
||||
)
|
||||
: Offset.zero,
|
||||
initialWidth: collapsed ? 0 : sidebarWidth,
|
||||
onStart: () => _startSidebarResize(sidebarWidth),
|
||||
onResize: (value) => _resizeSidebar(value, maximum),
|
||||
onEnd: _finishSidebarResize,
|
||||
),
|
||||
),
|
||||
if (!floating &&
|
||||
widget.sidebarCanExpand &&
|
||||
WorkspaceLayoutPolicy.desktopNavigationFits(width) &&
|
||||
widget.onTimelineHeightChanged != null)
|
||||
Positioned(
|
||||
left: collapsed
|
||||
? 0
|
||||
: sidebarWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
bottom:
|
||||
timelineHeight - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
height: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
child: WorkspaceResizeHandle.junction(
|
||||
key: const Key('desktop-chat-timeline-junction'),
|
||||
highlightOffset: collapsed
|
||||
? const Offset(
|
||||
-WorkspaceLayoutMetrics.desktopResizeHitExtent / 2,
|
||||
0,
|
||||
)
|
||||
: Offset.zero,
|
||||
highlightTargets: const {
|
||||
WorkspaceResizeBoundary.sidebar,
|
||||
WorkspaceResizeBoundary.timeline,
|
||||
},
|
||||
initialWidth: collapsed ? 0 : sidebarWidth,
|
||||
initialHeight: timelineHeight,
|
||||
verticalDirection: -1,
|
||||
onStart: () =>
|
||||
_startSidebarResize(sidebarWidth, junction: true),
|
||||
onWidthChanged: (value) => _resizeSidebar(value, maximum),
|
||||
onHeightChanged: (value) => widget.onTimelineHeightChanged!(
|
||||
resolveTimelineHeight(value),
|
||||
),
|
||||
onEnd: _finishSidebarResize,
|
||||
),
|
||||
),
|
||||
if (floating)
|
||||
|
||||
@@ -80,7 +80,6 @@ class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
||||
ProjectViewSettings get _viewController =>
|
||||
ref.read(projectViewSettingsProvider(widget.projectId).notifier);
|
||||
bool get _propertiesOpen => _viewSettings.propertiesOpen;
|
||||
double? get _timelineHeight => _viewSettings.timelineHeight;
|
||||
|
||||
void _saveViewSettings() {
|
||||
if (widget.projectId.isEmpty ||
|
||||
@@ -93,7 +92,8 @@ class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewSettings = ref.watch(
|
||||
projectViewSettingsProvider(widget.projectId),
|
||||
projectViewSettingsProvider(widget.projectId)
|
||||
.select((value) => (value.hasValue, value.value?.propertiesOpen)),
|
||||
);
|
||||
final preview = KeyedSubtree(
|
||||
key: _previewKey,
|
||||
@@ -205,10 +205,15 @@ class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
||||
if (desktop) mediaButton,
|
||||
Expanded(
|
||||
child: desktop
|
||||
? _PreviewHeaderTitle(
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: _PreviewHeaderTitle(
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
pending: _timelinePending,
|
||||
),
|
||||
)
|
||||
: widget.showProjectName
|
||||
? Row(
|
||||
@@ -249,7 +254,7 @@ class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
||||
? context.l10n.collapseProperties
|
||||
: context.l10n.expandProperties,
|
||||
isSelected: propertiesOpen,
|
||||
onPressed: !viewSettings.hasValue
|
||||
onPressed: !viewSettings.$1
|
||||
? null
|
||||
: () {
|
||||
if (desktop) {
|
||||
@@ -285,23 +290,40 @@ class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
||||
),
|
||||
),
|
||||
);
|
||||
Widget dockedEditing({required bool showTools}) =>
|
||||
ExpandedEditorLayout(
|
||||
Widget dockedEditing({required bool showTools}) => Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final dimensions = ref.watch(
|
||||
projectViewSettingsProvider(widget.projectId).select(
|
||||
(value) =>
|
||||
(value.value?.mediaWidth, value.value?.timelineHeight),
|
||||
),
|
||||
);
|
||||
return ExpandedEditorLayout(
|
||||
preview: preview,
|
||||
header: header,
|
||||
properties: properties,
|
||||
media: media,
|
||||
showMedia: dockMedia,
|
||||
showProperties: showTools && dockProperties,
|
||||
timelineHeight: _timelineHeight,
|
||||
mediaWidth: dimensions.$1,
|
||||
onMediaWidthChanged: (width) {
|
||||
if (viewSettings.$1) {
|
||||
_viewController.setMediaWidth(width);
|
||||
}
|
||||
},
|
||||
onMediaWidthChangeEnd: _saveViewSettings,
|
||||
timelineHeight: dimensions.$2,
|
||||
onTimelineHeightChanged: (height) {
|
||||
if (viewSettings.hasValue) {
|
||||
if (viewSettings.$1) {
|
||||
_viewController.setTimelineHeight(height);
|
||||
}
|
||||
},
|
||||
onTimelineHeightChangeEnd: _saveViewSettings,
|
||||
onJunctionResizeEnd: _saveViewSettings,
|
||||
timeline: timeline,
|
||||
);
|
||||
},
|
||||
);
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
|
||||
@@ -32,7 +32,7 @@ class EditorTimelineDefaults extends StatelessWidget {
|
||||
: 26,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: AppTheme.isDesktop(context) ? AppSpacing.tiny : 0,
|
||||
horizontal: AppTheme.isDesktop(context) ? AppSpacing.small : 0,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -90,7 +90,9 @@ class EditorTimelineDefaults extends StatelessWidget {
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.medium,
|
||||
),
|
||||
child: AppCommandToolbar(
|
||||
groups: [
|
||||
[
|
||||
|
||||
@@ -15,9 +15,13 @@ class ExpandedEditorLayout extends StatefulWidget {
|
||||
required this.media,
|
||||
required this.showMedia,
|
||||
required this.showProperties,
|
||||
required this.mediaWidth,
|
||||
required this.onMediaWidthChanged,
|
||||
required this.onMediaWidthChangeEnd,
|
||||
required this.timelineHeight,
|
||||
required this.onTimelineHeightChanged,
|
||||
required this.onTimelineHeightChangeEnd,
|
||||
required this.onJunctionResizeEnd,
|
||||
required this.timeline,
|
||||
});
|
||||
|
||||
@@ -27,9 +31,13 @@ class ExpandedEditorLayout extends StatefulWidget {
|
||||
final Widget media;
|
||||
final bool showMedia;
|
||||
final bool showProperties;
|
||||
final double? mediaWidth;
|
||||
final ValueChanged<double> onMediaWidthChanged;
|
||||
final VoidCallback onMediaWidthChangeEnd;
|
||||
final double? timelineHeight;
|
||||
final ValueChanged<double> onTimelineHeightChanged;
|
||||
final VoidCallback onTimelineHeightChangeEnd;
|
||||
final VoidCallback onJunctionResizeEnd;
|
||||
final Widget timeline;
|
||||
|
||||
@override
|
||||
@@ -50,28 +58,35 @@ class _ExpandedEditorLayoutState extends State<ExpandedEditorLayout> {
|
||||
WorkspaceCard(key: Key('editor-$name-card'), child: child);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
Widget build(BuildContext context) =>
|
||||
WorkspaceResizeHighlightScope(child: _layout());
|
||||
|
||||
Widget _layout() => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final maximum = math.max(
|
||||
0.0,
|
||||
constraints.maxHeight -
|
||||
gap -
|
||||
WorkspaceLayoutMetrics.previewMinimumHeight,
|
||||
double resolveTimelineHeight(double? height) =>
|
||||
WorkspaceLayoutMetrics.resolveTimelineHeight(
|
||||
constraints.maxHeight,
|
||||
height,
|
||||
);
|
||||
final minimum = math.min(
|
||||
WorkspaceLayoutMetrics.timelineMinimumHeight,
|
||||
maximum,
|
||||
);
|
||||
final timelineHeight =
|
||||
(widget.timelineHeight ??
|
||||
constraints.maxHeight *
|
||||
WorkspaceLayoutMetrics.timelineDefaultHeightFraction)
|
||||
.clamp(minimum, maximum)
|
||||
.toDouble();
|
||||
const mediaWidth = WorkspaceLayoutMetrics.mediaPanelWidth;
|
||||
final timelineHeight = resolveTimelineHeight(widget.timelineHeight);
|
||||
final propertiesWidth = widget.showProperties
|
||||
? WorkspaceLayoutMetrics.propertiesPanelWidth
|
||||
: 0.0;
|
||||
final mediaMaximumWidth = math.max(
|
||||
0.0,
|
||||
constraints.maxWidth -
|
||||
WorkspaceLayoutMetrics.previewMinimumWidth -
|
||||
gap -
|
||||
(widget.showProperties ? propertiesWidth + gap : 0),
|
||||
);
|
||||
final mediaMinimumWidth = math.min(
|
||||
WorkspaceLayoutMetrics.mediaPanelMinimumWidth,
|
||||
mediaMaximumWidth,
|
||||
);
|
||||
final mediaWidth =
|
||||
(widget.mediaWidth ?? WorkspaceLayoutMetrics.mediaPanelWidth)
|
||||
.clamp(mediaMinimumWidth, mediaMaximumWidth)
|
||||
.toDouble();
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
@@ -130,6 +145,24 @@ class _ExpandedEditorLayoutState extends State<ExpandedEditorLayout> {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.showMedia)
|
||||
Positioned(
|
||||
key: const Key('editor-media-divider'),
|
||||
left: mediaWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
top: 0,
|
||||
bottom: timelineHeight + gap,
|
||||
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
child: WorkspaceResizeHandle(
|
||||
key: const Key('editor-media-resize'),
|
||||
highlightTargets: const {WorkspaceResizeBoundary.media},
|
||||
axis: Axis.horizontal,
|
||||
initialValue: mediaWidth,
|
||||
onResize: (width) => widget.onMediaWidthChanged(
|
||||
width.clamp(mediaMinimumWidth, mediaMaximumWidth).toDouble(),
|
||||
),
|
||||
onEnd: widget.onMediaWidthChangeEnd,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
key: const Key('editor-timeline-divider'),
|
||||
left: 0,
|
||||
@@ -138,15 +171,39 @@ class _ExpandedEditorLayoutState extends State<ExpandedEditorLayout> {
|
||||
height: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
child: WorkspaceResizeHandle(
|
||||
key: const Key('editor-timeline-resize'),
|
||||
highlightTargets: const {WorkspaceResizeBoundary.timeline},
|
||||
axis: Axis.vertical,
|
||||
initialValue: timelineHeight,
|
||||
direction: -1,
|
||||
onResize: (height) => widget.onTimelineHeightChanged(
|
||||
height.clamp(minimum, maximum).toDouble(),
|
||||
),
|
||||
onResize: (height) =>
|
||||
widget.onTimelineHeightChanged(resolveTimelineHeight(height)),
|
||||
onEnd: widget.onTimelineHeightChangeEnd,
|
||||
),
|
||||
),
|
||||
if (widget.showMedia)
|
||||
Positioned(
|
||||
left: mediaWidth - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
bottom: timelineHeight - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
height: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
child: WorkspaceResizeHandle.junction(
|
||||
key: const Key('editor-media-timeline-junction'),
|
||||
highlightTargets: const {
|
||||
WorkspaceResizeBoundary.media,
|
||||
WorkspaceResizeBoundary.timeline,
|
||||
},
|
||||
initialWidth: mediaWidth,
|
||||
initialHeight: timelineHeight,
|
||||
verticalDirection: -1,
|
||||
onWidthChanged: (width) => widget.onMediaWidthChanged(
|
||||
width.clamp(mediaMinimumWidth, mediaMaximumWidth).toDouble(),
|
||||
),
|
||||
onHeightChanged: (height) => widget.onTimelineHeightChanged(
|
||||
resolveTimelineHeight(height),
|
||||
),
|
||||
onEnd: widget.onJunctionResizeEnd,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -45,6 +45,7 @@ import 'project_switch_region.dart';
|
||||
import 'project_sidebar.dart';
|
||||
import 'project_tabs_bar.dart';
|
||||
import 'project_tabs_controller.dart';
|
||||
import 'workflow_page.dart';
|
||||
import 'widgets/name_dialog.dart';
|
||||
|
||||
/// The single application surface: project navigation beside the editor.
|
||||
@@ -294,6 +295,19 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
);
|
||||
final projects = ref.read(projectsProvider);
|
||||
final state = projects.value ?? const ProjectState();
|
||||
final editorProjectId = state.timeline == null
|
||||
? null
|
||||
: state.activeProject?.id;
|
||||
final editorViewSettings = desktop && editorProjectId != null
|
||||
? ref.watch(
|
||||
projectViewSettingsProvider(editorProjectId).select(
|
||||
(value) => (
|
||||
ready: value.hasValue,
|
||||
timelineHeight: value.value?.timelineHeight,
|
||||
),
|
||||
),
|
||||
)
|
||||
: null;
|
||||
return EditorWindowChrome(
|
||||
headerHeight: desktop ? DesktopWindowFrame.headerHeight : 48,
|
||||
builder: (context, integrated) => Scaffold(
|
||||
@@ -631,30 +645,33 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
),
|
||||
),
|
||||
);
|
||||
bool isActiveContent(DesktopContent surface) =>
|
||||
surface == DesktopContent.workspace
|
||||
? contentSelection.surface ==
|
||||
DesktopContent.workspace ||
|
||||
contentSelection.surface ==
|
||||
DesktopContent.library ||
|
||||
contentSelection.surface ==
|
||||
DesktopContent.resourceLibrary
|
||||
: contentSelection.surface == surface;
|
||||
Widget contentSurface(
|
||||
DesktopContent surface,
|
||||
Widget child,
|
||||
) => ExcludeFocus(
|
||||
excluding:
|
||||
(contentSelection.surface ==
|
||||
DesktopContent.settings) !=
|
||||
(surface == DesktopContent.settings),
|
||||
excluding: !isActiveContent(surface),
|
||||
child: TickerMode(
|
||||
enabled:
|
||||
(contentSelection.surface ==
|
||||
DesktopContent.settings) ==
|
||||
(surface == DesktopContent.settings),
|
||||
enabled: isActiveContent(surface),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
Widget desktopContents(
|
||||
Widget workspace,
|
||||
) => IndexedStack(
|
||||
index:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.settings
|
||||
? 1
|
||||
: 0,
|
||||
index: switch (contentSelection.surface) {
|
||||
DesktopContent.settings => 1,
|
||||
DesktopContent.workflow => 2,
|
||||
_ => 0,
|
||||
},
|
||||
children: [
|
||||
contentSurface(
|
||||
DesktopContent.workspace,
|
||||
@@ -685,6 +702,10 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
contentSurface(
|
||||
DesktopContent.workflow,
|
||||
const WorkflowPage(),
|
||||
),
|
||||
],
|
||||
);
|
||||
return switch (experience) {
|
||||
@@ -773,17 +794,23 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
resourceLibrarySelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.resourceLibrary,
|
||||
onResourceLibraryPressed: () => selectSidebar(
|
||||
DesktopContent.resourceLibrary,
|
||||
),
|
||||
settingsSelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.settings,
|
||||
onHomePressed: () =>
|
||||
selectSidebar(DesktopContent.workspace),
|
||||
workflowSelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.workflow,
|
||||
onHomePressed: () {
|
||||
selectSidebar(DesktopContent.workspace);
|
||||
_setMode(WorkspaceMode.agent);
|
||||
},
|
||||
onWorkflowPressed: () {
|
||||
ref
|
||||
.read(desktopContentProvider.notifier)
|
||||
.select(DesktopContent.workflow);
|
||||
_desktopScaffoldKey.currentState
|
||||
?.closeDrawer();
|
||||
},
|
||||
onSettingsPressed: () =>
|
||||
showSettingsPage(context),
|
||||
child: desktopContents(
|
||||
@@ -794,15 +821,43 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
navigationDrawer: navigation(drawer: true),
|
||||
mode: _mode,
|
||||
sidebarCollapsed: navigationCollapsed,
|
||||
sidebarCanExpand: !navigationHiddenBySpace,
|
||||
sidebarWidth: _sidebarWidthOverride,
|
||||
timelineHeight:
|
||||
editorViewSettings?.timelineHeight,
|
||||
onTimelineHeightChanged:
|
||||
editorViewSettings?.ready == true &&
|
||||
!_switchingProject
|
||||
? (height) => ref
|
||||
.read(
|
||||
projectViewSettingsProvider(
|
||||
editorProjectId!,
|
||||
).notifier,
|
||||
)
|
||||
.setTimelineHeight(height)
|
||||
: null,
|
||||
onJunctionResizeEnd: () {
|
||||
_saveViewState();
|
||||
if (editorViewSettings?.ready == true) {
|
||||
unawaited(
|
||||
ref
|
||||
.read(
|
||||
projectViewSettingsProvider(
|
||||
editorProjectId!,
|
||||
).notifier,
|
||||
)
|
||||
.save(),
|
||||
);
|
||||
}
|
||||
},
|
||||
onSidebarCollapsedChanged: (value) {
|
||||
_sidebarCollapsed = value;
|
||||
_saveViewState();
|
||||
},
|
||||
onSidebarWidthChanged: (value) {
|
||||
_sidebarWidthOverride = value;
|
||||
_saveViewState();
|
||||
},
|
||||
onSidebarResizeEnd: _saveViewState,
|
||||
sidebarBuilder: (geometry, expand) =>
|
||||
navigation(
|
||||
geometry: geometry,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex/shared/layout/workspace_layout_metrics.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class WorkflowPage extends StatelessWidget {
|
||||
const WorkflowPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(WorkspaceLayoutMetrics.desktopOuterSpacing),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.workflow,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 420),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
AppIcons.timeline,
|
||||
size: 40,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
context.l10n.workflowDescription,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,21 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
abstract final class WorkspaceLayoutMetrics {
|
||||
static const desktopSpacing = 6.0;
|
||||
static const desktopOuterSpacing = 6.0;
|
||||
static const desktopResizeSlop = 2.0;
|
||||
static const desktopResizeHitExtent = desktopSpacing + 2 * desktopResizeSlop;
|
||||
// Keep the cards compact; their two facing borders add another 2 px.
|
||||
static const desktopSpacing = 2.0;
|
||||
static const desktopOuterSpacing = desktopSpacing;
|
||||
// Resize targets overlap the panel edges without widening the visible gap.
|
||||
static const desktopResizeHitExtent = 10.0;
|
||||
// Cover the gutter and its facing borders without changing the hit target.
|
||||
static const desktopResizeHighlightThickness = 4.0;
|
||||
static const desktopResizeSlop =
|
||||
(desktopResizeHitExtent - desktopSpacing) / 2;
|
||||
static const dualPaneMinimumWidth = 840.0;
|
||||
|
||||
static const sidebarDefaultWidth = 240.0;
|
||||
static const sidebarMinimumWidth = 220.0;
|
||||
// Like VS Code SplitView, snap closed halfway past the minimum width.
|
||||
static const sidebarSnapThreshold = sidebarMinimumWidth / 2;
|
||||
static const sidebarWidthLimit = 320.0;
|
||||
static const contentMinimumWidth = 320.0;
|
||||
|
||||
@@ -15,9 +24,24 @@ abstract final class WorkspaceLayoutMetrics {
|
||||
static const previewMinimumHeight = 180.0;
|
||||
|
||||
static const mediaPanelWidth = 260.0;
|
||||
static const propertiesPanelWidth = 260.0;
|
||||
static const mediaPanelMinimumWidth = 220.0;
|
||||
static const propertiesPanelWidth = 240.0;
|
||||
static const previewMinimumWidth = 320.0;
|
||||
|
||||
static double resolveTimelineHeight(
|
||||
double availableHeight,
|
||||
double? requestedHeight,
|
||||
) {
|
||||
final maximum = math.max(
|
||||
0.0,
|
||||
availableHeight - desktopSpacing - previewMinimumHeight,
|
||||
);
|
||||
final minimum = math.min(timelineMinimumHeight, maximum);
|
||||
return (requestedHeight ?? availableHeight * timelineDefaultHeightFraction)
|
||||
.clamp(minimum, maximum)
|
||||
.toDouble();
|
||||
}
|
||||
|
||||
static double sidebarMaximumWidth(double availableWidth) =>
|
||||
(availableWidth - contentMinimumWidth)
|
||||
.clamp(sidebarMinimumWidth, sidebarWidthLimit)
|
||||
|
||||
@@ -1,5 +1,94 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
|
||||
import '../layout/workspace_layout_metrics.dart';
|
||||
|
||||
enum WorkspaceResizeBoundary { sidebar, media, timeline }
|
||||
|
||||
/// Shares feedback for boundaries that meet at a resize junction.
|
||||
class WorkspaceResizeHighlightScope extends StatefulWidget {
|
||||
const WorkspaceResizeHighlightScope({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<WorkspaceResizeHighlightScope> createState() =>
|
||||
_WorkspaceResizeHighlightScopeState();
|
||||
}
|
||||
|
||||
class _WorkspaceResizeHighlightScopeState
|
||||
extends State<WorkspaceResizeHighlightScope> {
|
||||
final _controller = _ResizeHighlightController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => _ResizeHighlightScope(
|
||||
controller:
|
||||
context
|
||||
.dependOnInheritedWidgetOfExactType<_ResizeHighlightScope>()
|
||||
?.notifier ??
|
||||
_controller,
|
||||
child: widget.child,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class _ResizeHighlightScope
|
||||
extends InheritedNotifier<_ResizeHighlightController> {
|
||||
const _ResizeHighlightScope({
|
||||
required super.child,
|
||||
required _ResizeHighlightController controller,
|
||||
}) : super(notifier: controller);
|
||||
}
|
||||
|
||||
class _ResizeHighlightController extends ChangeNotifier {
|
||||
final _sources = <Object, Set<WorkspaceResizeBoundary>>{};
|
||||
bool _notificationPending = false;
|
||||
bool _disposed = false;
|
||||
|
||||
bool highlights(Set<WorkspaceResizeBoundary> boundaries) =>
|
||||
_sources.values.any((active) => active.any(boundaries.contains));
|
||||
|
||||
void update(
|
||||
Object source,
|
||||
Set<WorkspaceResizeBoundary> boundaries,
|
||||
bool active,
|
||||
) {
|
||||
if (_disposed) return;
|
||||
final next = active && boundaries.isNotEmpty ? boundaries : null;
|
||||
if (setEquals(_sources[source], next)) return;
|
||||
if (next == null) {
|
||||
_sources.remove(source);
|
||||
} else {
|
||||
_sources[source] = next;
|
||||
}
|
||||
// Handles can disappear while the layout is rebuilding (collapse/unmount).
|
||||
// Notify surviving handles after that frame instead of during their build.
|
||||
if (SchedulerBinding.instance.schedulerPhase ==
|
||||
SchedulerPhase.persistentCallbacks) {
|
||||
if (_notificationPending) return;
|
||||
_notificationPending = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_notificationPending = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
});
|
||||
} else {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the resize cursor active across the window while a split is dragged.
|
||||
class WorkspaceResizeHandle extends StatefulWidget {
|
||||
@@ -11,7 +100,30 @@ class WorkspaceResizeHandle extends StatefulWidget {
|
||||
this.direction = 1,
|
||||
this.onStart,
|
||||
this.onEnd,
|
||||
});
|
||||
this.highlightTargets = const {},
|
||||
this.highlightOffset = Offset.zero,
|
||||
}) : _orthogonalInitialValue = null,
|
||||
_onOrthogonalResize = null,
|
||||
_orthogonalDirection = 1;
|
||||
|
||||
const WorkspaceResizeHandle.junction({
|
||||
super.key,
|
||||
required double initialWidth,
|
||||
required double initialHeight,
|
||||
required ValueChanged<double> onWidthChanged,
|
||||
required ValueChanged<double> onHeightChanged,
|
||||
double verticalDirection = 1,
|
||||
this.onStart,
|
||||
this.onEnd,
|
||||
this.highlightTargets = const {},
|
||||
this.highlightOffset = Offset.zero,
|
||||
}) : axis = Axis.horizontal,
|
||||
initialValue = initialWidth,
|
||||
onResize = onWidthChanged,
|
||||
direction = 1,
|
||||
_orthogonalInitialValue = initialHeight,
|
||||
_onOrthogonalResize = onHeightChanged,
|
||||
_orthogonalDirection = verticalDirection;
|
||||
|
||||
final Axis axis;
|
||||
final double initialValue;
|
||||
@@ -19,6 +131,13 @@ class WorkspaceResizeHandle extends StatefulWidget {
|
||||
final VoidCallback? onStart;
|
||||
final ValueChanged<double> onResize;
|
||||
final VoidCallback? onEnd;
|
||||
final Set<WorkspaceResizeBoundary> highlightTargets;
|
||||
|
||||
/// Aligns feedback with an edge while keeping the full resize hit target.
|
||||
final Offset highlightOffset;
|
||||
final double? _orthogonalInitialValue;
|
||||
final ValueChanged<double>? _onOrthogonalResize;
|
||||
final double _orthogonalDirection;
|
||||
|
||||
@override
|
||||
State<WorkspaceResizeHandle> createState() => _WorkspaceResizeHandleState();
|
||||
@@ -26,10 +145,56 @@ class WorkspaceResizeHandle extends StatefulWidget {
|
||||
|
||||
class _WorkspaceResizeHandleState extends State<WorkspaceResizeHandle> {
|
||||
OverlayEntry? _cursorOverlay;
|
||||
double? _startPosition;
|
||||
Offset? _startPosition;
|
||||
double _startValue = 0;
|
||||
double _orthogonalStartValue = 0;
|
||||
bool _hovered = false;
|
||||
final _highlightSource = Object();
|
||||
_ResizeHighlightController? _highlightController;
|
||||
|
||||
MouseCursor get _cursor => widget.axis == Axis.horizontal
|
||||
bool get _locallyHighlighted => _hovered || _startPosition != null;
|
||||
bool get _highlighted =>
|
||||
_locallyHighlighted ||
|
||||
!_isJunction &&
|
||||
(_highlightController?.highlights(widget.highlightTargets) ?? false);
|
||||
|
||||
void _publishHighlight() => _highlightController?.update(
|
||||
_highlightSource,
|
||||
widget.highlightTargets,
|
||||
_locallyHighlighted,
|
||||
);
|
||||
|
||||
void _hover(bool value) {
|
||||
if (_hovered == value) return;
|
||||
setState(() => _hovered = value);
|
||||
_publishHighlight();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final controller = context
|
||||
.dependOnInheritedWidgetOfExactType<_ResizeHighlightScope>()
|
||||
?.notifier;
|
||||
if (_highlightController == controller) return;
|
||||
_highlightController?.update(_highlightSource, const {}, false);
|
||||
_highlightController = controller;
|
||||
_publishHighlight();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant WorkspaceResizeHandle oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!setEquals(oldWidget.highlightTargets, widget.highlightTargets)) {
|
||||
_publishHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
bool get _isJunction => widget._onOrthogonalResize != null;
|
||||
|
||||
MouseCursor get _cursor => _isJunction
|
||||
? SystemMouseCursors.grab
|
||||
: widget.axis == Axis.horizontal
|
||||
? SystemMouseCursors.resizeColumn
|
||||
: SystemMouseCursors.resizeRow;
|
||||
|
||||
@@ -37,11 +202,13 @@ class _WorkspaceResizeHandleState extends State<WorkspaceResizeHandle> {
|
||||
widget.axis == Axis.horizontal ? position.dx : position.dy;
|
||||
|
||||
void _start(DragStartDetails details) {
|
||||
_startPosition = _coordinate(details.globalPosition);
|
||||
setState(() => _startPosition = details.globalPosition);
|
||||
_publishHighlight();
|
||||
_startValue = widget.initialValue;
|
||||
_orthogonalStartValue = widget._orthogonalInitialValue ?? 0;
|
||||
widget.onStart?.call();
|
||||
_releaseCursor();
|
||||
final cursor = _cursor;
|
||||
final cursor = _isJunction ? SystemMouseCursors.grabbing : _cursor;
|
||||
_cursorOverlay = OverlayEntry(
|
||||
builder: (_) => Positioned.fill(
|
||||
child: MouseRegion(
|
||||
@@ -60,7 +227,12 @@ class _WorkspaceResizeHandleState extends State<WorkspaceResizeHandle> {
|
||||
if (start == null) return;
|
||||
widget.onResize(
|
||||
_startValue +
|
||||
widget.direction * (_coordinate(details.globalPosition) - start),
|
||||
widget.direction *
|
||||
(_coordinate(details.globalPosition) - _coordinate(start)),
|
||||
);
|
||||
widget._onOrthogonalResize?.call(
|
||||
_orthogonalStartValue +
|
||||
widget._orthogonalDirection * (details.globalPosition.dy - start.dy),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,13 +243,16 @@ class _WorkspaceResizeHandleState extends State<WorkspaceResizeHandle> {
|
||||
}
|
||||
|
||||
void _finish() {
|
||||
_startPosition = null;
|
||||
if (_startPosition == null) return;
|
||||
setState(() => _startPosition = null);
|
||||
_publishHighlight();
|
||||
_releaseCursor();
|
||||
widget.onEnd?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_highlightController?.update(_highlightSource, const {}, false);
|
||||
_releaseCursor();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -85,20 +260,79 @@ class _WorkspaceResizeHandleState extends State<WorkspaceResizeHandle> {
|
||||
@override
|
||||
Widget build(BuildContext context) => MouseRegion(
|
||||
cursor: _cursor,
|
||||
onEnter: (_) => _hover(true),
|
||||
onExit: (_) => _hover(false),
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onHorizontalDragStart: widget.axis == Axis.horizontal ? _start : null,
|
||||
onHorizontalDragUpdate: widget.axis == Axis.horizontal ? _update : null,
|
||||
onHorizontalDragEnd: widget.axis == Axis.horizontal
|
||||
onHorizontalDragStart: !_isJunction && widget.axis == Axis.horizontal
|
||||
? _start
|
||||
: null,
|
||||
onHorizontalDragUpdate: !_isJunction && widget.axis == Axis.horizontal
|
||||
? _update
|
||||
: null,
|
||||
onHorizontalDragEnd: !_isJunction && widget.axis == Axis.horizontal
|
||||
? (_) => _finish()
|
||||
: null,
|
||||
onVerticalDragStart: widget.axis == Axis.vertical ? _start : null,
|
||||
onVerticalDragUpdate: widget.axis == Axis.vertical ? _update : null,
|
||||
onVerticalDragEnd: widget.axis == Axis.vertical ? (_) => _finish() : null,
|
||||
onHorizontalDragCancel: widget.axis == Axis.horizontal ? _finish : null,
|
||||
onVerticalDragCancel: widget.axis == Axis.vertical ? _finish : null,
|
||||
child: const SizedBox.expand(),
|
||||
onVerticalDragStart: !_isJunction && widget.axis == Axis.vertical
|
||||
? _start
|
||||
: null,
|
||||
onVerticalDragUpdate: !_isJunction && widget.axis == Axis.vertical
|
||||
? _update
|
||||
: null,
|
||||
onVerticalDragEnd: !_isJunction && widget.axis == Axis.vertical
|
||||
? (_) => _finish()
|
||||
: null,
|
||||
onHorizontalDragCancel: !_isJunction && widget.axis == Axis.horizontal
|
||||
? _finish
|
||||
: null,
|
||||
onVerticalDragCancel: !_isJunction && widget.axis == Axis.vertical
|
||||
? _finish
|
||||
: null,
|
||||
onPanStart: _isJunction ? _start : null,
|
||||
onPanUpdate: _isJunction ? _update : null,
|
||||
onPanEnd: _isJunction ? (_) => _finish() : null,
|
||||
onPanCancel: _isJunction ? _finish : null,
|
||||
child: IgnorePointer(
|
||||
child: Transform.translate(
|
||||
offset: widget.highlightOffset,
|
||||
child: Center(
|
||||
child: TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0, end: _highlighted ? 1 : 0),
|
||||
duration: MediaQuery.disableAnimationsOf(context)
|
||||
? Duration.zero
|
||||
: Duration(milliseconds: _highlighted ? 180 : 140),
|
||||
curve: Curves.easeInOutCubic,
|
||||
builder: (context, progress, child) => Opacity(
|
||||
opacity: progress,
|
||||
child: Transform.scale(
|
||||
scaleX: _isJunction || widget.axis == Axis.horizontal
|
||||
? .5 + .5 * progress
|
||||
: .98 + .02 * progress,
|
||||
scaleY: _isJunction || widget.axis == Axis.vertical
|
||||
? .5 + .5 * progress
|
||||
: .98 + .02 * progress,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
width: _isJunction || widget.axis == Axis.horizontal
|
||||
? WorkspaceLayoutMetrics.desktopResizeHighlightThickness
|
||||
: double.infinity,
|
||||
height: _isJunction || widget.axis == Axis.vertical
|
||||
? WorkspaceLayoutMetrics.desktopResizeHighlightThickness
|
||||
: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(
|
||||
WorkspaceLayoutMetrics.desktopResizeHighlightThickness / 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -61,8 +61,8 @@ Future<void> floatOrDockChat(WidgetTester tester) async {
|
||||
|
||||
void main() {
|
||||
test('space classes and two-pane decisions do not depend on workflow', () {
|
||||
expect(WorkspaceLayoutPolicy.desktopNavigationFits(545), isFalse);
|
||||
expect(WorkspaceLayoutPolicy.desktopNavigationFits(546), isTrue);
|
||||
expect(WorkspaceLayoutPolicy.desktopNavigationFits(541), isFalse);
|
||||
expect(WorkspaceLayoutPolicy.desktopNavigationFits(542), isTrue);
|
||||
expect(WorkspaceLayoutPolicy.showAgentBesideEditor(839), isFalse);
|
||||
expect(WorkspaceLayoutPolicy.showAgentBesideEditor(840), isTrue);
|
||||
});
|
||||
@@ -178,7 +178,7 @@ void main() {
|
||||
expect(header.contains(tester.getCenter(projectTab)), isTrue);
|
||||
expect(find.byKey(const Key('sidebar-tab-chat')), findsNothing);
|
||||
expect(find.byKey(const Key('sidebar-tab-resources')), findsNothing);
|
||||
expect(find.byKey(const Key('desktop-navigation-rail')), findsNothing);
|
||||
expect(find.byKey(const Key('desktop-navigation-rail')), findsOneWidget);
|
||||
expect(find.byKey(const Key('media-project-button')), findsNothing);
|
||||
expect(find.byKey(const Key('media-panel-close')), findsNothing);
|
||||
final mediaHeader = find.byKey(const Key('media-panel-header'));
|
||||
@@ -202,12 +202,49 @@ void main() {
|
||||
find.byKey(const Key('editor-timeline-card')),
|
||||
);
|
||||
final chatRect = tester.getRect(find.byKey(const Key('desktop-chat-card')));
|
||||
expect(media.left - chatRect.right, 6);
|
||||
expect(preview.left - media.right, 6);
|
||||
expect(media.left - chatRect.right, 2);
|
||||
expect(preview.left - media.right, 2);
|
||||
expect(timeline.top - media.bottom, 2);
|
||||
final content = tester.getRect(
|
||||
find.byKey(const Key('desktop-content-container')),
|
||||
);
|
||||
expect(content.left, 46);
|
||||
expect(content.right, 1198);
|
||||
expect(content.bottom, 798);
|
||||
expect(media.top, preview.top);
|
||||
expect(timeline.left, media.left);
|
||||
expect(timeline.right, preview.right);
|
||||
final previewElement = tester.element(find.byType(EditorPreviewPanel));
|
||||
await tester.drag(
|
||||
find.byKey(const Key('editor-media-resize')),
|
||||
const Offset(60, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('editor-media-card'))).width,
|
||||
media.width + 60,
|
||||
);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('editor-media-timeline-junction')),
|
||||
const Offset(40, -30),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final resizedSettings = mounted.container
|
||||
.read(projectViewSettingsProvider(mounted.projectId))
|
||||
.requireValue;
|
||||
expect(resizedSettings.mediaWidth, media.width + 100);
|
||||
expect(resizedSettings.timelineHeight, closeTo(timeline.height + 30, .01));
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('editor-timeline-card'))).height,
|
||||
closeTo(timeline.height + 30, .01),
|
||||
);
|
||||
expect(
|
||||
mounted.container
|
||||
.read(projectViewSettingsProvider(mounted.projectId))
|
||||
.requireValue
|
||||
.mediaWidth,
|
||||
media.width + 100,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MediaPanel), findsNothing);
|
||||
@@ -218,6 +255,10 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MediaPanel), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('editor-media-card'))).width,
|
||||
media.width + 100,
|
||||
);
|
||||
expect(tester.element(find.byType(AgentChatPanel)), same(chat));
|
||||
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
|
||||
expect(
|
||||
@@ -228,6 +269,319 @@ void main() {
|
||||
await mounted.close();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'chat/timeline junction resizes both axes, persists and follows docking',
|
||||
(tester) async {
|
||||
final mounted = await mount(tester, const Size(1800, 800));
|
||||
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
|
||||
Rect card(String name) => tester.getRect(find.byKey(Key(name)));
|
||||
final chat = card('desktop-chat-card');
|
||||
final media = card('editor-media-card');
|
||||
final timeline = card('editor-timeline-card');
|
||||
final center = tester.getCenter(junction);
|
||||
expect(center.dx, (chat.right + media.left) / 2);
|
||||
expect(center.dy, (media.bottom + timeline.top) / 2);
|
||||
final editorElement = tester.element(find.byType(EditorWorkspace));
|
||||
final mediaElement = tester.element(find.byType(MediaPanel));
|
||||
final input = find.descendant(
|
||||
of: find.byType(AgentChatPanel),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
await tester.enterText(input, 'Keep draft while resizing the junction');
|
||||
|
||||
await tester.drag(junction, const Offset(60, -50));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('desktop-chat-card').width, chat.width + 60);
|
||||
expect(
|
||||
card('editor-timeline-card').height,
|
||||
closeTo(timeline.height + 50, .01),
|
||||
);
|
||||
expect(card('editor-media-card').width, media.width);
|
||||
expect(
|
||||
mounted.container
|
||||
.read(workspaceViewSettingsProvider)
|
||||
.requireValue
|
||||
.sidebarWidth,
|
||||
chat.width + 60,
|
||||
);
|
||||
expect(
|
||||
mounted.container
|
||||
.read(projectViewSettingsProvider(mounted.projectId))
|
||||
.requireValue
|
||||
.timelineHeight,
|
||||
closeTo(timeline.height + 50, .01),
|
||||
);
|
||||
final savedWorkspace = await tester.runAsync(
|
||||
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
|
||||
);
|
||||
final savedProject = await tester.runAsync(
|
||||
() => mounted.container
|
||||
.read(projectViewSettingsRepositoryProvider)
|
||||
.load(mounted.projectId),
|
||||
);
|
||||
expect(savedWorkspace!.sidebarWidth, chat.width + 60);
|
||||
expect(savedProject!.timelineHeight, closeTo(timeline.height + 50, .01));
|
||||
|
||||
await tester.drag(junction, const Offset(-40, 30));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('desktop-chat-card').width, chat.width + 20);
|
||||
expect(
|
||||
card('editor-timeline-card').height,
|
||||
closeTo(timeline.height + 20, .01),
|
||||
);
|
||||
await tester.drag(junction, const Offset(-100, -2000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('desktop-chat-card').width, 220);
|
||||
expect(card('editor-preview-card').height, 180);
|
||||
await tester.drag(junction, const Offset(40, -60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('desktop-chat-card').width, 260);
|
||||
expect(card('editor-preview-card').height, 180);
|
||||
await tester.drag(junction, const Offset(2000, 2000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('desktop-chat-card').width, 320);
|
||||
expect(card('editor-timeline-card').height, 220);
|
||||
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
|
||||
expect(tester.element(find.byType(MediaPanel)), same(mediaElement));
|
||||
expect(
|
||||
tester.widget<TextField>(input).controller!.text,
|
||||
'Keep draft while resizing the junction',
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(junction, findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(junction, findsOneWidget);
|
||||
expect(card('desktop-chat-card').width, 320);
|
||||
expect(card('editor-timeline-card').height, 220);
|
||||
await floatOrDockChat(tester);
|
||||
await tester.pumpAndSettle();
|
||||
expect(junction, findsNothing);
|
||||
await floatOrDockChat(tester);
|
||||
await tester.pumpAndSettle();
|
||||
expect(junction, findsOneWidget);
|
||||
|
||||
// The same T remains between chat, preview and timeline with media hidden.
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(junction, findsOneWidget);
|
||||
await tester.drag(junction, const Offset(-40, -30));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('desktop-chat-card').width, 280);
|
||||
expect(card('editor-timeline-card').height, 250);
|
||||
tester.view.physicalSize = const Size(600, 360);
|
||||
await tester.pumpAndSettle();
|
||||
final narrowCenter = tester.getCenter(junction);
|
||||
expect(
|
||||
narrowCenter.dy,
|
||||
(card('editor-preview-card').bottom +
|
||||
card('editor-timeline-card').top) /
|
||||
2,
|
||||
);
|
||||
await tester.drag(junction, const Offset(2000, -2000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('editor-preview-card').height, 180);
|
||||
expect(card('desktop-editor-card').width, 320);
|
||||
expect(tester.takeException(), isNull);
|
||||
await mounted.close();
|
||||
},
|
||||
);
|
||||
|
||||
for (final junctionDrag in [false, true]) {
|
||||
testWidgets(
|
||||
'${junctionDrag ? 'junction' : 'sidebar'} persists resize only when the gesture ends',
|
||||
(tester) async {
|
||||
final mounted = await mount(tester, const Size(1800, 800));
|
||||
final repository = mounted.container.read(
|
||||
workspaceViewSettingsRepositoryProvider,
|
||||
);
|
||||
final savedBefore = (await tester.runAsync(repository.load))!;
|
||||
final sidebar = find.byKey(const Key('desktop-chat-card'));
|
||||
final initialWidth = tester.getSize(sidebar).width;
|
||||
final handle = find.byKey(
|
||||
Key(
|
||||
junctionDrag
|
||||
? 'desktop-chat-timeline-junction'
|
||||
: 'project-sidebar-resize',
|
||||
),
|
||||
);
|
||||
final drag = await tester.startGesture(
|
||||
tester.getCenter(handle),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
for (var i = 0; i < 5; i++) {
|
||||
await drag.moveBy(Offset(10, junctionDrag ? -10 : 0));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
expect(tester.getSize(sidebar).width, initialWidth + 50);
|
||||
final savedDuring = (await tester.runAsync(repository.load))!;
|
||||
expect(savedDuring.sidebarWidth, savedBefore.sidebarWidth);
|
||||
// Cancellation also commits the last visible size.
|
||||
if (junctionDrag) {
|
||||
await drag.cancel();
|
||||
} else {
|
||||
await drag.up();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
final savedAfter = (await tester.runAsync(repository.load))!;
|
||||
expect(savedAfter.sidebarWidth, initialWidth + 50);
|
||||
await mounted.close();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (final junctionDrag in [false, true]) {
|
||||
testWidgets(
|
||||
'${junctionDrag ? 'junction' : 'sidebar'} drag snaps closed and can drag back open',
|
||||
(tester) async {
|
||||
final mounted = await mount(tester, const Size(1800, 800));
|
||||
final sidebar = find.byKey(const Key('desktop-chat-card'));
|
||||
final resize = find.byKey(const Key('project-sidebar-resize'));
|
||||
final junction = find.byKey(
|
||||
const Key('desktop-chat-timeline-junction'),
|
||||
);
|
||||
final initialWidth = tester.getSize(sidebar).width;
|
||||
final initialTimeline = tester
|
||||
.getSize(find.byKey(const Key('editor-timeline-card')))
|
||||
.height;
|
||||
final editor = tester.element(find.byType(EditorWorkspace));
|
||||
final input = find.descendant(
|
||||
of: find.byType(AgentChatPanel),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
await tester.enterText(input, 'Draft survives sidebar snapping');
|
||||
final start = tester.getCenter(junctionDrag ? junction : resize);
|
||||
final drag = await tester.startGesture(
|
||||
start,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await drag.moveTo(
|
||||
start + Offset(115 - initialWidth, junctionDrag ? -30 : 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(sidebar).width, 220);
|
||||
await drag.moveBy(Offset(-6, junctionDrag ? -20 : 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sidebar, findsNothing);
|
||||
expect(resize, findsOneWidget);
|
||||
expect(
|
||||
mounted.container
|
||||
.read(workspaceViewSettingsProvider)
|
||||
.requireValue
|
||||
.sidebarCollapsed,
|
||||
isTrue,
|
||||
);
|
||||
// Crossing back over the threshold within the same gesture restores it.
|
||||
await drag.moveBy(const Offset(16, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(sidebar).width, 220);
|
||||
await drag.moveBy(Offset(-16, junctionDrag ? -20 : 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sidebar, findsNothing);
|
||||
if (junctionDrag) {
|
||||
expect(junction, findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.getSize(find.byKey(const Key('editor-timeline-card')))
|
||||
.height,
|
||||
closeTo(initialTimeline + 70, .01),
|
||||
);
|
||||
await drag.cancel();
|
||||
} else {
|
||||
await drag.up();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(junction, findsOneWidget);
|
||||
final saved = await tester.runAsync(
|
||||
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
|
||||
);
|
||||
expect(saved!.sidebarCollapsed, isTrue);
|
||||
expect(saved.sidebarWidth, initialWidth);
|
||||
if (junctionDrag) {
|
||||
final savedProject = await tester.runAsync(
|
||||
() => mounted.container
|
||||
.read(projectViewSettingsRepositoryProvider)
|
||||
.load(mounted.projectId),
|
||||
);
|
||||
expect(
|
||||
savedProject!.timelineHeight,
|
||||
closeTo(initialTimeline + 70, .01),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(sidebar).width, initialWidth);
|
||||
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
|
||||
expect(
|
||||
tester.widget<TextField>(input).controller!.text,
|
||||
'Draft survives sidebar snapping',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
|
||||
await tester.pumpAndSettle();
|
||||
// A fresh edge or junction drag starts from the collapsed width of zero.
|
||||
final edgeTimeline = tester
|
||||
.getSize(find.byKey(const Key('editor-timeline-card')))
|
||||
.height;
|
||||
expect(junction, findsOneWidget);
|
||||
final edge = await tester.startGesture(
|
||||
tester.getCenter(junctionDrag ? junction : resize),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await edge.moveBy(Offset(109, junctionDrag ? -25 : 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sidebar, findsNothing);
|
||||
if (junctionDrag) {
|
||||
expect(
|
||||
tester
|
||||
.getSize(find.byKey(const Key('editor-timeline-card')))
|
||||
.height,
|
||||
closeTo(edgeTimeline + 25, .01),
|
||||
);
|
||||
}
|
||||
await edge.moveBy(const Offset(1, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(sidebar).width, 220);
|
||||
await edge.moveBy(const Offset(140, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(sidebar).width, 250);
|
||||
await edge.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
mounted.container
|
||||
.read(workspaceViewSettingsProvider)
|
||||
.requireValue
|
||||
.sidebarCollapsed,
|
||||
isFalse,
|
||||
);
|
||||
final reopened = await tester.runAsync(
|
||||
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
|
||||
);
|
||||
expect(reopened!.sidebarCollapsed, isFalse);
|
||||
expect(reopened.sidebarWidth, 250);
|
||||
if (junctionDrag) {
|
||||
final reopenedProject = await tester.runAsync(
|
||||
() => mounted.container
|
||||
.read(projectViewSettingsRepositoryProvider)
|
||||
.load(mounted.projectId),
|
||||
);
|
||||
expect(
|
||||
reopenedProject!.timelineHeight,
|
||||
closeTo(edgeTimeline + 25, .01),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
tester.widget<TextField>(input).controller!.text,
|
||||
'Draft survives sidebar snapping',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await mounted.close();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('project tabs switch scoped drafts and preserve failed close', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -504,9 +858,9 @@ void main() {
|
||||
);
|
||||
expect(preview.top, properties.top);
|
||||
expect(preview.bottom, properties.bottom);
|
||||
expect(properties.left - preview.right, 6);
|
||||
expect(properties.left - preview.right, 2);
|
||||
expect(playback.bottom, preview.bottom - 1);
|
||||
expect(playback.height, 36);
|
||||
expect(playback.height, 32);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('timeline-tabs-bar'))).height,
|
||||
32,
|
||||
@@ -527,7 +881,7 @@ void main() {
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('timeline-toolbar'))).height,
|
||||
36,
|
||||
32,
|
||||
);
|
||||
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
|
||||
expect(AppColors.of(Theme.of(editor)).family, palette);
|
||||
@@ -839,9 +1193,9 @@ void main() {
|
||||
contentRect.top,
|
||||
tester.getRect(find.byKey(const Key('desktop-window-header'))).bottom,
|
||||
);
|
||||
expect(contentRect.left, 6);
|
||||
expect(contentRect.right, 1194);
|
||||
expect(contentRect.bottom, 794);
|
||||
expect(contentRect.left, 46);
|
||||
expect(contentRect.right, 1198);
|
||||
expect(contentRect.bottom, 798);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('window-minimize'))).left -
|
||||
tester
|
||||
@@ -1022,8 +1376,14 @@ void main() {
|
||||
expect(left.left - headerRect.left, AppSidebarMetrics.outerPadding);
|
||||
expect(headerRect.right - right.right, AppSidebarMetrics.outerPadding);
|
||||
expect(middle.center.dx, closeTo(headerRect.center.dx, 0.01));
|
||||
expect(middle.left, greaterThanOrEqualTo(left.right));
|
||||
expect(middle.right, lessThanOrEqualTo(right.left));
|
||||
expect(
|
||||
middle.left - left.right,
|
||||
greaterThanOrEqualTo(AppSpacing.small),
|
||||
);
|
||||
expect(
|
||||
right.left - middle.right,
|
||||
greaterThanOrEqualTo(AppSpacing.small),
|
||||
);
|
||||
expect(left.center.dy, right.center.dy);
|
||||
expect(tester.widget<Text>(title).overflow, TextOverflow.ellipsis);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
@@ -69,6 +69,7 @@ void main() {
|
||||
onRename: (_) {},
|
||||
),
|
||||
onHomePressed: () {},
|
||||
onWorkflowPressed: () {},
|
||||
onSettingsPressed: () {},
|
||||
child: const SizedBox.shrink(),
|
||||
),
|
||||
|
||||
@@ -1,12 +1,399 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex/app/adaptive/desktop_workspace_controller.dart';
|
||||
import 'package:cutdex/shared/layout/workspace_layout_metrics.dart';
|
||||
import 'package:cutdex/app/shells/desktop_workspace_shell.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex/features/editor/layouts/expanded_editor_layout.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'junctions paint both connected boundaries during hover and drag',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1500, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final controller = DesktopWorkspaceController();
|
||||
addTearDown(controller.dispose);
|
||||
const accent = Color(0xFF0D99FF);
|
||||
final repaintKey = GlobalKey();
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
var sidebarWidth = 240.0;
|
||||
var mediaWidth = 260.0;
|
||||
var timelineHeight = 280.0;
|
||||
var showMedia = true;
|
||||
var sidebarCollapsed = false;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: accent)
|
||||
.copyWith(primary: accent),
|
||||
),
|
||||
home: RepaintBoundary(
|
||||
key: repaintKey,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return DesktopWorkspaceShell(
|
||||
projectTabsLayout: true,
|
||||
mode: WorkspaceMode.cut,
|
||||
controller: controller,
|
||||
sidebarCollapsed: sidebarCollapsed,
|
||||
sidebarWidth: sidebarWidth,
|
||||
onSidebarCollapsedChanged: (collapsed) =>
|
||||
setState(() => sidebarCollapsed = collapsed),
|
||||
onSidebarWidthChanged: (width) =>
|
||||
setState(() => sidebarWidth = width),
|
||||
timelineHeight: timelineHeight,
|
||||
onTimelineHeightChanged: (height) =>
|
||||
setState(() => timelineHeight = height),
|
||||
sidebarBuilder: (_, _) => const SizedBox.expand(),
|
||||
agentBuilder: (_, _) => const SizedBox.expand(),
|
||||
scaffoldKey: scaffoldKey,
|
||||
navigationDrawer: const SizedBox.shrink(),
|
||||
editor: ExpandedEditorLayout(
|
||||
preview: const SizedBox.expand(),
|
||||
header: const SizedBox(height: 40),
|
||||
properties: const SizedBox.expand(),
|
||||
media: const SizedBox.expand(),
|
||||
showMedia: showMedia,
|
||||
showProperties: false,
|
||||
mediaWidth: mediaWidth,
|
||||
onMediaWidthChanged: (width) =>
|
||||
setState(() => mediaWidth = width),
|
||||
onMediaWidthChangeEnd: () {},
|
||||
timelineHeight: timelineHeight,
|
||||
onTimelineHeightChanged: (height) =>
|
||||
setState(() => timelineHeight = height),
|
||||
onTimelineHeightChangeEnd: () {},
|
||||
onJunctionResizeEnd: () {},
|
||||
timeline: const SizedBox.expand(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
const boundaries = {
|
||||
'sidebar': 'project-sidebar-resize',
|
||||
'media': 'editor-media-resize',
|
||||
'timeline': 'editor-timeline-resize',
|
||||
};
|
||||
Future<void> expectPainted(Set<String> active) async {
|
||||
final render =
|
||||
repaintKey.currentContext!.findRenderObject()!
|
||||
as RenderRepaintBoundary;
|
||||
final image = (await tester.runAsync(render.toImage))!;
|
||||
final data = (await tester.runAsync(
|
||||
() => image.toByteData(format: ui.ImageByteFormat.rawRgba),
|
||||
))!;
|
||||
Color pixel(Offset global) {
|
||||
final point = render.globalToLocal(global);
|
||||
final offset =
|
||||
(point.dy.floor() * image.width + point.dx.floor()) * 4;
|
||||
return Color.fromARGB(
|
||||
data.getUint8(offset + 3),
|
||||
data.getUint8(offset),
|
||||
data.getUint8(offset + 1),
|
||||
data.getUint8(offset + 2),
|
||||
);
|
||||
}
|
||||
|
||||
for (final entry in boundaries.entries) {
|
||||
final handle = find.byKey(Key(entry.value));
|
||||
if (handle.evaluate().isEmpty) continue;
|
||||
final rect = tester.getRect(handle);
|
||||
final paint = tester.getRect(
|
||||
find.descendant(of: handle, matching: find.byType(DecoratedBox)),
|
||||
);
|
||||
final color = pixel(paint.center);
|
||||
expect(
|
||||
color,
|
||||
active.contains(entry.key) ? accent : isNot(accent),
|
||||
reason: entry.key,
|
||||
);
|
||||
if (active.contains(entry.key)) {
|
||||
final vertical = entry.key != 'timeline';
|
||||
expect(vertical ? rect.width : rect.height, 10);
|
||||
expect(vertical ? paint.width : paint.height, 4);
|
||||
}
|
||||
}
|
||||
if (active.containsAll({'sidebar', 'timeline'})) {
|
||||
final sidebar = tester.getRect(
|
||||
find.byKey(const Key('project-sidebar-resize')),
|
||||
);
|
||||
final timeline = tester.getRect(
|
||||
find.byKey(const Key('editor-timeline-resize')),
|
||||
);
|
||||
if (sidebarCollapsed) {
|
||||
expect(sidebar.left, 0);
|
||||
expect(sidebar.width, 10);
|
||||
final verticalPaint = tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('project-sidebar-resize')),
|
||||
matching: find.byType(DecoratedBox),
|
||||
),
|
||||
);
|
||||
expect(verticalPaint.center.dx, timeline.left);
|
||||
expect(
|
||||
pixel(Offset(sidebar.center.dx, timeline.center.dy - 20)),
|
||||
isNot(accent),
|
||||
reason: 'Collapsed feedback sits at the edge, not the hit center',
|
||||
);
|
||||
expect(
|
||||
pixel(Offset(timeline.left, timeline.center.dy - 20)),
|
||||
accent,
|
||||
);
|
||||
}
|
||||
if (showMedia) {
|
||||
final media = tester.getRect(
|
||||
find.byKey(const Key('editor-media-resize')),
|
||||
);
|
||||
expect(
|
||||
pixel(Offset(media.center.dx, timeline.center.dy)),
|
||||
accent,
|
||||
reason: 'The original media/preview/timeline T stays continuous',
|
||||
);
|
||||
}
|
||||
}
|
||||
image.dispose();
|
||||
}
|
||||
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(1400, 50));
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({});
|
||||
await mouse.moveTo(
|
||||
tester.getCenter(find.byKey(const Key('editor-media-resize'))),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({'media'});
|
||||
await mouse.moveTo(
|
||||
tester.getCenter(
|
||||
find.byKey(const Key('editor-media-timeline-junction')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({'media', 'timeline'});
|
||||
// Removing the junction leaves the pointer hovering over the timeline.
|
||||
update(() => showMedia = false);
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({'timeline'});
|
||||
await mouse.moveTo(const Offset(1450, 50));
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({});
|
||||
update(() => showMedia = true);
|
||||
await tester.pumpAndSettle();
|
||||
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
|
||||
await mouse.moveTo(tester.getCenter(junction));
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({'sidebar', 'timeline'});
|
||||
await mouse.down(tester.getCenter(junction));
|
||||
await mouse.moveBy(const Offset(60, -40));
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.moveTo(const Offset(1450, 50));
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({'sidebar', 'timeline'});
|
||||
await mouse.up();
|
||||
await tester.pumpAndSettle();
|
||||
await expectPainted({});
|
||||
await mouse.moveTo(tester.getCenter(junction));
|
||||
await mouse.down(tester.getCenter(junction));
|
||||
await mouse.moveBy(const Offset(-300, 20));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sidebarCollapsed, isTrue);
|
||||
await expectPainted({'sidebar', 'timeline'});
|
||||
final node = tester.getRect(
|
||||
find.descendant(of: junction, matching: find.byType(DecoratedBox)),
|
||||
);
|
||||
expect(node.center.dx, 0);
|
||||
expect(tester.getSize(junction).width, 10);
|
||||
// Reverse the same drag: feedback returns to the expanded boundary.
|
||||
await mouse.moveBy(const Offset(150, -20));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sidebarCollapsed, isFalse);
|
||||
await expectPainted({'sidebar', 'timeline'});
|
||||
final expandedNode = tester.getRect(
|
||||
find.descendant(of: junction, matching: find.byType(DecoratedBox)),
|
||||
);
|
||||
expect(expandedNode.center.dx, tester.getCenter(junction).dx);
|
||||
await mouse.up();
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'media/timeline junction drags both splits and clamps each axis',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1100, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
var mediaWidth = 260.0;
|
||||
var timelineHeight = 280.0;
|
||||
var showMedia = true;
|
||||
var saves = 0;
|
||||
var singleAxisEnds = 0;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ExpandedEditorLayout(
|
||||
preview: const SizedBox.expand(),
|
||||
header: const SizedBox(height: 40),
|
||||
properties: const SizedBox.expand(),
|
||||
media: const SizedBox.expand(),
|
||||
showMedia: showMedia,
|
||||
showProperties: true,
|
||||
mediaWidth: mediaWidth,
|
||||
onMediaWidthChanged: (value) =>
|
||||
setState(() => mediaWidth = value),
|
||||
onMediaWidthChangeEnd: () => singleAxisEnds++,
|
||||
timelineHeight: timelineHeight,
|
||||
onTimelineHeightChanged: (value) =>
|
||||
setState(() => timelineHeight = value),
|
||||
onTimelineHeightChangeEnd: () => singleAxisEnds++,
|
||||
onJunctionResizeEnd: () => saves++,
|
||||
timeline: const SizedBox.expand(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final junction = find.byKey(const Key('editor-media-timeline-junction'));
|
||||
Rect card(String name) =>
|
||||
tester.getRect(find.byKey(Key('editor-$name-card')));
|
||||
final center = tester.getCenter(junction);
|
||||
expect(center.dx, (card('media').right + card('preview').left) / 2);
|
||||
expect(center.dy, (card('preview').bottom + card('timeline').top) / 2);
|
||||
await tester.drag(junction, const Offset(80, -60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 340);
|
||||
expect(card('timeline').height, 340);
|
||||
expect(saves, 1);
|
||||
expect(singleAxisEnds, 0);
|
||||
await tester.drag(junction, const Offset(-40, 30));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 300);
|
||||
expect(card('timeline').height, 310);
|
||||
expect(saves, 2);
|
||||
await tester.drag(junction, const Offset(-2000, -2000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 220);
|
||||
expect(card('preview').height, 180);
|
||||
await tester.drag(junction, const Offset(80, -60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 300);
|
||||
expect(card('preview').height, 180);
|
||||
await tester.drag(junction, const Offset(2000, 2000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('preview').width, 320);
|
||||
expect(card('timeline').height, 220);
|
||||
expect(saves, 5);
|
||||
expect(singleAxisEnds, 0);
|
||||
update(() => showMedia = false);
|
||||
await tester.pump();
|
||||
expect(junction, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('media width drags, respects other panels and survives hiding', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1100, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
double? mediaWidth;
|
||||
var showMedia = true;
|
||||
var saves = 0;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ExpandedEditorLayout(
|
||||
preview: const SizedBox.expand(),
|
||||
header: const SizedBox(height: 40),
|
||||
properties: const SizedBox.expand(),
|
||||
media: const SizedBox.expand(key: Key('test-media')),
|
||||
showMedia: showMedia,
|
||||
showProperties: true,
|
||||
mediaWidth: mediaWidth,
|
||||
onMediaWidthChanged: (value) =>
|
||||
setState(() => mediaWidth = value),
|
||||
onMediaWidthChangeEnd: () => saves++,
|
||||
timelineHeight: 220,
|
||||
onTimelineHeightChanged: (_) {},
|
||||
onTimelineHeightChangeEnd: () {},
|
||||
onJunctionResizeEnd: () {},
|
||||
timeline: const SizedBox.expand(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
Rect card(String name) =>
|
||||
tester.getRect(find.byKey(Key('editor-$name-card')));
|
||||
final resize = find.byKey(const Key('editor-media-resize'));
|
||||
final mediaElement = tester.element(find.byKey(const Key('test-media')));
|
||||
expect(card('media').width, 260);
|
||||
expect(tester.getSize(resize).width, 10);
|
||||
expect(tester.getRect(resize).bottom, card('preview').bottom);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(resize) + const Offset(4, 0),
|
||||
const Offset(80, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 340);
|
||||
expect(saves, 1);
|
||||
expect(card('preview').left - card('media').right, 2);
|
||||
expect(card('properties').width, 240);
|
||||
await tester.drag(resize, const Offset(2000, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('preview').width, 320);
|
||||
expect(card('media').width, 536);
|
||||
await tester.drag(resize, const Offset(-2000, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 220);
|
||||
expect(saves, 3);
|
||||
update(() => mediaWidth = 400);
|
||||
await tester.pump();
|
||||
tester.view.physicalSize = const Size(900, 800);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 336);
|
||||
expect(card('preview').width, 320);
|
||||
expect(mediaWidth, 400);
|
||||
tester.view.physicalSize = const Size(1100, 800);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('media').width, 400);
|
||||
update(() => showMedia = false);
|
||||
await tester.pump();
|
||||
expect(resize, findsNothing);
|
||||
update(() => showMedia = true);
|
||||
await tester.pump();
|
||||
expect(card('media').width, 400);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('test-media'))),
|
||||
same(mediaElement),
|
||||
);
|
||||
expect(saves, 3);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('inspector has an independent frame aligned with the preview', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -28,9 +415,13 @@ void main() {
|
||||
media: const SizedBox(),
|
||||
showMedia: false,
|
||||
showProperties: showProperties,
|
||||
mediaWidth: null,
|
||||
onMediaWidthChanged: (_) {},
|
||||
onMediaWidthChangeEnd: () {},
|
||||
timelineHeight: 200,
|
||||
onTimelineHeightChanged: (_) {},
|
||||
onTimelineHeightChangeEnd: () {},
|
||||
onJunctionResizeEnd: () {},
|
||||
timeline: const SizedBox(),
|
||||
);
|
||||
},
|
||||
@@ -65,7 +456,7 @@ void main() {
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('preview and timeline cards resize through their 6 dp gap', (
|
||||
testWidgets('preview and timeline cards resize through their narrow gap', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(700, 800);
|
||||
@@ -84,10 +475,14 @@ void main() {
|
||||
media: const SizedBox(),
|
||||
showMedia: false,
|
||||
showProperties: false,
|
||||
mediaWidth: null,
|
||||
onMediaWidthChanged: (_) {},
|
||||
onMediaWidthChangeEnd: () {},
|
||||
timelineHeight: timelineHeight,
|
||||
onTimelineHeightChanged: (value) =>
|
||||
update(() => timelineHeight = value),
|
||||
onTimelineHeightChangeEnd: () => saves++,
|
||||
onJunctionResizeEnd: () {},
|
||||
timeline: const Column(
|
||||
children: [
|
||||
Text('Toolbar'),
|
||||
|
||||
@@ -66,7 +66,7 @@ void main() {
|
||||
expect(find.byKey(const Key('timeline-toolbar')), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('timeline-add-button'))),
|
||||
const Size.square(26),
|
||||
const Size.square(24),
|
||||
);
|
||||
for (final button in tester.widgetList<IconButton>(
|
||||
find.byType(IconButton),
|
||||
|
||||
@@ -131,7 +131,7 @@ void main() {
|
||||
.top,
|
||||
),
|
||||
);
|
||||
expect(settingsRect.left - navigationRect.right, 6);
|
||||
expect(settingsRect.left - navigationRect.right, 2);
|
||||
expect(settingsRect.top, navigationRect.top);
|
||||
expect(settingsRect.bottom, navigationRect.bottom);
|
||||
expect(find.byKey(const Key('settings-sidebar-divider')), findsNothing);
|
||||
@@ -885,13 +885,13 @@ void main() {
|
||||
.textStyle!
|
||||
.resolve({})!
|
||||
.fontSize,
|
||||
13,
|
||||
11,
|
||||
);
|
||||
final projectTabFinder = find.byKey(
|
||||
const ValueKey('timeline-tab-project'),
|
||||
);
|
||||
final tabRect = tester.getRect(projectTabFinder);
|
||||
expect(tabRect.height, 26);
|
||||
expect(tabRect.height, 24);
|
||||
for (final key in ['timeline-add-button', 'timeline-list-button']) {
|
||||
final buttonRect = tester.getRect(find.byKey(Key(key)));
|
||||
expect(buttonRect.height, tabRect.height);
|
||||
@@ -901,7 +901,7 @@ void main() {
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('timeline-tabs-bar'))).right -
|
||||
tester.getRect(find.byKey(const Key('timeline-list-button'))).right,
|
||||
4,
|
||||
8,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
@@ -909,8 +909,7 @@ void main() {
|
||||
.style!
|
||||
.backgroundColor!
|
||||
.resolve({}),
|
||||
Theme.of(tester.element(projectTabFinder)).colorScheme.primary
|
||||
.withValues(alpha: .12),
|
||||
Theme.of(tester.element(projectTabFinder)).colorScheme.surfaceContainer,
|
||||
);
|
||||
expect(find.byKey(const ValueKey('timeline-tab-second')), findsOneWidget);
|
||||
final tabs = find.byKey(const Key('timeline-tabs-list'));
|
||||
|
||||
@@ -5,11 +5,92 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final axis in Axis.values) {
|
||||
for (final finish in ['release', 'cancel', 'unmount']) {
|
||||
testWidgets('$axis resize cursor stays locked until $finish', (
|
||||
for (final axis in [...Axis.values, null]) {
|
||||
testWidgets('$axis feedback fades and expands with rounded ends', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = find.byKey(const Key('animated-handle'));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: axis == Axis.vertical ? 200 : 10,
|
||||
height: axis == Axis.horizontal ? 200 : 10,
|
||||
child: axis == null
|
||||
? WorkspaceResizeHandle.junction(
|
||||
key: const Key('animated-handle'),
|
||||
initialWidth: 100,
|
||||
initialHeight: 100,
|
||||
onWidthChanged: (_) {},
|
||||
onHeightChanged: (_) {},
|
||||
)
|
||||
: WorkspaceResizeHandle(
|
||||
key: const Key('animated-handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
onResize: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final fade = find.descendant(of: handle, matching: find.byType(Opacity));
|
||||
final paint = find.descendant(
|
||||
of: handle,
|
||||
matching: find.byType(DecoratedBox),
|
||||
);
|
||||
double opacity() => tester.widget<Opacity>(fade).opacity;
|
||||
final hitSize = tester.getSize(handle);
|
||||
final center = tester.getCenter(handle);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
expect(opacity(), 0);
|
||||
await mouse.addPointer(location: center);
|
||||
await tester.pump();
|
||||
expect(opacity(), 0);
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
expect(opacity(), inExclusiveRange(0, 1));
|
||||
final growing = tester.getRect(paint);
|
||||
expect(
|
||||
axis == Axis.vertical ? growing.height : growing.width,
|
||||
inExclusiveRange(2, 4),
|
||||
);
|
||||
expect(tester.getSize(handle), hitSize);
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 1);
|
||||
final decoration =
|
||||
tester.widget<DecoratedBox>(paint).decoration as BoxDecoration;
|
||||
expect(decoration.borderRadius, BorderRadius.circular(2));
|
||||
await mouse.moveTo(const Offset(10, 10));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 30));
|
||||
final fading = opacity();
|
||||
expect(fading, inExclusiveRange(0, 1));
|
||||
// Reentering mid-fade continues from its current appearance.
|
||||
await mouse.moveTo(center);
|
||||
await tester.pump();
|
||||
expect(opacity(), closeTo(fading, .001));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 1);
|
||||
await mouse.moveTo(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 0);
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
for (final axis in [...Axis.values, null]) {
|
||||
for (final finish in ['release', 'cancel', 'unmount']) {
|
||||
testWidgets(
|
||||
'$axis resize cursor stays locked until $finish',
|
||||
(tester) async {
|
||||
final expectedCursor = axis == null
|
||||
? SystemMouseCursors.grab
|
||||
: axis == Axis.horizontal
|
||||
? SystemMouseCursors.resizeColumn
|
||||
: SystemMouseCursors.resizeRow;
|
||||
var showHandle = true;
|
||||
var taps = 0;
|
||||
var ends = 0;
|
||||
@@ -42,9 +123,29 @@ void main() {
|
||||
Positioned(
|
||||
left: 100,
|
||||
top: 100,
|
||||
width: axis == Axis.horizontal ? 5 : 200,
|
||||
height: axis == Axis.horizontal ? 200 : 5,
|
||||
child: WorkspaceResizeHandle(
|
||||
width: axis == null || axis == Axis.horizontal
|
||||
? 5
|
||||
: 200,
|
||||
height: axis == null || axis == Axis.vertical
|
||||
? 5
|
||||
: 200,
|
||||
child: axis == null
|
||||
? WorkspaceResizeHandle.junction(
|
||||
key: const Key('handle'),
|
||||
initialWidth: 100,
|
||||
initialHeight: 100,
|
||||
onStart: () => starts++,
|
||||
onWidthChanged: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onHeightChanged: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onEnd: () => ends++,
|
||||
)
|
||||
: WorkspaceResizeHandle(
|
||||
key: const Key('handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
@@ -63,24 +164,44 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
final mouse = await tester.createGesture(
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
final start = tester.getCenter(find.byKey(const Key('handle')));
|
||||
final button = tester.getCenter(find.byKey(const Key('button')));
|
||||
double highlightOpacity() => tester
|
||||
.widget<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('handle')),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.opacity;
|
||||
expect(highlightOpacity(), 0);
|
||||
await mouse.addPointer(location: start);
|
||||
await tester.pumpAndSettle();
|
||||
expect(highlightOpacity(), 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
expectedCursor,
|
||||
);
|
||||
await mouse.down(start);
|
||||
await mouse.moveBy(
|
||||
axis == Axis.horizontal ? const Offset(30, 0) : const Offset(0, 30),
|
||||
axis == null
|
||||
? const Offset(30, 30)
|
||||
: axis == Axis.horizontal
|
||||
? const Offset(30, 0)
|
||||
: const Offset(0, 30),
|
||||
);
|
||||
await tester.pump();
|
||||
await mouse.moveTo(button);
|
||||
await tester.pump();
|
||||
expect(updates, greaterThan(0));
|
||||
expect(starts, 1);
|
||||
expect(highlightOpacity(), 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
axis == Axis.horizontal
|
||||
? SystemMouseCursors.resizeColumn
|
||||
: SystemMouseCursors.resizeRow,
|
||||
axis == null ? SystemMouseCursors.grabbing : expectedCursor,
|
||||
);
|
||||
// A second pointer still reaches the control through the cursor overlay.
|
||||
await tester.tap(find.byKey(const Key('button')));
|
||||
@@ -103,9 +224,25 @@ void main() {
|
||||
SystemMouseCursors.click,
|
||||
);
|
||||
expect(ends, finish == 'unmount' ? 0 : 1);
|
||||
if (finish != 'unmount') {
|
||||
expect(highlightOpacity(), 0);
|
||||
await mouse.moveTo(start);
|
||||
await tester.pumpAndSettle();
|
||||
expect(highlightOpacity(), 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
expectedCursor,
|
||||
);
|
||||
}
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
},
|
||||
variant: const TargetPlatformVariant({
|
||||
TargetPlatform.macOS,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.linux,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user