Add persisted state-machine diagram contexts and shared geometry
This commit is contained in:
@@ -908,9 +908,19 @@ fn layout(p: &mut Project, diagram: Id) -> Result<(), ModelError> {
|
||||
if !seen.insert(id) {
|
||||
return Err(ModelError("Diagram containment cycle.".into()));
|
||||
}
|
||||
let own = crate::projection::minimum_node_size(p, d.nodes[&id].element, d.nodes[&id].size);
|
||||
let node = &d.nodes[&id];
|
||||
let own = crate::projection::minimum_node_size(p, node.element, node.size);
|
||||
let own = if d.projection.state_machine().is_some() {
|
||||
crate::projection::state_node_size(p, &p.elements[&node.element], own, false)
|
||||
} else {
|
||||
own
|
||||
};
|
||||
let mut width = own.width;
|
||||
let mut height = 64.;
|
||||
let mut height = if d.projection.state_machine().is_some() {
|
||||
crate::projection::state_header_height(p, node.element)
|
||||
} else {
|
||||
64.
|
||||
};
|
||||
let kids = children.get(&Some(id));
|
||||
if let Some(kids) = kids {
|
||||
for child in kids {
|
||||
@@ -935,9 +945,10 @@ fn layout(p: &mut Project, diagram: Id) -> Result<(), ModelError> {
|
||||
children: &BTreeMap<Option<Id>, Vec<Id>>,
|
||||
sizes: &BTreeMap<Id, Size>,
|
||||
positions: &mut BTreeMap<Id, Position>,
|
||||
headers: &BTreeMap<Id, f32>,
|
||||
) {
|
||||
positions.insert(id, position);
|
||||
let mut y = position.y + 64.;
|
||||
let mut y = position.y + headers[&id];
|
||||
if let Some(kids) = children.get(&Some(id)) {
|
||||
for child in kids {
|
||||
place(
|
||||
@@ -949,6 +960,7 @@ fn layout(p: &mut Project, diagram: Id) -> Result<(), ModelError> {
|
||||
children,
|
||||
sizes,
|
||||
positions,
|
||||
headers,
|
||||
);
|
||||
y += sizes[child].height + 16.;
|
||||
}
|
||||
@@ -1006,6 +1018,20 @@ fn layout(p: &mut Project, diagram: Id) -> Result<(), ModelError> {
|
||||
for id in &roots {
|
||||
measure(p, *id, d, &children, &mut sizes, &mut seen)?;
|
||||
}
|
||||
let headers = d
|
||||
.nodes
|
||||
.values()
|
||||
.map(|n| {
|
||||
(
|
||||
n.id,
|
||||
if d.projection.state_machine().is_some() {
|
||||
crate::projection::state_header_height(p, n.element)
|
||||
} else {
|
||||
64.
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let mut positions = BTreeMap::new();
|
||||
let mut x = 60.;
|
||||
let mut y = 60.;
|
||||
@@ -1016,7 +1042,14 @@ fn layout(p: &mut Project, diagram: Id) -> Result<(), ModelError> {
|
||||
y += row_height + 60.;
|
||||
row_height = 0.;
|
||||
}
|
||||
place(*id, Position { x, y }, &children, &sizes, &mut positions);
|
||||
place(
|
||||
*id,
|
||||
Position { x, y },
|
||||
&children,
|
||||
&sizes,
|
||||
&mut positions,
|
||||
&headers,
|
||||
);
|
||||
x += sizes[id].width + 240.;
|
||||
row_height = row_height.max(sizes[id].height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user