fix(editor): port docks elegantly — line terminates at perimeter
Stefan's "the connections to the round ports look unelegant" feedback was about three concrete things: (1) The bezier endpoint sat at the port dot's GEOMETRIC CENTRE. The dot was rendered ON TOP, so the line visually disappeared into the centre of the dot — looked like a thread being eaten by a bead. (2) A separate arrow-head triangle was drawn on top of the dot, doubling the visual terminator and making the endpoint look "noisy". (3) The dots were hollow rings the same colour as the line, so the boundary between line and dot blurred visually. They didn't read as connectors. Fix: - EdgeSegment now carries `fromSide` + `toSide` (left / right) so the painter knows which way to shorten each endpoint. The bezier ends `portRadius` px short of the centre — exactly on the dot's outer perimeter, on the side facing the line. The line now "docks" cleanly at the rim. - The end-cap triangle arrow is gone. The dot itself is the visual terminator; an arrow on top was redundant. - Port dot redesigned as a connector-socket: outer ring defines the footprint, inner 4-px surface-coloured pin appears when connected. The result reads as "an active socket with a plug seated in it" rather than "a hollow circle next to a card edge". Empty ports stay surface- filled rings — unambiguous empty-slot signal. - Bezier handle length floor raised from 40 to 60 px so vertical detours (e.g. inputs-endpoint → step far below) curve gracefully out of the start before dropping instead of kinking near the origin. - Stroke width nudged from 1.8 to 2.0 px for the normal accent so the line carries the right visual weight against the new docked-at-perimeter port treatment. Visual: lines now look like cables seated into sockets, not strings vanishing under beads. Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
parent
e4e2d45374
commit
9afb51a4b5
3 changed files with 115 additions and 47 deletions
|
|
@ -11,13 +11,22 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Which horizontal edge of its host node a port sits on.
|
||||
/// Determines whether the bezier endpoint shortens INWARD or
|
||||
/// OUTWARD when terminating at the port dot's perimeter.
|
||||
enum EdgeSide { left, right }
|
||||
|
||||
class EdgeSegment {
|
||||
final Offset from;
|
||||
final Offset to;
|
||||
final EdgeSide fromSide;
|
||||
final EdgeSide toSide;
|
||||
final EdgeAccent accent;
|
||||
const EdgeSegment({
|
||||
required this.from,
|
||||
required this.to,
|
||||
required this.fromSide,
|
||||
required this.toSide,
|
||||
this.accent = EdgeAccent.normal,
|
||||
});
|
||||
}
|
||||
|
|
@ -30,11 +39,21 @@ class EdgePainter extends CustomPainter {
|
|||
final Color highlightColor;
|
||||
final Color draftColor;
|
||||
|
||||
/// Radius of the port dot the line is terminating at. The
|
||||
/// bezier endpoint shortens by this amount on each end so
|
||||
/// the line stops cleanly at the dot's outer perimeter
|
||||
/// instead of vanishing under the dot's centre. Without
|
||||
/// this, the connection looks like a string being eaten
|
||||
/// by a bead; with it, the line "docks" at the port like
|
||||
/// a cable at a socket.
|
||||
final double portRadius;
|
||||
|
||||
EdgePainter({
|
||||
required this.segments,
|
||||
required this.baseColor,
|
||||
required this.highlightColor,
|
||||
required this.draftColor,
|
||||
this.portRadius = 6.0,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
@ -48,24 +67,36 @@ class EdgePainter extends CustomPainter {
|
|||
final paint = Paint()
|
||||
..color = color
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = seg.accent == EdgeAccent.highlight ? 2.5 : 1.8
|
||||
..strokeWidth = seg.accent == EdgeAccent.highlight ? 2.6 : 2.0
|
||||
..strokeCap = StrokeCap.round;
|
||||
final path = _bezier(seg.from, seg.to);
|
||||
canvas.drawPath(path, paint);
|
||||
// End-cap arrow: small filled triangle pointing at the
|
||||
// target port so the reader can tell direction at a
|
||||
// glance without inspecting the geometry.
|
||||
_drawArrowHead(canvas, seg.to, seg.from, color);
|
||||
// Shorten the segment so the endpoints land on the
|
||||
// OUTER perimeter of the port dots, not at the centre.
|
||||
// The shift sign depends on the side each port sits on:
|
||||
// a left-side port has its outer perimeter to the left
|
||||
// of its centre, so we move the endpoint LEFT by
|
||||
// radius; right-side port goes the other way.
|
||||
final shortenedFrom = Offset(
|
||||
seg.from.dx +
|
||||
(seg.fromSide == EdgeSide.right ? portRadius : -portRadius),
|
||||
seg.from.dy,
|
||||
);
|
||||
final shortenedTo = Offset(
|
||||
seg.to.dx + (seg.toSide == EdgeSide.right ? portRadius : -portRadius),
|
||||
seg.to.dy,
|
||||
);
|
||||
canvas.drawPath(_bezier(shortenedFrom, shortenedTo), paint);
|
||||
}
|
||||
}
|
||||
|
||||
Path _bezier(Offset from, Offset to) {
|
||||
// Cubic with horizontal handles — typical "flow diagram"
|
||||
// smooth curve. The handle length scales with the
|
||||
// horizontal distance so steep verticals still look
|
||||
// graceful.
|
||||
// smooth curve. Handle length scales with the horizontal
|
||||
// distance with a comfortable minimum (60 px) so vertical
|
||||
// detours (e.g. an inputs-endpoint port reaching a step
|
||||
// way down on the canvas) still curve gracefully out of
|
||||
// the start before dropping.
|
||||
final dx = (to.dx - from.dx).abs();
|
||||
final handleLen = (dx / 2).clamp(40.0, 220.0);
|
||||
final handleLen = (dx / 2).clamp(60.0, 260.0);
|
||||
return Path()
|
||||
..moveTo(from.dx, from.dy)
|
||||
..cubicTo(
|
||||
|
|
@ -78,28 +109,11 @@ class EdgePainter extends CustomPainter {
|
|||
);
|
||||
}
|
||||
|
||||
void _drawArrowHead(Canvas canvas, Offset tip, Offset from, Color color) {
|
||||
// Approximate the incoming direction by sampling a
|
||||
// little before the tip. Good enough since the curve is
|
||||
// nearly horizontal near the end.
|
||||
final dir = tip.dx - from.dx;
|
||||
final orient = dir >= 0 ? 1.0 : -1.0;
|
||||
const size = 6.0;
|
||||
final p1 = tip;
|
||||
final p2 = Offset(tip.dx - size * orient, tip.dy - size * 0.7);
|
||||
final p3 = Offset(tip.dx - size * orient, tip.dy + size * 0.7);
|
||||
final path = Path()
|
||||
..moveTo(p1.dx, p1.dy)
|
||||
..lineTo(p2.dx, p2.dy)
|
||||
..lineTo(p3.dx, p3.dy)
|
||||
..close();
|
||||
canvas.drawPath(path, Paint()..color = color);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(EdgePainter old) =>
|
||||
old.segments != segments ||
|
||||
old.baseColor != baseColor ||
|
||||
old.highlightColor != highlightColor ||
|
||||
old.draftColor != draftColor;
|
||||
old.draftColor != draftColor ||
|
||||
old.portRadius != portRadius;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue