/// 时序图模块 UI:工具栏中段 / 右侧工具、左右侧栏、状态栏。 /// /// 所有方法由 `SequenceModule` 在 `lib/modules/registry.dart` 注册后由外壳调用; /// 本文件只依赖模块自身代码与共享内核(主题 / 持久化 / 通用对话框)。 library; import 'dart:convert'; import 'dart:io'; import 'dart:math' as math; import 'package:flutter/material.dart' hide Action; import 'package:flutter/services.dart'; import 'package:sequence_diagram/model/models.dart'; import 'package:sequence_diagram/model/units.dart'; import 'package:sequence_diagram/modules/module.dart'; import 'package:sequence_diagram/modules/sequence/export/drawio_writer.dart'; import 'package:sequence_diagram/modules/sequence/export/export_renderer.dart'; import 'package:sequence_diagram/modules/sequence/export/svg_writer.dart'; import 'package:sequence_diagram/modules/sequence/layout/layout.dart'; import 'package:sequence_diagram/modules/sequence/ui/ai_dialog.dart'; import 'package:sequence_diagram/modules/sequence/ui/canvas_overlays.dart'; import 'package:sequence_diagram/modules/sequence/ui/canvas_view.dart'; import 'package:sequence_diagram/persistence/android_docs.dart'; import 'package:sequence_diagram/state/app_controller.dart'; import 'package:sequence_diagram/theme/tokens.dart'; import 'package:sequence_diagram/ui/dialogs.dart'; /// 时序图模块 UI 构建器。 class SequenceUi { /// 构造 UI 构建器。 const SequenceUi(this.ui); /// 外壳上下文。 final ModuleUiContext ui; AppController get c => ui.controller; BuildContext get context => ui.context; Tokens get t => ui.tokens; double get _toolScale => ui.toolScale; double _toolFont(double size) => ui.toolFont(size); double get _leftPanelWidth => ui.leftPanelWidth; double get _rightPanelWidth => ui.rightPanelWidth; Widget _panelControls(Tokens t, bool left) => ui.panelControls(left); /// 工具栏中段:AI 生成 + 视图切换。 List buildToolbarCenter(Tokens t, {required bool compact}) => [ _aiBtn(t), SizedBox(width: (compact ? 8 : 12) * _toolScale), _segmented(t, compact: compact), ]; /// 工具栏右侧:导出 / 缩放 / 适应视图 / 时间单位。 List buildToolbarRight(Tokens t, {required bool compact}) => [ _exportMenu(t), SizedBox(width: (compact ? 4 : 6) * _toolScale), _zoomBox(t), SizedBox(width: (compact ? 4 : 6) * _toolScale), _iconBtn(t, Icons.crop_free, c.fitView, tooltip: '适应视图'), SizedBox(width: (compact ? 4 : 8) * _toolScale), _unitDropdown(t), ]; /// 左侧栏。 Widget buildLeftPanel(Tokens t, {bool floating = false}) => _leftPanel(t, floating: floating); /// 右侧栏。 Widget buildRightPanel(Tokens t, {bool floating = false}) => _rightPanel(t, floating: floating); /// 底部状态栏。 Widget buildStatusBar(Tokens t) => _statusBar(t); /// 工作区:可交互画布 + 画布浮层。 Widget buildWorkspace() => Stack( children: [ Positioned.fill( child: Container( color: t.canvas2, child: CanvasView(controller: c), ), ), Positioned.fill( child: CanvasOverlays( controller: c, leftInset: ui.leftRail ? 22 : 0, rightInset: ui.rightRail ? 22 : 0, ), ), ], ); Widget _segmented(Tokens t, {bool compact = false}) { final ViewMode mode = c.project.viewState.mode; Widget seg(String label, bool active, VoidCallback onTap) { return InkWell( onTap: onTap, borderRadius: BorderRadius.circular(10), child: Container( width: (compact ? 84 : 118) * _toolScale, height: 34 * _toolScale, alignment: Alignment.center, decoration: BoxDecoration( color: active ? t.accent.withValues(alpha: 0.16) : Colors.transparent, borderRadius: BorderRadius.circular(10), border: active ? Border.all(color: t.accent, width: 1.4) : null, ), child: Text(label, style: TextStyle( color: active ? t.accent : t.sub, fontWeight: active ? FontWeight.w600 : FontWeight.normal, fontSize: _toolFont(12), )), ), ); } return Container( padding: EdgeInsets.all(3 * _toolScale), decoration: BoxDecoration( color: t.panel, borderRadius: BorderRadius.circular(12), border: Border.all(color: t.line2), ), child: Row( children: [ seg('条形节拍', mode == ViewMode.bar, () => c.setViewMode(ViewMode.bar)), seg('圆周节拍', mode == ViewMode.circular, () => c.setViewMode(ViewMode.circular)), seg('流程图', mode == ViewMode.flow, () => c.setViewMode(ViewMode.flow)), ], ), ); } Widget _zoomBox(Tokens t) { final double s = _toolScale; final double zoom = c.project.viewState.zoom; final String pct = '${(zoom * 100).round()}%'; return Container( height: 34 * s, padding: EdgeInsets.symmetric(horizontal: 4 * s), decoration: BoxDecoration( color: t.panel, borderRadius: BorderRadius.circular(9), border: Border.all(color: t.line2), ), child: Row( children: [ _miniIcon(t, Icons.remove, () => c.zoomBy(0.9)), SizedBox( width: 52 * s, child: Text(pct, textAlign: TextAlign.center, style: TextStyle(color: t.text, fontSize: _toolFont(11))), ), _miniIcon(t, Icons.add, () => c.zoomBy(1.1)), ], ), ); } Widget _miniIcon(Tokens t, IconData icon, VoidCallback onTap) { return InkWell( onTap: onTap, borderRadius: BorderRadius.circular(6), child: Padding( padding: EdgeInsets.all(6 * _toolScale), child: Icon(icon, size: 15 * _toolScale, color: t.sub), ), ); } Widget _unitDropdown(Tokens t) { final double s = _toolScale; return Container( height: 34 * s, padding: EdgeInsets.symmetric(horizontal: 10 * s), decoration: BoxDecoration( color: t.panel, borderRadius: BorderRadius.circular(9), border: Border.all(color: t.accent, width: 1.2), ), child: DropdownButton( value: c.project.units.timeUnit, underline: const SizedBox.shrink(), dropdownColor: t.dialog, borderRadius: BorderRadius.circular(9), style: TextStyle(color: t.accent, fontSize: _toolFont(11), fontWeight: FontWeight.w600), icon: Icon(Icons.keyboard_arrow_down, color: t.accent, size: 18 * s), items: TimeUnit.values .map((TimeUnit u) => DropdownMenuItem(value: u, child: Text(timeUnitLabel(u)))) .toList(), onChanged: (TimeUnit? u) { if (u != null) c.setUnits(c.project.units.copyWith(timeUnit: u)); }, ), ); } Widget _exportMenu(Tokens t) { final double s = _toolScale; final bool licensed = c.licensed; final bool flow = c.project.viewState.mode == ViewMode.flow; final Color fg = licensed ? Colors.white : t.dim; return Padding( padding: EdgeInsets.symmetric(horizontal: 3 * s), child: PopupMenuButton( tooltip: '导出(SVG / PNG${flow ? ' / drawio' : ''})', color: t.panel2, position: PopupMenuPosition.under, onSelected: (String v) { if (v == 'svg') _exportSvg(); if (v == 'png') _exportPng(); if (v == 'drawio') _exportDrawio(); }, itemBuilder: (BuildContext ctx) => >[ _exportItem(t, 'svg', Icons.code, '导出 SVG', '矢量图:无损缩放 / 打印 / 二次编辑', licensed), _exportItem(t, 'png', Icons.image_outlined, '导出 PNG', '位图(3840×2160):分享 / 汇报', licensed), if (flow) _exportItem(t, 'drawio', Icons.account_tree_outlined, '导出 drawio', 'diagrams.net 可编辑工程', licensed), ], child: Container( height: 34 * s, padding: EdgeInsets.symmetric(horizontal: 12 * s), decoration: BoxDecoration( color: licensed ? t.accent2 : t.panel2, borderRadius: BorderRadius.circular(9), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.ios_share, size: 15 * s, color: fg), SizedBox(width: 6 * s), Text('导出', style: TextStyle(fontSize: _toolFont(11), fontWeight: FontWeight.w600, color: fg)), Icon(Icons.arrow_drop_down, size: 18 * s, color: fg), ], ), ), ), ); } PopupMenuItem _exportItem( Tokens t, String value, IconData icon, String label, String hint, bool enabled) { final Color main = enabled ? t.text : t.dim; return PopupMenuItem( value: value, enabled: enabled, height: 46, child: Row( children: [ Icon(icon, size: 17, color: enabled ? t.accent : t.dim), const SizedBox(width: 10), Expanded( child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(label, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: main, fontSize: 12.5, fontWeight: FontWeight.w600)), Text(hint, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: enabled ? t.dim : t.dim.withValues(alpha: 0.6), fontSize: 10)), ], ), ), ], ), ); } Widget _aiBtn(Tokens t) { final double s = _toolScale; final bool enabled = c.project.viewState.mode != ViewMode.flow; final Widget btn = FilledButton.icon( onPressed: enabled ? () => showDialog( context: context, builder: (_) => AiGenerateDialog(controller: c), ) : null, icon: Icon(Icons.auto_awesome, size: 16 * s), label: Text('AI 生成', style: TextStyle(fontSize: _toolFont(12), fontWeight: FontWeight.w700)), style: FilledButton.styleFrom( backgroundColor: enabled ? t.accent2 : t.panel2, foregroundColor: enabled ? Colors.white : t.dim, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)), padding: EdgeInsets.symmetric(horizontal: 10 * s, vertical: 8 * s), minimumSize: Size(0, 34 * s), tapTargetSize: MaterialTapTargetSize.shrinkWrap, ), ); return Padding( padding: EdgeInsets.symmetric(horizontal: 3 * s), child: enabled ? btn : Tooltip(message: 'AI 生成仅针对时序图(条形 / 圆周视图)', child: btn), ); } Widget _iconBtn(Tokens t, IconData icon, VoidCallback? onTap, {String? tooltip, Color? color}) { final double s = _toolScale; return IconButton( onPressed: onTap, icon: Icon(icon, size: 18 * s, color: onTap == null ? t.dim : (color ?? t.text)), tooltip: tooltip, splashRadius: 16 * s, padding: EdgeInsets.zero, constraints: BoxConstraints(minWidth: 34 * s, minHeight: 34 * s), // 新版 Flutter 的 IconButton 已移除 tapTargetSize 形参,改由 style 提供。 style: IconButton.styleFrom(tapTargetSize: s < 1 ? MaterialTapTargetSize.shrinkWrap : null), ); } Future _exportSvg() async { if (!c.licensed) { if (context.mounted) await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 SVG。'); return; } // 安卓版:写入公共 Documents/EDC。 if (AndroidDocs.isAvailable) { final String? name = await showDialog( context: context, builder: (_) => AndroidFileDialog( saveMode: true, defaultName: '${c.project.name}.svg', suffix: '.svg', ), ); if (name == null) return; try { final String svg = SvgWriter( project: c.project, tokens: Tokens.of(c.brightness), mode: c.project.viewState.mode, ).build(); await AndroidDocs.saveFile(name, Uint8List.fromList(utf8.encode(svg)), mime: 'image/svg+xml'); if (context.mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name'); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); } return; } final String? path = await pickFile( context, save: true, defaultName: '${c.project.name}.svg', suffix: '.svg', ); if (path == null) return; try { final String svg = SvgWriter( project: c.project, tokens: Tokens.of(c.brightness), mode: c.project.viewState.mode, ).build(); await File(path).writeAsString(svg, flush: true); if (context.mounted) c.setStatus('已导出 $path'); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); } } Future _exportPng() async { if (!c.licensed) { if (context.mounted) await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 PNG。'); return; } final Uint8List bytes; try { bytes = await renderExportPng( project: c.project, tokens: Tokens.of(c.brightness), criticalActions: c.criticalActions, criticalDeps: c.criticalDeps, ); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); return; } if (!context.mounted) return; // 安卓版:写入配置的公共目录。 if (AndroidDocs.isAvailable) { final String? name = await showDialog( context: context, builder: (_) => AndroidFileDialog( saveMode: true, defaultName: '${c.project.name}.png', suffix: '.png', ), ); if (name == null) return; try { await AndroidDocs.saveFile(name, bytes, mime: 'image/png'); if (context.mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name'); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); } return; } final String? path = await pickFile( context, save: true, defaultName: '${c.project.name}.png', suffix: '.png', ); if (path == null) return; try { await File(path).writeAsBytes(bytes, flush: true); if (context.mounted) c.setStatus('已导出 $path'); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); } } Future _exportDrawio() async { if (c.project.viewState.mode != ViewMode.flow) { if (context.mounted) { await showMessage(context, '导出 drawio', '仅流程图视图支持导出 drawio;条形 / 圆周视图请导出 SVG 或 PNG。'); } return; } if (!c.licensed) { if (context.mounted) await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 drawio。'); return; } final String xml = DrawioWriter(project: c.project, tokens: Tokens.of(c.brightness)).build(); // 安卓版:写入公共 Documents 目录。 if (AndroidDocs.isAvailable) { final String? name = await showDialog( context: context, builder: (_) => AndroidFileDialog( saveMode: true, defaultName: '${c.project.name}.drawio', suffix: '.drawio', ), ); if (name == null) return; try { await AndroidDocs.saveFile(name, Uint8List.fromList(utf8.encode(xml)), mime: 'application/xml'); if (context.mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name'); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); } return; } final String? path = await pickFile( context, save: true, defaultName: '${c.project.name}.drawio', suffix: '.drawio', ); if (path == null) return; try { await File(path).writeAsString(xml, flush: true); if (context.mounted) c.setStatus('已导出 $path'); } catch (e) { if (context.mounted) await showMessage(context, '导出失败', '$e'); } } Widget _leftPanel(Tokens t, {bool floating = false}) { final bool bar = c.project.viewState.mode == ViewMode.bar; final bool flow = c.project.viewState.mode == ViewMode.flow; return Container( width: _leftPanelWidth, decoration: BoxDecoration( color: t.panel, border: floating ? Border.all(color: t.line2) : Border(right: BorderSide(color: t.line)), boxShadow: floating ? [BoxShadow(color: Colors.black.withValues(alpha: 0.4), blurRadius: 20, offset: const Offset(4, 0))] : null, ), child: SingleChildScrollView( padding: const EdgeInsets.fromLTRB(12, 10, 12, 12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ _sectionLabel(t, '文档设置'), const Spacer(), _panelControls(t, true), ], ), const SizedBox(height: 8), _editEntry( t, icon: Icons.edit_note, label: '文档设置', enabled: !flow, onTap: () => showDialog( context: context, builder: (_) => SettingsDialog(controller: c), ), ), // 较浅的分隔横线,区分上方「文档设置」与下方「动作和执行编辑」。 const SizedBox(height: 14), Divider(height: 1, thickness: 1, color: t.line), const SizedBox(height: 14), Row( children: [ // 用 Expanded 占满剩余空间,标题不会被无谓地省略成「…」。 Expanded(child: _sectionLabel(t, '动作和执行编辑')), _headerAction(t, Icons.add, '新建', t.ok, t.onAccent, flow ? null : () => c.addAction(startAngle: 0)), const SizedBox(width: 6), // 至少保留一个动作 / 泳道:只剩一个时禁用删除;流程图只读时禁用。 _headerAction( t, Icons.delete_outline, '删除', t.danger, Colors.white, (flow || c.selectedId == null || c.project.actions.length <= 1) ? null : () => c.deleteAction(c.selectedId!), ), ], ), const SizedBox(height: 8), // 按泳道 / 轨道分组:同一泳道内的多个动作合并显示(最多两行,/ 分隔)。 ..._laneRows(t, bar), const SizedBox(height: 8), // 工位 / 相位分区管理入口,同属「动作和执行编辑」区域。 // 工位:一个流程可包含多个工位,可增删改与排序。 _editEntry( t, icon: Icons.precision_manufacturing_outlined, label: '编辑工位', badge: c.project.stations.length, enabled: !flow, onTap: () => showDialog( context: context, builder: (_) => StationDialog(controller: c), ), ), const SizedBox(height: 8), // 相位分区:可任意增删、改名、改起止角;流程图只读时置灰。 _editEntry( t, icon: Icons.tune, label: '编辑相位分区', badge: c.project.phaseZones.length, enabled: !flow, onTap: () => showDialog( context: context, builder: (_) => PhaseZoneDialog(controller: c), ), ), const SizedBox(height: 12), _sectionLabel(t, '视图模式'), const SizedBox(height: 8), // 该栏永久只保留条形 / 圆周两个时序视图的切换; // 流程图由时序图生成、属独立载体,入口在顶部工具栏(不在本栏混排)。 Row( children: [ Expanded(child: _modeButton(t, '条形节拍(甘特)', c.project.viewState.mode == ViewMode.bar, () => c.setViewMode(ViewMode.bar))), const SizedBox(width: 8), Expanded(child: _modeButton(t, '圆周节拍(同心)', c.project.viewState.mode == ViewMode.circular, () => c.setViewMode(ViewMode.circular))), ], ), const SizedBox(height: 12), _sectionLabel(t, '显示选项'), const SizedBox(height: 6), ..._displayOptions(t, bar), const SizedBox(height: 8), _sectionLabel(t, '工位负载 / 相位占用'), const SizedBox(height: 10), ..._stationLoads(t), const SizedBox(height: 12), Container( padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: t.info, borderRadius: BorderRadius.circular(10), border: Border.all(color: t.line), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('操作提示', style: TextStyle(color: t.warn, fontSize: 11, fontWeight: FontWeight.w700)), const SizedBox(height: 6), // 提示随视图模式切换:流程图是只读预览,给出交互方式说明。 if (flow) ...[ Text('流程图只读:点击节点可选中对应动作', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), Text('滚轮缩放 · 拖拽平移 · Ctrl+滚轮连续缩放', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), Text('需要修改请切回条形 / 圆周视图', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), ] else ...[ Text('拖拽动作块平移相位 · 拖端点改持续角', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), Text('Shift+拖拽改层 · Ctrl+滚轮缩放', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), Text('双击空白新建动作 · F1 打开帮助', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), ], ], ), ), ], ), ), ); } Widget _sectionLabel(Tokens t, String s) => Text( s, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.text2, fontSize: 11.5, letterSpacing: 1.2, fontWeight: FontWeight.w600), ); Widget _editEntry( Tokens t, { required IconData icon, required String label, required VoidCallback onTap, int? badge, bool enabled = true, }) { final Widget card = InkWell( onTap: enabled ? onTap : null, borderRadius: BorderRadius.circular(10), child: Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11), decoration: BoxDecoration( color: t.panel2, borderRadius: BorderRadius.circular(10), border: Border.all(color: t.line), ), child: Row( children: [ Icon(icon, size: 16, color: enabled ? t.accent : t.dim), const SizedBox(width: 8), Expanded(child: Text(label, style: TextStyle(color: enabled ? t.text2 : t.dim, fontSize: 12))), if (badge != null) ...[ Container( padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1), decoration: BoxDecoration( color: enabled ? t.accent.withValues(alpha: 0.14) : t.line.withValues(alpha: 0.35), borderRadius: BorderRadius.circular(6), ), child: Text('$badge', style: TextStyle( color: enabled ? t.accent : t.dim, fontSize: 10.5, fontWeight: FontWeight.w700)), ), const SizedBox(width: 4), ], Icon(Icons.chevron_right, size: 16, color: t.dim), ], ), ), ); if (enabled) return card; return Tooltip(message: '流程图只读:修改请切回条形 / 圆周视图', child: card); } Widget _laneSlotChip(Tokens t, int lane) { final int n = c.project.slotsOf(lane); return Builder( builder: (BuildContext ctx) => Tooltip( message: '泳道 L${lane + 1} 槽位数:$n(点击调整,最多 5)', child: InkWell( borderRadius: BorderRadius.circular(6), onTap: () async { final RenderBox box = ctx.findRenderObject()! as RenderBox; await showLaneSlotMenu(context, c, box.localToGlobal(Offset.zero), lane); }, child: Container( padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: n > 1 ? t.accent.withValues(alpha: 0.14) : t.panel2, borderRadius: BorderRadius.circular(6), border: Border.all(color: n > 1 ? t.accent.withValues(alpha: 0.4) : t.line2), ), child: Text('$n 槽', style: TextStyle(color: n > 1 ? t.accent : t.dim, fontSize: 10)), ), ), ), ); } Widget _headerAction(Tokens t, IconData icon, String label, Color bg, Color fg, VoidCallback? onTap) { final bool enabled = onTap != null; return Opacity( opacity: enabled ? 1 : 0.4, child: InkWell( onTap: onTap, borderRadius: BorderRadius.circular(8), child: Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6), decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(8)), child: Row( children: [ Icon(icon, size: 14, color: fg), const SizedBox(width: 4), Text(label, style: TextStyle(color: fg, fontSize: 11, fontWeight: FontWeight.w700)), ], ), ), ), ); } List _laneRows(Tokens t, bool bar) { final List lanes = c.project.renderLanes; final List out = []; for (int li = 0; li < lanes.length; li++) { final int lane = lanes[li]; final List acts = c.project.actions.where((Action a) => a.layer == lane).toList() ..sort((Action a, Action b) => a.startAngle.compareTo(b.startAngle)); // 空泳道(开启「保留空泳道」后动作被全部移走):显示占位行。 if (acts.isEmpty) { out.add(_emptyLaneRow(t, lane, li)); continue; } // 单动作泳道沿用普通动作行;多动作泳道合并显示。 out.add(acts.length == 1 ? _actionRow(t, acts.first, li, bar) : _laneRow(t, lane, li, acts, bar)); } return out; } Widget _emptyLaneRow(Tokens t, int lane, int li) { return Padding( padding: const EdgeInsets.only(bottom: 6), child: Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), border: Border.all(color: t.line), ), child: Row( children: [ Container( width: 22, height: 22, decoration: BoxDecoration( color: t.panel2, borderRadius: BorderRadius.circular(6), border: Border.all(color: t.line2), ), alignment: Alignment.center, child: Text('${li + 1}', style: TextStyle(color: t.dim, fontSize: 11, fontWeight: FontWeight.w700)), ), const SizedBox(width: 9), Expanded( child: Text('空泳道(已保留,可拖入动作)', style: TextStyle(color: t.dim, fontSize: 11)), ), _laneSlotChip(t, lane), ], ), ), ); } Widget _laneRow(Tokens t, int lane, int li, List acts, bool bar) { if (acts.isEmpty) return const SizedBox.shrink(); final bool flow = c.project.viewState.mode == ViewMode.flow; final Action primary = acts.firstWhere((Action a) => c.isSelected(a.id), orElse: () => acts.first); final bool sel = c.isSelected(primary.id); final Station? st = c.project.stationById(primary.stationId); final String joined = acts.map((Action a) => '${a.id} ${a.name}').join(' / '); double a0 = acts.first.startAngle; double a1 = acts.first.endAngle; for (final Action a in acts) { a0 = math.min(a0, a.startAngle); a1 = math.max(a1, a.endAngle); } return Padding( padding: const EdgeInsets.only(bottom: 6), child: InkWell( onTap: () => c.select( primary.id, toggle: HardwareKeyboard.instance.isControlPressed || HardwareKeyboard.instance.isShiftPressed, ), // 双击泳道行直接编辑该泳道的主动作(流程图只读时禁用)。 onDoubleTap: flow ? null : () => showDialog( context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)), borderRadius: BorderRadius.circular(10), child: Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), decoration: BoxDecoration( color: sel ? t.sel : t.panel2, borderRadius: BorderRadius.circular(10), border: Border.all(color: sel ? t.accent : t.line, width: sel ? 1.4 : 1), ), child: Row( children: [ Container( width: 22, height: 22, decoration: BoxDecoration( color: Color(primary.color).withValues(alpha: 0.9), borderRadius: BorderRadius.circular(6), ), alignment: Alignment.center, child: Text('${li + 1}', style: TextStyle(color: t.chip, fontSize: 11, fontWeight: FontWeight.w700)), ), const SizedBox(width: 9), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( joined, // 多槽位泳道允许更多行(最多与槽位数一致),持续自动换行。 maxLines: math.max(2, c.project.slotsOf(lane)), overflow: TextOverflow.ellipsis, style: TextStyle( color: sel ? t.text : t.text2, fontSize: 12.5, height: 1.25, fontWeight: sel ? FontWeight.w600 : FontWeight.normal, ), ), Text( '${st?.name ?? primary.stationId} · ${primary.driver}' '${acts.length > 1 ? ' · 共 ${acts.length} 个' : ''}', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.dim, fontSize: 10), ), ], ), ), const SizedBox(width: 6), Flexible( child: Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( bar ? '${a0.toStringAsFixed(0)}° – ${math.min(a1, 360).toStringAsFixed(0)}°' : 'L${li + 1}', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.sub, fontSize: 11), ), Text('${acts.length} 个动作', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.dim, fontSize: 10)), ], ), ), const SizedBox(width: 6), _laneSlotChip(t, lane), const SizedBox(width: 4), InkWell( onTap: flow ? null : () => showDialog( context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)), borderRadius: BorderRadius.circular(7), child: Container( width: 28, height: 24, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(7), border: Border.all(color: t.line2), ), child: Icon(Icons.edit, size: 13, color: flow ? t.line2 : (sel ? t.accent : t.dim)), ), ), ], ), ), ), ); } Widget _actionRow(Tokens t, Action a, int i, bool bar) { final bool flow = c.project.viewState.mode == ViewMode.flow; final bool sel = c.isSelected(a.id); final Station? st = c.project.stationById(a.stationId); return Padding( padding: const EdgeInsets.only(bottom: 6), child: InkWell( // Ctrl / Shift 点击可多选,用于批量对齐等操作。 onTap: () => c.select( a.id, toggle: HardwareKeyboard.instance.isControlPressed || HardwareKeyboard.instance.isShiftPressed, ), // 双击动作行直接进入编辑(流程图只读时禁用)。 onDoubleTap: flow ? null : () => showDialog( context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)), borderRadius: BorderRadius.circular(10), child: Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), decoration: BoxDecoration( color: sel ? t.sel : t.panel2, borderRadius: BorderRadius.circular(10), border: Border.all(color: sel ? t.accent : t.line, width: sel ? 1.4 : 1), ), child: Row( children: [ Container( width: 22, height: 22, decoration: BoxDecoration(color: Color(a.color).withValues(alpha: 0.9), borderRadius: BorderRadius.circular(6)), alignment: Alignment.center, child: Text('${i + 1}', style: TextStyle(color: t.chip, fontSize: 10, fontWeight: FontWeight.w700)), ), const SizedBox(width: 9), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(a.name, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: sel ? t.text : t.text2, fontSize: 12, fontWeight: sel ? FontWeight.w600 : FontWeight.normal)), Text( '${a.id} · ${st?.name ?? a.stationId} · ${a.driver}' '${c.project.slotsOf(a.layer) > 1 ? ' · 槽 ${effectiveSlot(c.project, a) + 1}' : ''}', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.dim, fontSize: 10)), ], ), ), const SizedBox(width: 6), Flexible( child: Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( bar ? '${a.startAngle.toStringAsFixed(0)}° – ${math.min(a.endAngle, 360).toStringAsFixed(0)}°' : 'L${a.layer + 1}', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.sub, fontSize: 10), ), Text(tfmt(a.durationAngle / 360 * c.project.cycle.durationMs, c.project.units), maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.dim, fontSize: 10)), ], ), ), const SizedBox(width: 6), _laneSlotChip(t, a.layer), const SizedBox(width: 4), InkWell( onTap: flow ? null : () => showDialog( context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)), borderRadius: BorderRadius.circular(7), child: Container( width: 28, height: 24, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(7), border: Border.all(color: t.line2), ), child: Icon(Icons.edit, size: 13, color: flow ? t.line2 : (sel ? t.accent : t.dim)), ), ), // 选中该动作时才出现删除入口;至少保留一个动作 / 泳道;流程图只读时隐藏。 if (sel && !flow && c.project.actions.length > 1) ...[ const SizedBox(width: 4), InkWell( onTap: () => c.deleteAction(a.id), borderRadius: BorderRadius.circular(7), child: Container( width: 28, height: 24, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(7), border: Border.all(color: t.danger.withValues(alpha: 0.6)), ), child: Icon(Icons.delete_outline, size: 13, color: t.danger), ), ), ], ], ), ), ), ); } Widget _modeButton(Tokens t, String label, bool active, VoidCallback onTap) { return InkWell( onTap: onTap, borderRadius: BorderRadius.circular(10), child: Container( height: 44, alignment: Alignment.center, decoration: BoxDecoration( color: active ? t.accent.withValues(alpha: 0.16) : t.panel2, borderRadius: BorderRadius.circular(10), border: Border.all(color: active ? t.accent : t.line, width: 1.2), ), child: Text(label, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: active ? t.accent : t.sub, fontSize: 11)), ), ); } List _displayOptions(Tokens t, bool bar) { final ViewState v = c.project.viewState; final List> opts = bar ? >[ ['时间轴 / 相位双刻度', v.showRuler, (bool x) => c.setViewFlag(showRuler: x)], ['依赖箭头 FS / SS', v.showDeps, (bool x) => c.setViewFlag(showDeps: x)], ['跨循环片段标记', c.project.units.autoSplitWrap, (bool x) => c.setUnits(c.project.units.copyWith(autoSplitWrap: x))], ['相位分区标注', v.showPhaseBands, (bool x) => c.setViewFlag(showPhaseBands: x)], ] : >[ ['同心圆环背景', v.showRingBg, (bool x) => c.setViewFlag(showRingBg: x)], ['顺序箭头(FS / SS)', v.showDeps, (bool x) => c.setViewFlag(showDeps: x)], ['层半径标注', v.showLayerLabels, (bool x) => c.setViewFlag(showLayerLabels: x)], ['跨循环高亮', c.project.units.autoSplitWrap, (bool x) => c.setUnits(c.project.units.copyWith(autoSplitWrap: x))], ]; return opts.map((List o) { final bool on = o[1] as bool; return InkWell( onTap: () => (o[2] as void Function(bool))(!on), child: Padding( padding: const EdgeInsets.symmetric(vertical: 4), child: Row( children: [ Container( width: 16, height: 16, decoration: BoxDecoration( color: on ? t.accent.withValues(alpha: 0.22) : Colors.transparent, borderRadius: BorderRadius.circular(4), border: Border.all(color: on ? t.accent : t.line2), ), child: on ? Icon(Icons.check, size: 12, color: t.accent) : null, ), const SizedBox(width: 10), Text(o[0] as String, style: TextStyle(color: t.sub, fontSize: 11)), ], ), ), ); }).toList(); } List _stationLoads(Tokens t) { final Map load = {}; for (final Action a in c.project.actions) { load[a.stationId] = (load[a.stationId] ?? 0) + a.durationAngle; } final List out = []; for (final Station s in c.project.stations) { final double deg = load[s.id] ?? 0; out.add(Padding( padding: const EdgeInsets.only(bottom: 10), child: Column( children: [ Row( children: [ Expanded( child: Text('${s.id} ${s.name}', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.sub, fontSize: 11)), ), Text('${deg.toStringAsFixed(0)}° · ${(deg / 3.6).toStringAsFixed(1)}%', style: TextStyle(color: t.accent, fontSize: 11, fontWeight: FontWeight.w600)), ], ), const SizedBox(height: 5), ClipRRect( borderRadius: BorderRadius.circular(4), child: LinearProgressIndicator( value: (deg / 360).clamp(0, 1), minHeight: 8, backgroundColor: t.track, valueColor: AlwaysStoppedAnimation(t.accent), ), ), ], ), )); } return out; } int _depCount() { int n = 0; for (final Action a in c.project.actions) { n += a.deps.length; } return n; } Widget _rightPanel(Tokens t, {bool floating = false}) { final Action? a = c.selected; final bool bar = c.project.viewState.mode == ViewMode.bar; final bool flow = c.project.viewState.mode == ViewMode.flow; return Container( width: _rightPanelWidth, decoration: BoxDecoration( color: t.panel, border: floating ? Border.all(color: t.line2) : Border(left: BorderSide(color: t.line)), boxShadow: floating ? [BoxShadow(color: Colors.black.withValues(alpha: 0.4), blurRadius: 20, offset: const Offset(-4, 0))] : null, ), child: Column( children: [ Padding( padding: const EdgeInsets.fromLTRB(16, 12, 10, 0), child: Row( children: [ _sectionLabel(t, '属性 · 选中动作'), const Spacer(), _panelControls(t, false), ], ), ), Expanded( child: a == null ? Center( child: Text('未选中动作\n点击画布或左侧列表选择', textAlign: TextAlign.center, style: TextStyle(color: t.dim, fontSize: 11, height: 1.6)), ) : SingleChildScrollView( padding: const EdgeInsets.fromLTRB(14, 8, 14, 16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _selectedHeader(t, a, bar), const SizedBox(height: 14), // 流程图只读提示:节点与连线自动生成,编辑请回时序视图。 if (flow) ...[ Container( padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: t.info, borderRadius: BorderRadius.circular(10), border: Border.all(color: t.line), ), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Icon(Icons.lock_outline, size: 15, color: t.warn), const SizedBox(width: 8), Expanded( child: Text('流程图只读:节点与连线由时序图自动生成,修改请切回条形 / 圆周视图。', style: TextStyle(color: t.sub, fontSize: 10.5, height: 1.55)), ), ], ), ), const SizedBox(height: 12), ], ..._propertyFields(t, a, bar), const SizedBox(height: 10), if (!bar) ...[ _sectionLabel(t, '角度编辑'), const SizedBox(height: 8), // 流程图只读:滑块仅展示数值,不可拖动。 Opacity( opacity: flow ? 0.45 : 1, child: IgnorePointer( ignoring: flow, child: Column( children: [ _slider(t, '起始角', (a.startAngle / 360).clamp(0, 1), pfmt(a.startAngle, c.project.units), (double v) => c.setActionStart(a.id, v * 360)), _slider(t, '持续角', (a.durationAngle / 180).clamp(0, 1), pfmt(a.durationAngle, c.project.units), (double v) => c.setActionDuration(a.id, v * 180)), ], ), ), ), const SizedBox(height: 8), ], const SizedBox(height: 12), // 输入依赖:允许多条(多前置)。 _sectionLabel(t, '前置依赖 · 输入(${a.deps.length})'), const SizedBox(height: 8), if (a.deps.isEmpty) Text('暂无前置依赖', style: TextStyle(color: t.dim, fontSize: 11)) else for (final Dependency d in a.deps) _depRow(t, a, d, enabled: !flow), const SizedBox(height: 6), OutlinedButton.icon( onPressed: flow ? null : () => showDialog( context: context, builder: (_) => DependencyEditorDialog(controller: c, action: a)), icon: const Icon(Icons.add_link, size: 15), label: const Text('添加前置依赖', style: TextStyle(fontSize: 11)), style: OutlinedButton.styleFrom( foregroundColor: t.accent, side: BorderSide(color: t.line2), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)), padding: const EdgeInsets.symmetric(vertical: 10), minimumSize: const Size(double.infinity, 0), ), ), const SizedBox(height: 12), // 输出依赖:本动作作为前置指向的后续动作(允许多结果)。 _sectionLabel(t, '输出依赖 · 结果(${_outgoingDeps(a).length})'), const SizedBox(height: 8), if (_outgoingDeps(a).isEmpty) Text('暂无后续动作引用本动作', style: TextStyle(color: t.dim, fontSize: 11)) else for (final (Action target, Dependency d) in _outgoingDeps(a)) _outDepRow(t, a, target, d, enabled: !flow), const SizedBox(height: 12), _helpCard(t), ], ), ), ), ], ), ); } Widget _selectedHeader(Tokens t, Action a, bool bar) { final Station? st = c.project.stationById(a.stationId); return Container( padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: t.panel2, borderRadius: BorderRadius.circular(12), border: Border.all(color: t.line), ), child: Row( children: [ Container( width: 34, height: 34, decoration: BoxDecoration(color: Color(a.color).withValues(alpha: 0.9), borderRadius: BorderRadius.circular(8)), alignment: Alignment.center, child: Text(a.id, style: TextStyle(color: t.chip, fontSize: 10, fontWeight: FontWeight.w700)), ), const SizedBox(width: 10), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(a.name, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.text, fontSize: 14, fontWeight: FontWeight.w600)), Text('${st?.id ?? a.stationId} · ${a.driver} · 层 L${a.layer + 1}', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.dim, fontSize: 10)), ], ), ), Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7), decoration: BoxDecoration( color: (a.wrap ? t.warn : t.accent).withValues(alpha: 0.14), borderRadius: BorderRadius.circular(8), border: Border.all(color: a.wrap ? t.warn : t.accent), ), child: Text(a.wrap ? '跨圈' : '选中', style: TextStyle(color: a.wrap ? t.warn : t.accent, fontSize: 11)), ), ], ), ); } List _propertyFields(Tokens t, Action a, bool bar) { final UnitSettings u = c.project.units; final double cycle = c.project.cycle.durationMs; final List> fields; if (bar) { fields = >[ ['开始时刻', tfmt(a.startAngle / 360 * cycle, u), pfmt(a.startAngle, u)], ['结束时刻', tfmt(a.endAngle / 360 * cycle, u), a.wrap ? '${a.endAngle.toStringAsFixed(1)}° → ${(a.endAngle - 360).toStringAsFixed(1)}°' : pfmt(a.endAngle, u)], ['持续时间', tfmt(a.durationAngle / 360 * cycle, u), pfmt(a.durationAngle, u)], ['循环归属', a.wrap ? '当前圈 + 下一圈' : '当前圈', a.wrap ? '跨圈片段' : '单圈内'], ['顺序约束', _depSummary(a), '前序动作关系'], ['相位归属', _phaseZone(a), '${a.startAngle.toStringAsFixed(0)}°–${math.min(a.endAngle, 360).toStringAsFixed(0)}°'], ]; } else { fields = >[ ['起始相位', pfmt(a.startAngle, u), '${tfmt(a.startAngle / 360 * cycle, u)} · 12 点钟起顺时针'], ['结束相位', pfmt(a.endAngle, u), tfmt(a.endAngle / 360 * cycle, u)], ['持续相位', pfmt(a.durationAngle, u), '${tfmt(a.durationAngle / 360 * cycle, u)} · 占循环 ${(a.durationAngle / 3.6).toStringAsFixed(2)}%'], ['所在层', 'L${a.layer + 1}', '层内序号 ${a.layer + 1}'], ['顺序约束', _depSummary(a), '前序动作关系'], ['相位归属', _phaseZone(a), '${a.startAngle.toStringAsFixed(0)}°–${math.min(a.endAngle, 360).toStringAsFixed(0)}°'], ]; } final List out = []; for (int i = 0; i < fields.length; i++) { out.add(Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7), decoration: BoxDecoration( color: i.isEven ? t.panel2.withValues(alpha: 0.7) : Colors.transparent, borderRadius: BorderRadius.circular(8), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Text(fields[i][0], style: TextStyle(color: t.sub, fontSize: 11)), const Spacer(), Flexible( child: Text(fields[i][1], textAlign: TextAlign.right, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: t.text, fontSize: 12, fontWeight: FontWeight.w600)), ), ], ), if (fields[i][2].isNotEmpty) Align( alignment: Alignment.centerRight, child: Text(fields[i][2], style: TextStyle(color: t.dim, fontSize: 10)), ), ], ), )); } return out; } /// 收集以 [a] 为起点的输出依赖(即 a 是前置、指向其它动作)。 List<(Action, Dependency)> _outgoingDeps(Action a) { final List<(Action, Dependency)> out = <(Action, Dependency)>[]; for (final Action target in c.project.actions) { for (final Dependency d in target.deps) { if (d.fromId == a.id) out.add((target, d)); } } return out; } String _depSummary(Action a) { if (a.deps.isEmpty) return '无输入'; int fs = 0; int ss = 0; int other = 0; for (final Dependency d in a.deps) { if (d.type == DepType.fs) { fs++; } else if (d.type == DepType.ss) { ss++; } else { other++; } } final List parts = []; if (fs > 0) parts.add('FS ×$fs'); if (ss > 0) parts.add('SS ×$ss'); if (other > 0) parts.add('其它 ×$other'); return '${a.deps.length} 条(${parts.join(' · ')})'; } String _phaseZone(Action a) { final double mid = (a.startAngle + a.endAngle) / 2 % 360; for (final PhaseZone z in c.project.phaseZones) { if (z.contains(mid)) return z.name; } return '—'; } Widget _slider(Tokens t, String label, double value, String display, ValueChanged onChanged) { return Padding( padding: const EdgeInsets.only(bottom: 6), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Text(label, style: TextStyle(color: t.sub, fontSize: 11)), const Spacer(), Text(display, style: TextStyle(color: t.accent, fontSize: 11, fontWeight: FontWeight.w600)), ], ), SliderTheme( data: SliderTheme.of(context).copyWith( trackHeight: 4, thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 7), overlayShape: const RoundSliderOverlayShape(overlayRadius: 14), ), child: Slider(value: value, onChanged: onChanged), ), ], ), ); } /// 依赖偏移显示:内部存角度,界面以当前时间单位显示;0 偏移不显示。 String _depOffsetText(Dependency d) { if (d.type != DepType.ss || d.offsetAngle == 0) return ''; return ' +${deg2msStr(d.offsetAngle, c.project.units, c.project.cycle.durationMs, dec: 2)}'; } Widget _depRow(Tokens t, Action a, Dependency d, {bool enabled = true}) { final Color col = d.type == DepType.fs ? t.fs : t.ss; return Container( margin: const EdgeInsets.only(bottom: 5), padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6), decoration: BoxDecoration( color: t.panel2, borderRadius: BorderRadius.circular(7), border: Border.all(color: t.line), ), child: Row( children: [ Container(width: 8, height: 8, decoration: BoxDecoration(color: col, shape: BoxShape.circle)), const SizedBox(width: 8), Expanded( child: Text( '${d.fromId} → ${a.id} ${d.type.name.toUpperCase()}${_depOffsetText(d)}', style: TextStyle(color: t.sub, fontSize: 10), ), ), Tooltip( message: '编辑依赖', child: InkWell( onTap: enabled ? () => showDialog( context: context, builder: (_) => DependencyEditorDialog( controller: c, action: a, initial: d, ), ) : null, child: Icon(Icons.edit_outlined, size: 14, color: enabled ? t.accent : t.line2), ), ), const SizedBox(width: 8), Tooltip( message: '删除依赖', child: InkWell( onTap: enabled ? () => c.removeDependency(d.fromId, a.id) : null, child: Icon(Icons.close, size: 14, color: enabled ? t.dim : t.line2), ), ), ], ), ); } Widget _outDepRow(Tokens t, Action a, Action target, Dependency d, {bool enabled = true}) { final Color col = d.type == DepType.fs ? t.fs : t.ss; return Container( margin: const EdgeInsets.only(bottom: 5), padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6), decoration: BoxDecoration( color: t.panel2, borderRadius: BorderRadius.circular(7), border: Border.all(color: t.line), ), child: Row( children: [ Container(width: 8, height: 8, decoration: BoxDecoration(color: col, shape: BoxShape.circle)), const SizedBox(width: 8), Expanded( child: Text( '${a.id} → ${target.id} ${d.type.name.toUpperCase()}${_depOffsetText(d)}', style: TextStyle(color: t.sub, fontSize: 10), ), ), Tooltip( message: '编辑依赖', child: InkWell( onTap: enabled ? () => showDialog( context: context, builder: (_) => DependencyEditorDialog( controller: c, action: target, initial: d, ), ) : null, child: Icon(Icons.edit_outlined, size: 14, color: enabled ? t.accent : t.line2), ), ), const SizedBox(width: 8), Tooltip( message: '删除依赖', child: InkWell( onTap: enabled ? () => c.removeDependency(a.id, target.id) : null, child: Icon(Icons.close, size: 14, color: enabled ? t.dim : t.line2), ), ), ], ), ); } Widget _helpCard(Tokens t) { return Container( padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: t.panel2, borderRadius: BorderRadius.circular(10), border: Border.all(color: t.line), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Icon(Icons.help_outline, size: 16, color: t.accent), const SizedBox(width: 6), Text('帮助 · 快捷键', style: TextStyle(color: t.accent, fontSize: 11, fontWeight: FontWeight.w600)), ], ), const SizedBox(height: 8), Text('拖拽 = 平移相位 · 拖端点 = 改持续角', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), Text('Shift+拖 = 改层 · F1 = 帮助中心', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), Text('Ctrl+Z / Ctrl+Y = 撤销 / 重做', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)), ], ), ); } Widget _statusBar(Tokens t) { final UnitSettings u = c.project.units; final ViewMode mode = c.project.viewState.mode; final bool circular = mode == ViewMode.circular; final List items = [ '循环周期 ${tfmt(c.project.cycle.durationMs, u)}', '相位 360° = 100%', '动作 ${c.project.actions.length}', '依赖 ${_depCount()}', circular ? '轨道 L1–L${c.project.renderLaneCount}' : '工位 ${c.project.stations.length}', mode == ViewMode.flow ? '泳道 L1–L${c.project.renderLaneCount}(流程节点 ${c.project.actions.length})' : (circular ? '同心圆 ${c.project.laneCount}' : '时间轴 0–${tfmt(c.project.cycle.durationMs, u)}'), '单位 ${timeUnitLabel(u.timeUnit)} / ${phaseUnitLabel(u.phaseUnit)}', '1° = ${tfmtAuto(c.project.cycle.durationMs / 360)}', c.status, ]; return Container( height: 32, padding: const EdgeInsets.symmetric(horizontal: 16), decoration: BoxDecoration( color: t.chrome, border: Border(top: BorderSide(color: t.line2)), ), child: Row( children: [ Expanded( child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: items.map((String s) { final bool last = s == items.last; return Padding( padding: const EdgeInsets.only(right: 22), child: Text(s, style: TextStyle(color: last ? t.ok : t.sub, fontSize: 11)), ); }).toList(), ), ), ), if (c.dirty) Padding( padding: const EdgeInsets.only(right: 14), child: Text('● 未保存', style: TextStyle(color: t.warn, fontSize: 11)), ), Text('F1 帮助 · Ctrl+Z 撤销 · Ctrl+S 保存', style: TextStyle(color: t.dim, fontSize: 10)), ], ), ); } }