Add MoveNode::relative
This commit is contained in:
parent
be6693b20a
commit
1803d784f9
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue