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;
}
+50 -11
View File
@@ -131,11 +131,14 @@ class CircularPainter extends CustomPainter {
// 依赖连线先于动作弧绘制,使其位于弧之下、不被遮挡。
if (project.viewState.showDeps) {
final List<_ArcChip> chips = <_ArcChip>[];
for (final Action to in project.actions) {
for (final Dependency d in to.deps) {
_dep(canvas, layout, d);
final _ArcChip? chip = _dep(canvas, layout, d);
if (chip != null) chips.add(chip);
}
}
_placeArcChips(canvas, layout, chips);
}
// 逐个绘制动作弧。
@@ -381,10 +384,10 @@ class CircularPainter extends CustomPainter {
/// - 相邻层取两层半径均值作为 [rC];层差大于 1 时改用最外圈 `rMax+24` 绕行。
/// - [large]/[cw] 决定圆弧走大弧还是小弧、顺时针还是逆时针。
/// - 关键依赖先画低透明度粗描边,再画主线,最后放置 `A→B 类型` 胶囊。
void _dep(Canvas canvas, CircularLayout layout, Dependency d) {
_ArcChip? _dep(Canvas canvas, CircularLayout layout, Dependency d) {
final Action? A = project.actionById(d.fromId);
final Action? B = project.actionById(d.toId);
if (A == null || B == null) return;
if (A == null || B == null) return null;
final Offset c = layout.center;
final double rA = layout.radiusFor(A.layer);
final double rB = layout.radiusFor(B.layer);
@@ -455,14 +458,34 @@ class CircularPainter extends CustomPainter {
String label = d.type == DepType.fs ? 'FS' : 'SS+${d.offsetAngle.toStringAsFixed(0)}°';
if (d.type == DepType.ff) label = 'FF';
if (d.type == DepType.sf) label = 'SF';
// 依赖标签沿圆弧切向排布(与动作名一致),呈现“圆弧效果”。
final double arcLen = 2 * math.pi * chipR * 0.9;
_arcLabel(canvas, c, chipR, chipDeg, '${A.id}→${B.id} $label', col, 10,
math.max(math.min(arcLen, 200), 40));
if (crit) {
final Offset sp = polar(c, chipR, chipDeg);
canvas.drawCircle(sp.translate(-46, 0), 7, Paint()..color = tokens.crit);
_text(canvas, '★', sp.translate(-46, 0), color: tokens.onAccent, size: 9, align: TextAlign.center, weight: FontWeight.w700);
// 标签不在此处直接绘制:收集后统一避让放置(见 [_placeArcChips]),
// 字号收小、取消五角星,避免多个依赖(尤其 FS 与 SS 并存)互相压盖。
return _ArcChip(chipR, chipDeg, '${A.id}→${B.id} $label', col);
}
/// 统一绘制圆周视图的依赖标签:沿半径方向逐级外移 / 内移避让,避免相互重叠。
///
/// 估算每个标签的占位矩形(文本长度 × 字号),若与已放置标签相交则按
/// +14 / −14 / +28 / −28 … 的步长沿半径方向挪动,直到找到空位。
void _placeArcChips(Canvas canvas, CircularLayout layout, List<_ArcChip> chips) {
final Offset c = layout.center;
final List<Rect> placed = <Rect>[];
const double size = 8.5;
for (final _ArcChip chip in chips) {
final double w = chip.text.runes.length * size * 0.62 + 8;
final double h = size * 1.7;
double r = chip.r;
Rect rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h);
for (int i = 1; i <= 10; i++) {
if (!placed.any((Rect o) => o.inflate(1.5).overlaps(rect))) break;
final double step = 14.0 * ((i + 1) ~/ 2);
r = chip.r + (i.isOdd ? step : -step);
rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h);
}
placed.add(rect);
final double arcLen = 2 * math.pi * r * 0.9;
_arcLabel(canvas, c, r, chip.deg, chip.text, chip.color, size,
math.max(math.min(arcLen, 200), 40));
}
}
@@ -626,3 +649,19 @@ class CircularPainter extends CustomPainter {
@override
bool shouldRepaint(covariant CircularPainter old) => true;
}
/// 圆周视图依赖标签的待放置描述:半径、角度、文本与颜色。
///
/// 先在依赖遍历中收集,再由 [CircularPainter] 统一做径向避让绘制。
class _ArcChip {
const _ArcChip(this.r, this.deg, this.text, this.color);
/// 期望的标签半径(像素)。
final double r;
/// 期望的标签角度(度,0° = 12 点钟、顺时针)。
final double deg;
/// 标签文本(如 `A1→A2 SS+30°`)。
final String text;
/// 文本颜色(按依赖类型区分)。
final Color color;
}