import 'dart:math' as math; import 'package:flutter/material.dart'; import '../../../integrations/platform/device_experience.dart'; import '../../../l10n/l10n.dart'; import '../../../shared/layout/workspace_layout_metrics.dart'; import 'package:cutdex_ui/icons.dart'; import 'package:cutdex_ui/theme.dart'; import '../editor_presentation_controller.dart'; /// Space changes the tool bounds; device experience determines its interactions. class BoundedEditorLayout extends StatelessWidget { const BoundedEditorLayout({ super.key, required this.experience, required this.editing, required this.tool, required this.media, required this.properties, required this.onCloseTool, }); final DeviceExperience experience; final Widget editing; final EditorTool? tool; final Widget media; final Widget properties; final VoidCallback onCloseTool; @override Widget build(BuildContext context) => LayoutBuilder( builder: (context, constraints) { final page = experience == DeviceExperience.phone; final desktop = experience == DeviceExperience.desktop; Widget toolSurface() => Column( children: [ SizedBox( height: desktop ? AppDesktopMetrics.panelHeader : 48, child: Padding( padding: EdgeInsets.symmetric( horizontal: desktop ? AppSpacing.small : 0, ), child: Row( children: [ SizedBox.square( dimension: desktop ? AppControlSize.headerButton : 48, child: IconButton( key: const Key('editor-tool-close'), tooltip: MaterialLocalizations.of(context) .closeButtonTooltip, onPressed: onCloseTool, icon: Icon(page ? AppIcons.arrowBack : AppIcons.close), ), ), Expanded( child: Text( tool == EditorTool.media ? context.l10n.materials : context.l10n.expandProperties, maxLines: 1, overflow: TextOverflow.ellipsis, style: desktop && tool == EditorTool.properties ? AppTheme.propertiesPanelTheme(Theme.of(context)) .textTheme .titleSmall : null, ), ), ], ), ), ), const Divider(height: 1), Expanded(child: tool == EditorTool.media ? media : properties), ], ); return PopScope( canPop: desktop || tool == null, onPopInvokedWithResult: (didPop, result) { if (didPop || desktop || tool == null) return; final scaffold = Scaffold.maybeOf(context); if (scaffold?.isDrawerOpen ?? false) { scaffold!.closeDrawer(); } else { onCloseTool(); } }, child: Stack( key: Key('${experience.name}-editor-tools'), fit: StackFit.expand, children: [ ExcludeFocus( excluding: page && tool != null, child: IgnorePointer( ignoring: page && tool != null, child: TickerMode( enabled: !page || tool == null, child: editing, ), ), ), if (tool != null) Positioned( top: desktop ? AppDesktopMetrics.panelHeader + 1 : 0, bottom: 0, right: 0, width: page ? constraints.maxWidth : math.min( desktop && tool == EditorTool.properties ? WorkspaceLayoutMetrics.propertiesPanelWidth : 320, constraints.maxWidth, ), child: Material( key: const Key('editor-tool-surface'), elevation: page ? 0 : 8, color: Theme.of(context).colorScheme.surface, child: toolSurface(), ), ), ], ), ); }, ); } /// A shared preview/timeline arrangement for touch experiences. class TouchEditingLayout extends StatelessWidget { const TouchEditingLayout({ super.key, required this.preview, required this.timeline, }); final Widget preview; final Widget timeline; @override Widget build(BuildContext context) => LayoutBuilder( builder: (context, constraints) { final short = constraints.maxHeight < 340 && constraints.maxWidth >= 600; return short ? Row( children: [ Expanded(child: preview), const VerticalDivider(width: 1), Expanded(child: timeline), ], ) : Column( children: [ Expanded(flex: 3, child: preview), const Divider(height: 1), Expanded(flex: 2, child: timeline), ], ); }, ); }