import 'dart:math' as math; import 'package:flutter/material.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.mediaWidth, required this.onMediaWidthChanged, required this.onMediaWidthChangeEnd, required this.timelineHeight, required this.onTimelineHeightChanged, required this.onTimelineHeightChangeEnd, required this.onJunctionResizeEnd, required this.timeline, }); final Widget preview; final Widget header; final Widget properties; final Widget media; final bool showMedia; final bool showProperties; final double? mediaWidth; final ValueChanged onMediaWidthChanged; final VoidCallback onMediaWidthChangeEnd; final double? timelineHeight; final ValueChanged onTimelineHeightChanged; final VoidCallback onTimelineHeightChangeEnd; final VoidCallback onJunctionResizeEnd; final Widget timeline; @override State createState() => _ExpandedEditorLayoutState(); } class _ExpandedEditorLayoutState extends State { static const gap = WorkspaceLayoutMetrics.desktopSpacing; late bool _mediaVisited = widget.showMedia; @override void didUpdateWidget(covariant ExpandedEditorLayout oldWidget) { super.didUpdateWidget(oldWidget); _mediaVisited |= widget.showMedia; } Widget _card(String name, Widget child) => WorkspaceCard(key: Key('editor-$name-card'), child: child); @override Widget build(BuildContext context) => WorkspaceResizeHighlightScope(child: _layout()); Widget _layout() => LayoutBuilder( builder: (context, constraints) { 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: [ Column( children: [ Expanded( child: Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ if (_mediaVisited) Offstage( offstage: !widget.showMedia, child: ExcludeFocus( excluding: !widget.showMedia, child: TickerMode( enabled: widget.showMedia, child: SizedBox( key: const Key('editor-media-region'), width: mediaWidth, child: _card('media', widget.media), ), ), ), ), if (widget.showMedia) const SizedBox(width: gap), Expanded( child: _card( 'preview', Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ widget.header, Expanded(child: widget.preview), ], ), ), ), if (widget.showProperties) ...[ const SizedBox( key: Key('editor-properties-divider'), width: gap, ), SizedBox( key: const Key('editor-properties-region'), width: propertiesWidth, child: _card('properties', widget.properties), ), ], ], ), ), const SizedBox(height: gap), SizedBox( height: timelineHeight, child: _card('timeline', widget.timeline), ), ], ), 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, right: 0, bottom: timelineHeight - WorkspaceLayoutMetrics.desktopResizeSlop, 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(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, ), ), ], ); }, ); }