Node can decide whether it can be deleted

This commit is contained in:
huisedenanhai 2022-11-19 22:16:48 +08:00
parent 070ff85bd3
commit d2350d494a
2 changed files with 19 additions and 3 deletions

View File

@ -771,9 +771,16 @@ where
// --- Interaction ---
// Titlebar buttons
if Self::close_button(ui, outer_rect).clicked() {
responses.push(NodeResponse::DeleteNodeUi(self.node_id));
};
let can_delete = self.graph.nodes[self.node_id].user_data.can_delete(
self.node_id,
self.graph,
user_state,
);
if can_delete {
if Self::close_button(ui, outer_rect).clicked() {
responses.push(NodeResponse::DeleteNodeUi(self.node_id));
};
}
let window_response = ui.interact(
outer_rect,

View File

@ -102,6 +102,15 @@ where
) -> Option<egui::Color32> {
None
}
fn can_delete(
&self,
_node_id: NodeId,
_graph: &Graph<Self, Self::DataType, Self::ValueType>,
_user_state: &mut Self::UserState,
) -> bool {
true
}
}
/// This trait can be implemented by any user type. The trait tells the library