Add MoveNode::relative

This commit is contained in:
mars 2022-09-19 09:22:52 -06:00
parent be6693b20a
commit 1803d784f9
1 changed files with 9 additions and 1 deletions

View File

@ -126,6 +126,7 @@ impl Command for DeleteNode {
pub struct MoveNode {
pub target: usize,
pub to: glam::Vec2,
pub relative: bool,
}
impl Command for MoveNode {
@ -135,6 +136,7 @@ impl Command for MoveNode {
let undo = Self {
target: self.target,
to: target.pos,
relative: false,
};
Ok(Box::new(undo))
@ -142,7 +144,13 @@ impl Command for MoveNode {
fn apply(&self, graph: &mut Graph) -> GraphResult<()> {
let target = graph.get_node_mut(self.target)?;
target.pos = self.to;
if self.relative {
target.pos += self.to;
} else {
target.pos = self.to;
}
Ok(())
}
}