-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make enum for changes * Send one by one.
- Loading branch information
Showing
10 changed files
with
145 additions
and
215 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "egui_graphs" | ||
version = "0.3.1" | ||
version = "0.4.0" | ||
authors = ["Dmitrii Samsonov <[email protected]>"] | ||
license = "MIT" | ||
homepage = "https://github.com/blitzarx1/egui_graphs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "basic" | ||
version = "0.3.1" | ||
version = "0.4.0" | ||
authors = ["Dmitrii Samsonov <[email protected]>"] | ||
license = "MIT" | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "configurable" | ||
version = "0.3.1" | ||
version = "0.4.0" | ||
authors = ["Dmitrii Samsonov <[email protected]>"] | ||
license = "MIT" | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "interactive" | ||
version = "0.3.1" | ||
version = "0.4.0" | ||
authors = ["Dmitrii Samsonov <[email protected]>"] | ||
license = "MIT" | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use egui::Vec2; | ||
use petgraph::stable_graph::{NodeIndex, EdgeIndex}; | ||
|
||
/// `ChangeNode` is a enum that stores the changes to `Node` properties. | ||
#[derive(Debug, Clone)] | ||
pub enum ChangeNode { | ||
Location { id: NodeIndex, old: Vec2, new: Vec2 }, | ||
|
||
Selected { id: NodeIndex, old: bool, new: bool }, | ||
|
||
Dragged { id: NodeIndex, old: bool, new: bool }, | ||
} | ||
|
||
impl ChangeNode { | ||
pub(crate) fn change_location(id: NodeIndex, old: Vec2, new: Vec2) -> Self { | ||
Self::Location { id, old, new } | ||
} | ||
|
||
pub(crate) fn change_selected(id: NodeIndex, old: bool, new: bool) -> Self { | ||
Self::Selected { id, old, new } | ||
} | ||
|
||
pub(crate) fn change_dragged(id: NodeIndex, old: bool, new: bool) -> Self { | ||
Self::Dragged { id, old, new } | ||
} | ||
} | ||
|
||
/// `ChangeEdge` is a enum that stores the changes to `Edge` properties. | ||
#[derive(Debug, Clone)] | ||
pub enum ChangeEdge { | ||
Selected { id: EdgeIndex, old: bool, new: bool }, | ||
} | ||
|
||
impl ChangeEdge { | ||
pub(crate) fn change_selected(id: EdgeIndex, old: bool, new: bool) -> Self { | ||
Self::Selected { id, old, new } | ||
} | ||
} | ||
|
||
/// Change is a enum that stores the changes to `Node` or `Edge` properties. | ||
#[derive(Debug, Clone)] | ||
pub enum Change { | ||
Node(ChangeNode), | ||
Edge(ChangeEdge), | ||
} | ||
|
||
impl Change { | ||
pub(crate) fn node(change: ChangeNode) -> Self { | ||
Self::Node(change) | ||
} | ||
|
||
pub(crate) fn edge(change: ChangeEdge) -> Self { | ||
Self::Edge(change) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use egui::vec2; | ||
|
||
#[test] | ||
fn test_change_enum() { | ||
let node_id = NodeIndex::new(0); | ||
let edge_id = EdgeIndex::new(0); | ||
|
||
let old_node_location = vec2(0.0, 0.0); | ||
let new_node_location = vec2(10.0, 10.0); | ||
|
||
let node_change = Change::node(ChangeNode::change_location(node_id, old_node_location, new_node_location)); | ||
|
||
let node_selected_old = false; | ||
let node_selected_new = true; | ||
|
||
let edge_change = Change::edge(ChangeEdge::change_selected(edge_id, node_selected_old, node_selected_new)); | ||
|
||
match node_change { | ||
Change::Node(ChangeNode::Location { id, old, new }) => { | ||
assert_eq!(id, node_id); | ||
assert_eq!(old, old_node_location); | ||
assert_eq!(new, new_node_location); | ||
} | ||
_ => panic!("Unexpected node change type"), | ||
} | ||
|
||
match edge_change { | ||
Change::Edge(ChangeEdge::Selected { id, old, new }) => { | ||
assert_eq!(id, edge_id); | ||
assert_eq!(old, node_selected_old); | ||
assert_eq!(new, node_selected_new); | ||
} | ||
_ => panic!("Unexpected edge change type"), | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.