Files
cutdex/lib/features/editor/layouts/expanded_editor_layout.dart
T
lingjhf 1f73765745
Gitea CI / Windows x64 and Android (pull_request) Successful in 16m21s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s
refactor(desktop): reorganize workspace panels and navigation
2026-10-06 12:11:59 +08:00

151 lines
5.1 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:cutdex_ui/theme.dart';
import '../../../shared/layout/workspace_layout_metrics.dart';
import '../../../shared/widgets/workspace_card.dart';
import '../../../shared/widgets/workspace_resize_handle.dart';
class ExpandedEditorLayout extends StatefulWidget {
const ExpandedEditorLayout({
super.key,
required this.preview,
required this.header,
required this.properties,
required this.media,
required this.showMedia,
required this.showProperties,
required this.timelineHeight,
required this.onTimelineHeightChanged,
required this.onTimelineHeightChangeEnd,
required this.timeline,
});
final Widget preview;
final Widget header;
final Widget properties;
final Widget media;
final bool showMedia;
final bool showProperties;
final double? timelineHeight;
final ValueChanged<double> onTimelineHeightChanged;
final VoidCallback onTimelineHeightChangeEnd;
final Widget timeline;
@override
State<ExpandedEditorLayout> createState() => _ExpandedEditorLayoutState();
}
class _ExpandedEditorLayoutState extends State<ExpandedEditorLayout> {
static const gap = WorkspaceLayoutMetrics.desktopSpacing;
Widget _card(String name, Widget child) =>
WorkspaceCard(key: Key('editor-$name-card'), child: child);
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
final maximum = math.max(
0.0,
constraints.maxHeight -
gap -
AppControlSize.panelToolbar -
WorkspaceLayoutMetrics.timelineMinimumHeight,
);
final minimum = math.min(
WorkspaceLayoutMetrics.timelineMinimumHeight,
maximum,
);
final timelineHeight =
(widget.timelineHeight ??
constraints.maxHeight *
WorkspaceLayoutMetrics.timelineDefaultHeightFraction)
.clamp(minimum, maximum)
.toDouble();
final mediaWidth = widget.showMedia
? WorkspaceLayoutMetrics.mediaPanelWidth
: 0.0;
final propertiesWidth = widget.showProperties
? WorkspaceLayoutMetrics.propertiesPanelWidth
: 0.0;
return Stack(
fit: StackFit.expand,
children: [
Column(
children: [
Expanded(
child: _card(
'preview',
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
widget.header,
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (widget.showMedia) ...[
SizedBox(
key: const Key('editor-media-region'),
width: mediaWidth,
child: widget.media,
),
const VerticalDivider(width: 1),
],
Expanded(child: widget.preview),
],
),
),
],
),
),
if (widget.showProperties) ...[
const VerticalDivider(
key: Key('editor-properties-divider'),
width: 1,
),
SizedBox(
key: const Key('editor-properties-region'),
width: propertiesWidth,
child: widget.properties,
),
],
],
),
),
),
const SizedBox(height: gap),
SizedBox(
height: timelineHeight,
child: _card('timeline', widget.timeline),
),
],
),
Positioned(
key: const Key('editor-timeline-divider'),
left: 0,
right: 0,
bottom: timelineHeight - WorkspaceLayoutMetrics.desktopResizeSlop,
height: WorkspaceLayoutMetrics.desktopResizeHitExtent,
child: WorkspaceResizeHandle(
key: const Key('editor-timeline-resize'),
axis: Axis.vertical,
initialValue: timelineHeight,
direction: -1,
onResize: (height) => widget.onTimelineHeightChanged(
height.clamp(minimum, maximum).toDouble(),
),
onEnd: widget.onTimelineHeightChangeEnd,
),
),
],
);
},
);
}