Skip to content

Commit 58fd757

Browse files
author
Tom
committed
Delete constraints when depending features are deleted
1 parent 2e9df89 commit 58fd757

File tree

2 files changed

+46
-37
lines changed

2 files changed

+46
-37
lines changed

detailer/src/lib.rs

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,47 +77,50 @@ impl<'a> Widget<'a> {
7777
let mut commands: Vec<ToolResponse> = Vec::with_capacity(4);
7878
let mut changed = false;
7979
let selected: Vec<FeatureKey> = self.drawing.selected_map.keys().map(|k| *k).collect();
80-
for k in selected {
81-
ui.push_id(k, |ui| {
82-
match self.drawing.feature_mut(k) {
83-
Some(Feature::Point(_, x, y)) => Widget::show_selection_entry_point(
84-
ui,
85-
&mut commands,
86-
&mut changed,
87-
&k,
88-
x,
89-
y,
90-
),
91-
Some(Feature::LineSegment(_, _p1, _p2)) => {
92-
Widget::show_selection_entry_line(ui, &mut commands, &mut changed, &k)
80+
81+
egui::ScrollArea::vertical().show(ui, |ui| {
82+
for k in selected {
83+
ui.push_id(k, |ui| {
84+
match self.drawing.feature_mut(k) {
85+
Some(Feature::Point(_, x, y)) => Widget::show_selection_entry_point(
86+
ui,
87+
&mut commands,
88+
&mut changed,
89+
&k,
90+
x,
91+
y,
92+
),
93+
Some(Feature::LineSegment(_, _p1, _p2)) => {
94+
Widget::show_selection_entry_line(ui, &mut commands, &mut changed, &k)
95+
}
96+
None => {}
9397
}
94-
None => {}
95-
}
9698

97-
let constraints = self.drawing.constraints_by_feature(&k);
98-
if constraints.len() > 0 {
99-
egui::CollapsingHeader::new("Constraints")
100-
.default_open(true)
101-
.show(ui, |ui| {
102-
for ck in constraints {
103-
match self.drawing.constraint_mut(ck) {
104-
Some(Constraint::Fixed(_, _, x, y)) => {
105-
Widget::show_constraint_fixed(
106-
ui,
107-
&mut commands,
108-
&mut changed,
109-
&ck,
110-
x,
111-
y,
112-
)
99+
let constraints = self.drawing.constraints_by_feature(&k);
100+
if constraints.len() > 0 {
101+
egui::CollapsingHeader::new("Constraints")
102+
.default_open(true)
103+
.show(ui, |ui| {
104+
for ck in constraints {
105+
match self.drawing.constraint_mut(ck) {
106+
Some(Constraint::Fixed(_, _, x, y)) => {
107+
Widget::show_constraint_fixed(
108+
ui,
109+
&mut commands,
110+
&mut changed,
111+
&ck,
112+
x,
113+
y,
114+
)
115+
}
116+
None => {}
113117
}
114-
None => {}
115118
}
116-
}
117-
});
118-
}
119-
});
120-
}
119+
});
120+
}
121+
});
122+
}
123+
});
121124

122125
for c in commands.drain(..) {
123126
self.handler.handle(self.drawing, self.tools, c);

drawing/src/data.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ impl Data {
248248

249249
let out = match self.features.remove(k) {
250250
Some(_v) => {
251+
// Find and remove any constraints dependent on what we just removed.
252+
let dependent_constraints = self.constraints.by_feature(&k);
253+
for c in dependent_constraints {
254+
self.constraints.delete(c);
255+
}
256+
251257
// Find and also remove any features dependent on what we just removed.
252258
let to_delete: std::collections::HashSet<FeatureKey> = self
253259
.features

0 commit comments

Comments
 (0)