Repository: blitzarx1/egui_graphs (language: rust)

Issue:
Question: Is the Graph::from() function able to work with custom edges?
Using the NodeShapeAnimated example I tried to apply a similar setup to edges but im getting a type error on every use of Graph::from() and is clear its trying to return one with a default edge. 

```error[E0308]: mismatched types
   --> src/main.rs:540:16
    |
540 |             g: Graph::from(&g),
    |                ^^^^^^^^^^^^^^^ expected `Graph<(), (), ..., ..., ..., ...>`, found `Graph<_, _, Directed, u32, _>`
    |
    = note: expected struct `egui_graphs::Graph<(), (), _, _, node::NodeShape, edge::EdgeShape>`
               found struct `egui_graphs::Graph<_, _, _, _, _, egui_graphs::DefaultEdgeShape>`
```


Discussion / hints:
Hey! Sorry for long response. You can check `examples/custom_draw` `Graph::from` is used there with `NodeShapeAnimated`. All you need to do is to explicitly set `NodeShapeAnimated` in the `Graph` signature. Please check example. If this does not help please post here your code with this error.
Ah, I wasnt very clear, what i mean to say is that Ive already used NodeShapeAnimated and modified it some, what Im currently working on is EdgeShape and changing that, I copied the defaultedgeshape and applyed it to the same formating that NodeShapeAnimated has. 

You can view my code here https://github.com/Atlas16A/LSegui/blob/master/src/main.rs
The relevant lines are, 14-19, 517, and 946, in the main.rs file and 14, 25, and 41 in the edge.rs file.

My NodeShape works perfectly fine by itself however my EdgeShape creates the error above, when added, on all the Graph::from() functions.

Fix patch:
diff --git a/src/draw/displays.rs b/src/draw/displays.rs
index fc85f75..d5dc176 100644
--- a/src/draw/displays.rs
+++ b/src/draw/displays.rs
@@ -17,13 +17,13 @@ where
     /// Could be used to snap the edge ends to the node.
     fn closest_boundary_point(&self, dir: Vec2) -> Pos2;
 
-    /// Draws shapes of the node.
-    ///
+    /// Draws shapes of the node. If the node is interacted these shapes will be used for drawing on foreground layer, otherwise on background layer.
     /// Has mutable reference to itself for possibility to change internal state for the visualizations where this is important.
     ///
-    /// * `ctx` - should be used to determine current global properties.
+    /// * `ctx` - contains [`egui::Context`] and graph metadata.
     ///
     /// Use `ctx.meta` to properly scale and translate the shape.
+    /// Use `ctx.painter` to have low level access to egui painting process.
     fn shapes(&mut self, ctx: &DrawContext) -> Vec<Shape>;
 
     /// Is called on every frame. Can be used for updating state of the implementation of [DisplayNode]
