Files
EasyDesignCollection/lib/ui/canvas_overlays.dart
T
呆头鹅 6cfa79507c feat: V1.0.0 发布(呆头鹅)
- 默认浅色白底主题;字体整数化 + Microsoft YaHei UI 提升清晰度
- 相位分区:圆周/条形显示、沿弧排列、拖拽边界(虚线参考+弱吸附)、增删改(对话框/右键/双击)
- 动作:Ctrl 多选批量对齐;上下拖拽自由换行;左右端拖拽改起止(虚线+弱吸附+左右箭头光标)
- 动作编辑支持角度与时间双向换算
- 圆周顺时针箭头移至刻度环外;条形左侧标题列收窄
- 侧栏可隐藏/钉住;适应视图按内容自适应;节拍统计改为按钮弹窗
- AI 生成时序图(DeepSeek,Flash/Pro,推理强度),基于 dart:io 无插件
- 窗口标题显示文件名/未命名文件;关于信息(设计人/版本/版权)
- 全量中文注释、docs/ARCHITECTURE.md、docs/HELP.md(按任务组织)
- 构建脚本输出到 dist/,并附带 dist 生成物
2026-09-18 16:50:12 +08:00

900 lines
33 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 画布浮层:绘制在交互画布之上的固定信息面板,对应设计稿中的
// 标题、图例、统计、实时预览与编辑工具等元素。
//
// 架构位置:属于纯展示层,叠加在 CanvasView 之上,通过 AppController
// 读取项目数据;所有浮层均使用 IgnorePointer 或自身交互包裹,避免
// 遮挡画布手势。本文件通过 LayoutBuilder 依据窗口尺寸做响应式断点,
// 决定各面板是否显示。
import 'dart:math' as math;
import 'package:flutter/material.dart' hide Action;
import '../layout/layout.dart';
import '../model/models.dart';
import '../model/units.dart';
import '../state/app_controller.dart';
import '../theme/tokens.dart';
import 'dialogs.dart';
/// 画布浮层容器:按响应式断点组合并定位各信息面板。
class CanvasOverlays extends StatelessWidget {
/// 创建浮层容器,[controller] 为全局应用控制器。
const CanvasOverlays({super.key, required this.controller});
/// 全局应用控制器,提供项目数据与编辑动作。
final AppController controller;
/// 控制器快捷访问器。
AppController get c => controller;
/// 使用 [LayoutBuilder] 获取可用尺寸,计算响应式断点后,
/// 通过 [Stack] + [Positioned] 摆放各浮层面板。
@override
Widget build(BuildContext context) {
final Tokens t = context.tok;
final bool circular = c.project.viewState.mode == ViewMode.circular;
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final double w = constraints.maxWidth;
final double h = constraints.maxHeight;
// ---- 响应式断点:不同尺寸下显示不同的浮层组合 ----
// 圆周视图左侧图例列:需要较宽较高的窗口。
final bool showLeftColumn = circular && w >= 1500 && h >= 820;
// 条形视图统计卡片:中等尺寸以上显示。
final bool showStats = !circular && w >= 900 && h >= 760;
// 编辑工具条:门槛最低,几乎始终显示。
final bool showTools = w >= 760;
// 实时预览卡片:需要大屏才显示。
final bool showPreview = w >= 1400 && h >= 760;
// 浮层整体使用 Stack 叠加,各面板按断点条件选择性插入。
return Stack(
children: <Widget>[
// 顶部标题与副标题,横跨整个画布宽度,不拦截手势。
Positioned(
left: 18,
top: 12,
right: 18,
child: IgnorePointer(child: _Title(t: t, circular: circular, project: c.project)),
),
// 圆周视图左侧信息列:图例 + 选中卡片 + 依赖图例。
if (showLeftColumn)
Positioned(
left: 18,
top: 70,
bottom: 12,
width: 268,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
IgnorePointer(child: _CircularLegend(t: t, project: c.project)),
const SizedBox(height: 12),
IgnorePointer(child: _SelectedCard(t: t, c: c, circular: true)),
const SizedBox(height: 12),
IgnorePointer(child: _DepTypeLegend(t: t)),
],
),
),
),
// 条形视图左下角:节拍统计 + 编辑工具。
if (!circular && (showStats || showTools))
Positioned(
left: 18,
bottom: 12,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (showStats) ...<Widget>[
_StatsButton(t: t, c: c),
const SizedBox(height: 8),
],
_EditTools(t: t, c: c),
],
),
),
// 右下角实时预览:圆周视图显示条形缩略,反之亦然。
if (showPreview)
Positioned(
right: 18,
bottom: 12,
child: IgnorePointer(
child: circular
? _BarPreviewCard(t: t, project: c.project)
: _CircularPreviewCard(t: t, project: c.project),
),
),
// 圆周视图右侧浮动工具栏(添加/编辑/复制/删除/改层/对齐/帮助)。
if (circular)
Positioned(
right: 16,
top: 120,
child: _FloatingToolbar(t: t, c: c),
),
],
);
},
);
}
}
/// 通用卡片容器:统一浮层的背景、圆角与边框样式。
class _Card extends StatelessWidget {
const _Card({required this.t, required this.child, this.width, this.borderColor});
/// 主题令牌。
final Tokens t;
/// 卡片内容。
final Widget child;
/// 可选固定宽度。
final double? width;
/// 可选边框颜色,默认使用主题分隔线色。
final Color? borderColor;
@override
Widget build(BuildContext context) {
return Container(
width: width,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: t.panel2.withValues(alpha: 0.96),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: borderColor ?? t.line),
),
child: child,
);
}
}
/// 顶部标题浮层:显示当前视图名称与双刻度/图例说明。
class _Title extends StatelessWidget {
const _Title({required this.t, required this.circular, required this.project});
/// 主题令牌。
final Tokens t;
/// 是否处于圆周视图。
final bool circular;
/// 当前项目,用于展示循环时长等文案。
final Project project;
@override
Widget build(BuildContext context) {
final String title = circular
? '圆周节拍视图(同心圆 · 12 点钟起始 · 顺时针)'
: '条形节拍视图(甘特 / 流程图 · 依赖箭头)';
final String sub = circular
? '同心圆环 = 动作层;箭头 = 执行顺序(绿色实线 FS 严格顺序,琥珀虚线 SS 并行重叠);1 圈 = 1 循环 = ${tfmt(project.cycle.durationMs, project.units)} = 360° = 100%'
: '时间轴与相位角双刻度联动;箭头表示动作间关联(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠);跨循环动作自动拆分并标注';
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(title, style: TextStyle(color: t.text, fontSize: 16, fontWeight: FontWeight.w600)),
const SizedBox(height: 4),
Text(sub, style: TextStyle(color: t.dim, fontSize: 11)),
],
);
}
}
/// 圆周视图左侧图例:逐条列出动作的层号、相位区间与时长。
class _CircularLegend extends StatelessWidget {
const _CircularLegend({required this.t, required this.project});
/// 主题令牌。
final Tokens t;
/// 当前项目,用于枚举动作。
final Project project;
@override
Widget build(BuildContext context) {
return _Card(
t: t,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('图层 / 相位图例', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
const SizedBox(height: 8),
for (int i = 0; i < project.actions.length; i++)
Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 15,
height: 15,
margin: const EdgeInsets.only(top: 2),
decoration: BoxDecoration(
color: Color(project.actions[i].color),
borderRadius: BorderRadius.circular(5),
),
),
const SizedBox(width: 9),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('${i + 1}. ${project.actions[i].id} ${project.actions[i].name}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.text2, fontSize: 11)),
Text(
'L${project.actions[i].layer + 1} · ${project.actions[i].startAngle.toStringAsFixed(0)}°–${math.min(project.actions[i].endAngle, 360).toStringAsFixed(0)}° · ${tfmt(project.actions[i].durationAngle / 360 * project.cycle.durationMs, project.units)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.dim, fontSize: 10),
),
],
),
),
],
),
),
],
),
);
}
}
/// 选中动作信息卡:展示选中动作的起止/持续相位与所在层。
class _SelectedCard extends StatelessWidget {
const _SelectedCard({required this.t, required this.c, required this.circular});
/// 主题令牌。
final Tokens t;
/// 全局应用控制器。
final AppController c;
/// 是否处于圆周视图(用于文案微调)。
final bool circular;
@override
Widget build(BuildContext context) {
final Action? a = c.selected;
if (a == null) {
return _Card(
t: t,
borderColor: t.accent,
child: Text('未选中动作\n点击画布或左侧列表选择', style: TextStyle(color: t.dim, fontSize: 11, height: 1.6)),
);
}
final UnitSettings u = c.project.units;
final double cycle = c.project.cycle.durationMs;
final Station? st = c.project.stationById(a.stationId);
final String delta = tfmt(a.durationAngle / 360 * cycle, u);
return _Card(
t: t,
borderColor: t.accent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('选中动作', style: TextStyle(color: t.accent, fontSize: 10, fontWeight: FontWeight.w700, letterSpacing: 1)),
const SizedBox(height: 6),
Text('${a.id} ${a.name}', style: TextStyle(color: t.text, fontSize: 13, fontWeight: FontWeight.w700)),
const SizedBox(height: 8),
_kv(t, '起始相位', pfmt(a.startAngle, u)),
_kv(t, '结束相位', pfmt(a.endAngle, u)),
_kv(t, '持续相位', pfmt(a.durationAngle, u)),
const SizedBox(height: 4),
Text('Δ = $delta · 层 L${a.layer + 1} · ${st?.id ?? a.stationId}',
style: TextStyle(color: t.accent, fontSize: 11, fontWeight: FontWeight.w600)),
],
),
);
}
/// 渲染一行“标签 — 值”信息。
Widget _kv(Tokens t, String k, String v) => Padding(
padding: const EdgeInsets.only(bottom: 3),
child: Row(
children: <Widget>[
Text(k, style: TextStyle(color: t.sub, fontSize: 11)),
const Spacer(),
Flexible(
child: Text(v,
textAlign: TextAlign.right,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.text, fontSize: 11, fontWeight: FontWeight.w600)),
),
],
),
);
}
/// 依赖类型图例:说明 FS/SS 及关键路径的线条样式含义。
class _DepTypeLegend extends StatelessWidget {
const _DepTypeLegend({required this.t});
/// 主题令牌。
final Tokens t;
@override
Widget build(BuildContext context) {
Widget row(Widget sample, String label) => Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
children: <Widget>[
SizedBox(width: 48, child: sample),
const SizedBox(width: 8),
Expanded(child: Text(label, style: TextStyle(color: t.sub, fontSize: 10))),
],
),
);
return _Card(
t: t,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('执行顺序 / 依赖类型', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
const SizedBox(height: 10),
row(_SampleLine(color: t.fs, dash: false, arrow: true), 'FS 严格顺序(完成后启动)'),
row(_SampleLine(color: t.ss, dash: true, arrow: true), 'SS 并行重叠(可提前启动)'),
row(_SampleLine(color: t.fs, dash: false, arrow: false, star: true), '关键路径(累计最长链)'),
],
),
);
}
}
/// 图例中的示例线段:可组合实线/虚线、箭头与关键路径星标。
class _SampleLine extends StatelessWidget {
const _SampleLine({required this.color, required this.dash, required this.arrow, this.star = false});
/// 线条颜色。
final Color color;
/// 是否绘制为虚线。
final bool dash;
/// 是否绘制箭头。
final bool arrow;
/// 是否绘制关键路径星标。
final bool star;
/// 用 [_SamplePainter] 绘制示例线段。
@override
Widget build(BuildContext context) {
return SizedBox(
height: 16,
child: CustomPaint(painter: _SamplePainter(color, dash, arrow, star)),
);
}
}
/// 示例线段绘制器:按参数绘制实/虚线、箭头与星标。
class _SamplePainter extends CustomPainter {
_SamplePainter(this.color, this.dash, this.arrow, this.star);
/// 线条颜色。
final Color color;
/// 是否绘制为虚线。
final bool dash;
/// 是否绘制箭头。
final bool arrow;
/// 是否绘制关键路径星标。
final bool star;
/// 绘制示例线段本体、箭头及可选星标。
@override
void paint(Canvas canvas, Size size) {
final Paint p = Paint()
..color = color
..strokeWidth = 2.4
..strokeCap = StrokeCap.round;
final double y = size.height / 2;
if (dash) {
for (double x = 0; x < size.width - 10; x += 8) {
canvas.drawLine(Offset(x, y), Offset(math.min(x + 4, size.width - 10), y), p);
}
} else {
canvas.drawLine(Offset(0, y), Offset(size.width - 10, y), p);
}
if (arrow) {
final Path a = Path()
..moveTo(size.width - 1, y)
..lineTo(size.width - 11, y - 4.5)
..lineTo(size.width - 11, y + 4.5)
..close();
canvas.drawPath(a, Paint()..color = color);
}
if (star) {
canvas.drawCircle(Offset(size.width - 8, y), 7.5, Paint()..color = const Color(0xFF4CC9F0));
final TextPainter tp = TextPainter(
text: const TextSpan(text: '★', style: TextStyle(color: Colors.black, fontSize: 10, fontWeight: FontWeight.w700)),
textDirection: TextDirection.ltr,
)..layout();
tp.paint(canvas, Offset(size.width - 8 - tp.width / 2, y - tp.height / 2));
}
}
/// 示例线段始终重绘(开销极小)。
@override
bool shouldRepaint(covariant _SamplePainter old) => true;
}
/// 条形视图左下角的「节拍统计」按钮。
///
/// 统计内容改为**弹出窗口**展示(见 [_CycleStatsDialog]),
/// 避免固定面板长期遮挡画布。
class _StatsButton extends StatelessWidget {
const _StatsButton({required this.t, required this.c});
/// 主题令牌。
final Tokens t;
/// 全局应用控制器。
final AppController c;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => showDialog<void>(
context: context,
builder: (BuildContext ctx) => _CycleStatsDialog(t: t, c: c),
),
borderRadius: BorderRadius.circular(10),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 9),
decoration: BoxDecoration(
color: t.panel2.withValues(alpha: 0.96),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: t.line2),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.insights, size: 15, color: t.accent),
const SizedBox(width: 6),
Text('节拍统计', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
],
),
),
);
}
}
/// 节拍统计弹窗:汇总循环周期、动作数、关键路径、并行度、
/// 相位覆盖率、瓶颈工位与预估产能。
class _CycleStatsDialog extends StatelessWidget {
const _CycleStatsDialog({required this.t, required this.c});
/// 主题令牌。
final Tokens t;
/// 全局应用控制器。
final AppController c;
@override
Widget build(BuildContext context) {
final Project p = c.project;
final UnitSettings u = p.units;
final List<Action> acts = p.actions;
final int stations = p.stations.length;
final double perHour = p.cycle.durationMs > 0 ? 3600 / (p.cycle.durationMs / 1000) : 0;
final List<List<String>> stats = <List<String>>[
<String>['循环周期', '${tfmt(p.cycle.durationMs, u)} / 360° / 100%'],
<String>['动作数量', '${acts.length}($stations 工位)'],
<String>['关键路径', _criticalChain()],
<String>['最大并行度', _maxParallel(acts)],
<String>['相位覆盖率', _coverage(acts)],
<String>['瓶颈工位', _bottleneck(p)],
<String>['预估产能', '${perHour.toStringAsFixed(0)} 件/小时(节拍 ${tfmt(p.cycle.durationMs, u)})'],
];
return Dialog(
backgroundColor: t.dialog,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
child: SizedBox(
width: 460,
child: Padding(
padding: const EdgeInsets.fromLTRB(18, 16, 12, 14),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.insights, size: 18, color: t.accent),
const SizedBox(width: 8),
Text('节拍统计', style: TextStyle(color: t.text, fontSize: 14, fontWeight: FontWeight.w700)),
const Spacer(),
IconButton(
onPressed: () => Navigator.pop(context),
icon: Icon(Icons.close, size: 18, color: t.sub),
splashRadius: 16,
),
],
),
Divider(height: 14, color: t.line),
for (int i = 0; i < stats.length; i++) ...<Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
children: <Widget>[
Text(stats[i][0], style: TextStyle(color: t.dim, fontSize: 11)),
const Spacer(),
Flexible(
child: Text(stats[i][1],
textAlign: TextAlign.right,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.text2, fontSize: 11, fontWeight: FontWeight.w600)),
),
],
),
),
if (i < stats.length - 1) Divider(height: 1, color: t.line.withValues(alpha: 0.6)),
],
],
),
),
),
);
}
/// 拼接关键路径上的动作 id 链。
String _criticalChain() {
final List<String> ids = <String>[];
for (final Action a in c.project.actions) {
if (c.criticalActions.contains(a.id)) ids.add(a.id);
}
if (ids.isEmpty) return '—';
return ids.join(' → ');
}
/// 扫描 0–360°,找出同时执行的动作数量峰值。
String _maxParallel(List<Action> acts) {
int best = 0;
double bestAt = 0;
for (int d = 0; d <= 360; d += 5) {
int n = 0;
for (final Action a in acts) {
if (d >= a.startAngle && d <= math.min(a.endAngle, 360)) n++;
}
if (n > best) {
best = n;
bestAt = d.toDouble();
}
}
return '$best 个动作同时执行(${bestAt.toStringAsFixed(0)}° 附近)';
}
/// 统计 0–360° 被动作覆盖的相位比例。
String _coverage(List<Action> acts) {
final List<bool> cover = List<bool>.filled(360, false);
for (final Action a in acts) {
for (int d = a.startAngle.floor(); d < math.min(a.endAngle, 360).ceil(); d++) {
if (d >= 0 && d < 360) cover[d] = true;
}
}
final int filled = cover.where((bool e) => e).length;
return '${(filled / 360 * 100).toStringAsFixed(0)}%(0°–360°)';
}
/// 找出累计相位占用最大的工位作为瓶颈。
String _bottleneck(Project p) {
final Map<String, double> load = <String, double>{};
for (final Action a in p.actions) {
load[a.stationId] = (load[a.stationId] ?? 0) + a.durationAngle;
}
String best = '—';
double bestV = -1;
for (final MapEntry<String, double> e in load.entries) {
if (e.value > bestV) {
bestV = e.value;
best = '${e.key} ${e.value.toStringAsFixed(0)}°';
}
}
return best;
}
}
/// 条形视图编辑工具条:添加 / 编辑 / 复制 / 删除 / 对齐 / 帮助。
class _EditTools extends StatelessWidget {
const _EditTools({required this.t, required this.c});
/// 主题令牌。
final Tokens t;
/// 全局应用控制器。
final AppController c;
/// 渲染一组横向排列的编辑工具按钮。
@override
Widget build(BuildContext context) {
return _Card(
t: t,
width: 470,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('编辑工具', style: TextStyle(color: t.sub, fontSize: 12, fontWeight: FontWeight.w600)),
const SizedBox(height: 10),
Row(
children: <Widget>[
_tool(t, Icons.add, '添加动作', t.ok, t.onAccent, () => c.addAction(startAngle: 0)),
const SizedBox(width: 8),
_tool(t, Icons.edit, '编辑', t.accent, t.onAccent, () {
final Action? a = c.selected;
if (a != null) showDialog<void>(context: context, builder: (_) => ActionEditorDialog(controller: c, action: a));
}),
const SizedBox(width: 8),
_tool(t, Icons.copy, '复制', t.panel, t.sub, c.duplicateSelected, border: t.line2),
const SizedBox(width: 8),
_tool(t, Icons.delete_outline, '删除', t.panel, t.sub,
() => c.selectedId != null ? c.deleteAction(c.selectedId!) : null,
border: t.line2),
const SizedBox(width: 8),
_tool(t, Icons.align_horizontal_left, '对齐', t.panel, t.sub, c.alignPhase, border: t.line2),
const SizedBox(width: 8),
_tool(t, Icons.help_outline, '帮助', t.panel, t.sub,
() => showDialog<void>(context: context, builder: (_) => const HelpDialog()),
border: t.line2),
],
),
],
),
);
}
/// 渲染单个带图标与文字的工具按钮。
Widget _tool(Tokens t, IconData icon, String label, Color bg, Color fg, VoidCallback onTap, {Color? border}) {
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(9),
child: Container(
width: 66,
height: 56,
decoration: BoxDecoration(
color: bg,
borderRadius: BorderRadius.circular(9),
border: Border.all(color: border ?? bg),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(icon, size: 19, color: fg),
const SizedBox(height: 4),
Text(label, style: TextStyle(color: fg, fontSize: 10, fontWeight: FontWeight.w600)),
],
),
),
);
}
}
/// 圆周视图右侧浮动工具栏:纵向排列的编辑与帮助按钮。
class _FloatingToolbar extends StatelessWidget {
const _FloatingToolbar({required this.t, required this.c});
/// 主题令牌。
final Tokens t;
/// 全局应用控制器。
final AppController c;
/// 渲染纵向排列的浮动工具按钮组。
@override
Widget build(BuildContext context) {
/// 渲染单个浮动工具按钮。
Widget item(IconData icon, String label, Color bg, Color fg, VoidCallback onTap, {Color? border}) {
return Padding(
padding: const EdgeInsets.only(bottom: 6),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(10),
child: Container(
width: 46,
height: 46,
decoration: BoxDecoration(
color: bg,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: border ?? bg),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(icon, size: 17, color: fg),
const SizedBox(height: 1),
Text(label, style: TextStyle(color: fg, fontSize: 10, fontWeight: FontWeight.w600)),
],
),
),
),
);
}
return Container(
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: t.panel.withValues(alpha: 0.96),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: t.line2),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
item(Icons.add, '添加', t.ok, t.onAccent, () => c.addAction(startAngle: 0)),
item(Icons.edit, '编辑', t.accent, t.onAccent, () {
final Action? a = c.selected;
if (a != null) showDialog<void>(context: context, builder: (_) => ActionEditorDialog(controller: c, action: a));
}),
item(Icons.copy, '复制', t.panel2, t.sub, c.duplicateSelected, border: t.line),
item(Icons.delete_outline, '删除', t.panel2, t.sub,
() => c.selectedId != null ? c.deleteAction(c.selectedId!) : null, border: t.line),
item(Icons.keyboard_arrow_up, '层+', t.panel2, t.sub,
() => c.selectedId != null ? c.changeLayer(c.selectedId!, 1) : null, border: t.line),
item(Icons.keyboard_arrow_down, '层−', t.panel2, t.sub,
() => c.selectedId != null ? c.changeLayer(c.selectedId!, -1) : null, border: t.line),
item(Icons.align_horizontal_left, '对齐', t.panel2, t.sub, c.alignPhase, border: t.line),
item(Icons.help_outline, '帮助', t.panel2, t.sub,
() => showDialog<void>(context: context, builder: (_) => const HelpDialog()), border: t.line),
],
),
);
}
}
/// 条形节拍缩略预览卡(在圆周视图右下角显示)。
class _BarPreviewCard extends StatelessWidget {
const _BarPreviewCard({required this.t, required this.project});
/// 主题令牌。
final Tokens t;
/// 当前项目。
final Project project;
/// 渲染条形缩略预览。
@override
Widget build(BuildContext context) {
return _Card(
t: t,
width: 320,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('条形节拍预览(实时联动)', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
const SizedBox(height: 10),
SizedBox(
height: project.actions.length * 22.0 + 18,
child: CustomPaint(painter: _MiniBarPainter(project, t)),
),
],
),
);
}
}
/// 条形缩略预览绘制器:按相位比例绘制各动作的横向色条。
class _MiniBarPainter extends CustomPainter {
_MiniBarPainter(this.project, this.t);
/// 当前项目。
final Project project;
/// 主题令牌。
final Tokens t;
/// 逐行绘制动作色条、跨圈尾段与底部刻度。
@override
void paint(Canvas canvas, Size size) {
final double w = size.width - 4;
final double rh = 19;
for (int i = 0; i < project.actions.length; i++) {
final Action a = project.actions[i];
final double y = i * (rh + 3);
final double x1 = 2 + a.startAngle / 360 * w;
final double x2 = 2 + math.min(a.endAngle, 360) / 360 * w;
final RRect r = RRect.fromRectAndRadius(
Rect.fromLTWH(x1, y, math.max(x2 - x1, 2), rh - 4),
const Radius.circular(3),
);
canvas.drawRRect(r, Paint()..color = Color(a.color).withValues(alpha: 0.9));
if (a.wrap) {
canvas.drawRRect(
RRect.fromRectAndRadius(Rect.fromLTWH(2, y, (a.endAngle - 360) / 360 * w, rh - 4), const Radius.circular(3)),
Paint()..color = Color(a.color).withValues(alpha: t.tailOp),
);
}
}
final double baseY = project.actions.length * (rh + 3) + 4;
canvas.drawLine(Offset(2, baseY), Offset(size.width - 2, baseY), Paint()..color = t.line2..strokeWidth = 1);
final TextPainter tp = TextPainter(
text: TextSpan(text: '0.0 ${timeUnitLabel(project.units.timeUnit)}', style: TextStyle(color: t.dim, fontSize: 10)),
textDirection: TextDirection.ltr,
)..layout();
tp.paint(canvas, Offset(2, baseY + 4));
final TextPainter tp2 = TextPainter(
text: TextSpan(text: tfmt(project.cycle.durationMs, project.units), style: TextStyle(color: t.dim, fontSize: 10)),
textDirection: TextDirection.ltr,
)..layout();
tp2.paint(canvas, Offset(size.width - 2 - tp2.width, baseY + 4));
}
/// 预览始终重绘(数据实时联动)。
@override
bool shouldRepaint(covariant _MiniBarPainter old) => true;
}
/// 圆周节拍缩略预览卡(在条形视图右下角显示)。
class _CircularPreviewCard extends StatelessWidget {
const _CircularPreviewCard({required this.t, required this.project});
/// 主题令牌。
final Tokens t;
/// 当前项目。
final Project project;
/// 渲染圆周缩略预览。
@override
Widget build(BuildContext context) {
return _Card(
t: t,
width: 330,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('圆周节拍预览(实时联动)', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
const SizedBox(height: 8),
SizedBox(
height: 250,
child: CustomPaint(painter: _MiniCircularPainter(project, t)),
),
Text('12 点钟起始 · 顺时针 · 每层一环', style: TextStyle(color: t.dim, fontSize: 10)),
],
),
);
}
}
/// 圆周缩略预览绘制器:每层一环,绘制同心圆与动作圆弧。
class _MiniCircularPainter extends CustomPainter {
_MiniCircularPainter(this.project, this.t);
/// 当前项目。
final Project project;
/// 主题令牌。
final Tokens t;
/// 绘制同心圆环、各动作圆弧、12 点钟箭头与“360°”标注。
@override
void paint(Canvas canvas, Size size) {
final Offset c = Offset(size.width / 2, size.height / 2);
final int n = project.actions.length;
final double r0 = 26;
final double pitch = n <= 1 ? 18 : math.min(20, (size.height / 2 - 30 - r0) / (n - 1));
const double pw = 9;
canvas.drawCircle(c, r0 + (n - 1) * pitch + pw + 12, Paint()..color = t.dial);
for (int i = 0; i < n; i++) {
final Action a = project.actions[i];
final double r = r0 + i * pitch;
canvas.drawCircle(
c,
r,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = pw
..color = i.isEven ? t.ringA : t.ringB,
);
for (final List<double> s in splitArcs(a.startAngle, a.endAngle)) {
canvas.drawPath(
arcPath(c, r, s[0], s[1]),
Paint()
..style = PaintingStyle.stroke
..strokeWidth = pw
..strokeCap = a.wrap ? StrokeCap.butt : StrokeCap.round
..color = Color(a.color).withValues(alpha: 0.95),
);
}
}
final double tip = r0 + (n - 1) * pitch + pw + 12;
final Path arrow = Path()
..moveTo(c.dx, c.dy - tip - 10)
..lineTo(c.dx - 7, c.dy - tip - 22)
..lineTo(c.dx + 7, c.dy - tip - 22)
..close();
canvas.drawPath(arrow, Paint()..color = t.accent);
final TextPainter tp = TextPainter(
text: TextSpan(text: '360°', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
textDirection: TextDirection.ltr,
)..layout();
tp.paint(canvas, Offset(c.dx - tp.width / 2, c.dy - 8));
}
/// 预览始终重绘(数据实时联动)。
@override
bool shouldRepaint(covariant _MiniCircularPainter old) => true;
}