fix(交互/渲染): 手写笔拖拽、换泳道与依赖标签排版

- 触屏单指拖拽改走原始指针事件(绕开手势竞技场),手写笔拖拽端点更稳
- 端点把手优先命中:精确点在把手上也能选中并拖拽
- 换泳道不再因目标泳道时间重叠而拒绝(消除“磁吸回弹”),斜向拖拽也能换道
- 依赖标签:FS/SS 缩短、字号收小、去掉五角星;条形图上下/左右自动避让,
  圆周图沿半径自动避让,避免标签互相压盖
- 条形动作条 22→18px、泳道间距上限 52→58;圆周环宽略收窄、环间距上限提高
- 图例:关键路径改为「线条加粗光晕」示例
This commit is contained in:
2026-10-08 14:34:04 +08:00
parent 76d1ce0d9a
commit 5e30ab17a2
6 changed files with 292 additions and 82 deletions
+62 -20
View File
@@ -426,6 +426,8 @@ class BarPainter extends CustomPainter {
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
};
int k = 0;
// 依赖标签先收集、后统一避让放置(见方法末尾 _placeChips)。
final List<_ChipSpec> chips = <_ChipSpec>[];
for (final Action to in ordered) {
for (final Dependency d in to.deps) {
final Action? from = project.actionById(d.fromId);
@@ -434,8 +436,14 @@ class BarPainter extends CustomPainter {
final int ib = index[to.id] ?? 0;
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
final bool crit = criticalDeps.contains('${d.fromId}->${d.toId}');
final String label = d.type == DepType.fs ? 'FS 顺序' : 'SS +${d.offsetAngle.toStringAsFixed(0)}°';
final double chipW = _tp(label, 9.5, col, FontWeight.w600).width + 14 + (crit ? 15 : 0);
// 标签缩短 + 字号收小,减少占位与相互遮挡(关键路径已由线条光晕表示)。
final String label = switch (d.type) {
DepType.fs => 'FS',
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
DepType.ff => 'FF',
DepType.sf => 'SF',
};
final double chipW = _tp(label, 8.5, col, FontWeight.w600).width + 12;
final Rect ra = layout.rectFor(from);
final Rect rb = layout.rectFor(to);
const double barHalf = BarLayout.barH / 2;
@@ -533,11 +541,12 @@ class BarPainter extends CustomPainter {
..color = col.withValues(alpha: 0.95),
);
_arrow(canvas, arrowTip, arrowDir, col);
// 标签置于依赖线旁,避免压住箭头。
_chip(canvas, Offset(chipX, chipY), label, col, crit);
// 先记录标签位置,所有依赖线画完后统一避让放置(避免标签互相重叠)。
chips.add(_ChipSpec(Offset(chipX, chipY), label, col));
k++;
}
}
_placeChips(canvas, chips);
}
/// 在 [tip] 处绘制指向 [dir] 方向的实心三角箭头。
@@ -555,16 +564,41 @@ class BarPainter extends CustomPainter {
canvas.drawPath(p, Paint()..color = col);
}
/// 绘制依赖类型标签胶囊。
/// 统一放置并绘制依赖标签,避免标签之间相互重叠。
///
/// 参数 [center]:胶囊中心;[label]:文字;[col]:边框与文字色;
/// [crit]:为真时在左侧追加星形关键标记,并把胶囊加宽。
void _chip(Canvas canvas, Offset center, String label, Color col, bool crit) {
// 图注字号与刻度文字接近,整体更紧凑。
final TextPainter tp = _tp(label, 9.5, col, FontWeight.w600);
final double w = tp.width + 14 + (crit ? 15 : 0);
const double h = 15;
final Rect r = Rect.fromCenter(center: center, width: w, height: h);
/// 对每个标签依次尝试:原位 → 上下错开 → 上下再错开 → 左右错开 → 斜向错开,
/// 取第一个不与已放置标签相交的位置,实现“智能避让”。标签内不再绘制五角星
/// (关键路径改用线条光晕表示),字号与色块同时收小,画面更干净。
void _placeChips(Canvas canvas, List<_ChipSpec> chips) {
final List<Rect> placed = <Rect>[];
for (final _ChipSpec chip in chips) {
final TextPainter tp = _tp(chip.label, 8.5, chip.color, FontWeight.w600);
final double w = tp.width + 12;
const double h = 14;
final List<Offset> trials = <Offset>[
Offset.zero,
Offset(0, -(h + 3)), Offset(0, h + 3),
Offset(0, -2 * (h + 3)), Offset(0, 2 * (h + 3)),
Offset(0, -3 * (h + 3)), Offset(0, 3 * (h + 3)),
Offset(w + 6, 0), Offset(-w - 6, 0),
Offset(w + 6, -(h + 3)), Offset(-w - 6, -(h + 3)),
Offset(w + 6, h + 3), Offset(-w - 6, h + 3),
];
Rect r = Rect.fromCenter(center: chip.center, width: w, height: h);
for (final Offset t in trials) {
final Rect cand = r.shift(t);
if (!placed.any((Rect o) => o.inflate(1.5).overlaps(cand))) {
r = cand;
break;
}
}
placed.add(r);
_chipRect(canvas, r, tp, chip.color);
}
}
/// 按给定矩形绘制一颗标签胶囊(无星标)。
void _chipRect(Canvas canvas, Rect r, TextPainter tp, Color col) {
canvas.drawRRect(
RRect.fromRectAndRadius(r, const Radius.circular(5)),
Paint()..color = tokens.chip,
@@ -576,13 +610,7 @@ class BarPainter extends CustomPainter {
..strokeWidth = 1
..color = col,
);
if (crit) {
canvas.drawCircle(Offset(r.left + 8, center.dy), 6, Paint()..color = tokens.crit);
_text(canvas, '★', Offset(r.left + 8, center.dy), color: tokens.onAccent, size: 9, align: TextAlign.center);
tp.paint(canvas, Offset(r.left + 16, center.dy - tp.height / 2));
} else {
tp.paint(canvas, Offset(r.left + 7, center.dy - tp.height / 2));
}
tp.paint(canvas, Offset(r.left + 6, r.center.dy - tp.height / 2));
}
/// 构造并布局一个 [TextPainter]。
@@ -653,3 +681,17 @@ class BarPainter extends CustomPainter {
@override
bool shouldRepaint(covariant BarPainter old) => true;
}
/// 依赖标签的待放置描述:中心点、文本与颜色。
///
/// 在依赖遍历中收集,随后由 `BarPainter._placeChips` 统一做避让放置。
class _ChipSpec {
const _ChipSpec(this.center, this.label, this.color);
/// 期望的标签中心(逻辑坐标)。
final Offset center;
/// 标签文本(如 `FS` / `SS+30°`)。
final String label;
/// 边框与文字颜色(按依赖类型区分)。
final Color color;
}