feat(workspace): add workflow navigation and resizable desktop panels

This commit is contained in:
lingjhf committed 2026-10-09 19:23:49 +08:00
1 parent 02413383d8
commit 1acfe4a005
17 files changed
+2008 -277

No files matched your search

@@ -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,
+93 -74
View File
@@ -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,90 +119,109 @@ class DesktopWindowFrame extends StatelessWidget {
Expanded(
child: Row(
children: [
if (projectTabs == null)
SizedBox(
key: const Key('desktop-navigation-rail'),
width: railWidth,
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,
},
isSelected:
!settingsSelected &&
(section == 2
? resourceLibrarySelected
: !resourceLibrarySelected),
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:
!settingsSelected &&
(section == 2
? resourceLibrarySelected
: !resourceLibrarySelected)
? null
: Colors.transparent,
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: [
IconButton.filledTonal(
key: const ValueKey('desktop-rail-home'),
tooltip: context.l10n.navigationHome,
isSelected:
!settingsSelected && !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:
settingsSelected || workflowSelected
? Colors.transparent
: null,
),
onPressed: onHomePressed,
icon: const Icon(AppIcons.home),
),
onPressed: switch (section) {
0 => onHomePressed,
_ => onResourceLibraryPressed,
},
icon: Icon(switch (section) {
0 => AppIcons.home,
_ => AppIcons.folder,
}),
),
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: onWorkflowPressed,
icon: const Icon(AppIcons.timeline),
),
const Spacer(),
IconButton(
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,
),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
),
icon: const Icon(AppIcons.settings),
),
],
),
const Spacer(),
IconButton(
key: const Key('project-settings-button'),
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),
padding: EdgeInsets.zero,
iconSize: railIconSize,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
icon: const Icon(AppIcons.settings),
),
],
),
),
),
),
),
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
+121 -9
View File
@@ -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)
+33 -11
View File
@@ -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(
projectId: widget.projectId,
timelineId: widget.timelineId,
pending: _timelinePending,
? 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,
);
final minimum = math.min(
WorkspaceLayoutMetrics.timelineMinimumHeight,
maximum,
);
final timelineHeight =
(widget.timelineHeight ??
constraints.maxHeight *
WorkspaceLayoutMetrics.timelineDefaultHeightFraction)
.clamp(minimum, maximum)
.toDouble();
const mediaWidth = WorkspaceLayoutMetrics.mediaPanelWidth;
double resolveTimelineHeight(double? height) =>
WorkspaceLayoutMetrics.resolveTimelineHeight(
constraints.maxHeight,
height,
);
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,
),
),
],
);
},
+77 -22
View File
@@ -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,
+50
View File
@@ -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)
+250 -16
View File
@@ -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,
),
),
),
),
),
),
),
),
);
}