Add persisted per-view port anchors and connection-aware border placement

This commit is contained in:
2026-09-06 01:20:28 +03:00
parent 93fd32c684
commit 35133de650
13 changed files with 1435 additions and 149 deletions
+31
View File
@@ -1264,6 +1264,34 @@ pub struct EdgeLabel {
pub offset: Position,
}
pub const MAX_ROUTE_POINTS: usize = 128;
/// Presentation side; independent of the semantic port direction.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum PortAnchorSide {
Left,
Right,
Top,
Bottom,
}
impl PortAnchorSide {
pub fn normal(self) -> Position {
match self {
Self::Left => Position { x: -1., y: 0. },
Self::Right => Position { x: 1., y: 0. },
Self::Top => Position { x: 0., y: -1. },
Self::Bottom => Position { x: 0., y: 1. },
}
}
}
/// Manual position of a semantic child port on one owner placement.
/// Absence from the placement's list selects automatic positioning.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PortAnchor {
pub port: Id,
pub side: PortAnchorSide,
/// Fraction of the complete edge, from top (vertical) or left (horizontal).
pub offset: f32,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct NodePlacement {
@@ -1273,6 +1301,8 @@ pub struct NodePlacement {
pub position: Position,
pub size: Size,
pub collapsed: bool,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub port_anchors: Vec<PortAnchor>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ArtifactRelation {
@@ -1660,6 +1690,7 @@ impl Project {
height: 94.,
},
collapsed: false,
port_anchors: Vec::new(),
};
if let Some(d) = self.diagrams.get_mut(&diagram) {
d.nodes.insert(id, node);