Files
cutdex/lib/features/editor/layouts/bounded_editor_layout.dart
T
lingjhf 2e0033ce2d
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
feat(workspace): refresh desktop editing experience and prepare 0.1.2
2026-10-09 01:56:01 +08:00

153 lines
4.7 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../../../integrations/platform/device_experience.dart';
import '../../../l10n/l10n.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,
),
),
],
),
),
),
const Divider(height: 1),
Expanded(child: tool == EditorTool.media ? media : properties),
],
);
return PopScope<Object?>(
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(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),
],
);
},
);
}