@@ -45,16 +45,15 @@ where
     Ix: IndexType,
     D: DisplayNode<N, E, Ty, Ix>,
 {
-    /// Draws shapes of the edge.
-    ///
+    /// Draws shapes of the edge. Uses [DisplayNode] implementation from node endpoints to get start and end coordinates using [closest_boundary_point](DisplayNode::closest_boundary_point).
+    /// If the node is interacted these shapes will be used for drawing on foreground layer, otherwise on background layer.
     /// Has mutable reference to itself for possibility to change internal state for the visualizations where this is important.
     ///
-    /// * `ctx` - should be used to determine current global properties.
+    /// * `ctx` - contains [`egui::Context`] and graph metadata.
     /// * `start` and `end` - start and end points of the edge.
     ///
-    /// Uses `ctx.meta` to properly scale and translate the shape.
-    ///
-    /// Uses [DisplayNode] implementation from node endpoints to get start and end coordinates using [closest_boundary_point](DisplayNode::closest_boundary_point).
+    /// Use `ctx.meta` to properly scale and translate the shape.
+    /// Use `ctx.painter` to have low level access to egui painting process.
     fn shapes(
         &mut self,
         start: &Node<N, E, Ty, Ix, D>,
diff --git a/src/draw/drawer.rs b/src/draw/drawer.rs
index 68882da..e6ab4d0 100644
--- a/src/draw/drawer.rs
+++ b/src/draw/drawer.rs
@@ -11,6 +11,7 @@ use super::{DisplayEdge, DisplayNode};
 /// Contains all the data about current widget state which is needed for custom drawing functions.
 pub struct DrawContext<'a> {
     pub ctx: &'a Context,
+    pub painter: &'a Painter,
     pub style: &'a SettingsStyle,
     pub is_directed: bool,
     pub meta: &'a Metadata,
@@ -41,15 +42,12 @@ where
     Nd: DisplayNode<N, E, Ty, Ix>,
     Ed: DisplayEdge<N, E, Ty, Ix, Nd>,
 {
-    pub fn new(
-        p: Painter,
-        g: &'a mut Graph<N, E, Ty, Ix, Nd, Ed>,
-        ctx: &'a DrawContext<'a>,
-    ) -> Self {
-        let layer_top = p
+    pub fn new(g: &'a mut Graph<N, E, Ty, Ix, Nd, Ed>, ctx: &'a DrawContext<'a>) -> Self {
+        let layer_top = ctx
+            .painter
             .clone()
             .with_layer_id(LayerId::new(Order::Foreground, Id::new("top")));
-        let layer_bot = p.with_layer_id(LayerId::background());
+        let layer_bot = ctx.painter.clone().with_layer_id(LayerId::background());
         Drawer {
             layer_top,
             layer_bot,
diff --git a/src/draw/mod.rs b/src/draw/mod.rs
index 54283b6..765a73d 100644
--- a/src/draw/mod.rs
+++ b/src/draw/mod.rs
@@ -3,7 +3,7 @@ mod default_node;
 mod displays;
 mod drawer;
 
-pub use self::drawer::{DrawContext, Drawer};
 pub use default_edge::DefaultEdgeShape;
 pub use default_node::DefaultNodeShape;
 pub use displays::{DisplayEdge, DisplayNode};
+pub use drawer::{DrawContext, Drawer};
diff --git a/src/elements/mod.rs b/src/elements/mod.rs
index 0380c68..9640ccd 100644
--- a/src/elements/mod.rs
+++ b/src/elements/mod.rs
@@ -1,5 +1,5 @@
 mod edge;
 mod node;
 
-pub use self::edge::{Edge, EdgeProps};
-pub use self::node::{Node, NodeProps};
+pub use edge::{Edge, EdgeProps};
+pub use node::{Node, NodeProps};
diff --git a/src/events/mod.rs b/src/events/mod.rs
index a1ebad7..7aaf499 100644
--- a/src/events/mod.rs
+++ b/src/events/mod.rs
@@ -1,6 +1,6 @@
 mod event;
 
-pub use self::event::{
+pub use event::{
     Event, PayloadEdgeClick, PayloadEdgeDeselect, PayloadEdgeSelect, PayloadNodeClick,
     PayloadNodeDeselect, PayloadNodeDoubleClick, PayloadNodeDragEnd, PayloadNodeDragStart,
     PayloadNodeMove, PayloadNodeSelect, PayloadPan, PayloadZoom,
diff --git a/src/graph.rs b/src/graph.rs
index 7e526db..fadc05c 100644
--- a/src/graph.rs
+++ b/src/graph.rs
@@ -34,8 +34,14 @@ pub struct Graph<
     dragged_node: Option<NodeIndex<Ix>>,
 }
 
-impl<N: Clone, E: Clone, Ty: EdgeType, Ix: IndexType, D: DisplayNode<N, E, Ty, Ix>>
-    From<&StableGraph<N, E, Ty, Ix>> for Graph<N, E, Ty, Ix, D>
+impl<
+        N: Clone,
+        E: Clone,
+        Ty: EdgeType,
+        Ix: IndexType,
+        Dn: DisplayNode<N, E, Ty, Ix>,
+        De: DisplayEdge<N, E, Ty, Ix, Dn>,
+    > From<&StableGraph<N, E, Ty, Ix>> for Graph<N, E, Ty, Ix, Dn, De>
 {
     fn from(value: &StableGraph<N, E, Ty, Ix>) -> Self {
         transform::to_graph(value)
diff --git a/src/graph_view.rs b/src/graph_view.rs
index 82e74ac..f0910eb 100644
--- a/src/graph_view.rs
+++ b/src/graph_view.rs
@@ -90,10 +90,10 @@ where
 
         let is_directed = self.g.is_directed();
         Drawer::<N, E, Ty, Ix, Nd, Ed>::new(
-            p,
             self.g,
             &DrawContext {
                 ctx: ui.ctx(),
+                painter: &p,
                 meta: &meta,
                 is_directed,
                 style: &self.settings_style,
diff --git a/src/lib.rs b/src/lib.rs
index 5acc8ec..1fa9f90 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,13 +6,13 @@ mod metadata;
 mod settings;
 mod transform;
 
-pub use self::draw::{DefaultEdgeShape, DefaultNodeShape, DisplayEdge, DisplayNode, DrawContext};
-pub use self::elements::{Edge, EdgeProps, Node, NodeProps};
-pub use self::graph::Graph;
-pub use self::graph_view::GraphView;
-pub use self::metadata::Metadata;
-pub use self::settings::{SettingsInteraction, SettingsNavigation, SettingsStyle};
-pub use self::transform::{
+pub use draw::{DefaultEdgeShape, DefaultNodeShape, DisplayEdge, DisplayNode, DrawContext};
+pub use elements::{Edge, EdgeProps, Node, NodeProps};
+pub use graph::Graph;
+pub use graph_view::GraphView;
+pub use metadata::Metadata;
+pub use settings::{SettingsInteraction, SettingsNavigation, SettingsStyle};
+pub use transform::{
     add_edge, add_edge_custom, add_node, add_node_custom, default_edge_transform,
     default_node_transform, to_graph, to_graph_custom,
 };


Test patch: