import 'dart:math' as math; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import '../../../shared/layout/workspace_layout_metrics.dart'; class ExpandedEditorLayout extends StatefulWidget { const ExpandedEditorLayout({ super.key, required this.preview, 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 properties; final Widget media; final bool showMedia; final bool showProperties; final double? timelineHeight; final ValueChanged onTimelineHeightChanged; final VoidCallback onTimelineHeightChangeEnd; final Widget timeline; @override State createState() => _ExpandedEditorLayoutState(); } class _ExpandedEditorLayoutState extends State { double? _timelineDragStartY; double _timelineDragStartHeight = 0; @override Widget build(BuildContext context) => LayoutBuilder( builder: (context, constraints) { final maximum = math.max( 0.0, constraints.maxHeight - 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: 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(width: 1), SizedBox( key: const Key('editor-properties-region'), width: propertiesWidth, child: widget.properties, ), ], ], ), ), const SizedBox(height: 1), SizedBox(height: timelineHeight, child: widget.timeline), ], ), Positioned( key: const Key('editor-timeline-divider'), left: 0, right: 0, bottom: timelineHeight - 4, height: 8, child: MouseRegion( cursor: SystemMouseCursors.resizeRow, child: GestureDetector( key: const Key('editor-timeline-resize'), behavior: HitTestBehavior.opaque, dragStartBehavior: DragStartBehavior.down, onVerticalDragStart: (details) { _timelineDragStartY = details.globalPosition.dy; _timelineDragStartHeight = timelineHeight; }, onVerticalDragUpdate: (details) { final start = _timelineDragStartY; if (start == null) return; widget.onTimelineHeightChanged( (_timelineDragStartHeight + start - details.globalPosition.dy) .clamp(minimum, maximum) .toDouble(), ); }, onVerticalDragEnd: (_) { _timelineDragStartY = null; widget.onTimelineHeightChangeEnd(); }, onVerticalDragCancel: () { _timelineDragStartY = null; widget.onTimelineHeightChangeEnd(); }, child: const Center( child: SizedBox( height: 1, width: double.infinity, child: Divider(height: 1), ), ), ), ), ), ], ); }, ); }