-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom drawing function refactor (#97)
* Encapsulated widget state to `WidgetState` struct, for usage in custom drawing functions * Added custom edges drawing function * Added demo with edges labels using custom edges drawing function (#96)
- Loading branch information
Showing
13 changed files
with
428 additions
and
286 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.14.0" | ||
version = "0.15.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
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use egui::Context; | ||
use petgraph::{stable_graph::NodeIndex, EdgeType}; | ||
|
||
use crate::{Edge, Graph, Metadata, Node, SettingsStyle}; | ||
|
||
use super::Layers; | ||
|
||
/// Contains all the data about current widget state which is needed for custom drawing functions. | ||
pub struct WidgetState<'a, N: Clone, E: Clone, Ty: EdgeType> { | ||
pub g: &'a Graph<N, E, Ty>, | ||
pub style: &'a SettingsStyle, | ||
pub meta: &'a Metadata, | ||
} | ||
|
||
/// Allows to fully customize what shape would be drawn for node. | ||
/// The function is called for every node in the graph. | ||
/// | ||
/// Parameters: | ||
/// - egui context, is needed for computing node props and styles; | ||
/// - node reference, contains all node data; | ||
/// - widget state with references to graph, style and metadata; | ||
/// - when you create a shape, add it to the layers. | ||
pub type FnCustomNodeDraw<N, E, Ty> = | ||
fn(&Context, n: &Node<N>, &WidgetState<N, E, Ty>, &mut Layers); | ||
|
||
/// Allows to fully customize what shape would be drawn for an edge. | ||
/// The function is **called once for every node pair** which has edges connecting them. So make sure you have drawn all the edges which are passed to the function. | ||
/// | ||
/// Parameters: | ||
/// - egui context, is needed for computing node props and styles; | ||
/// - start node index and end node index; | ||
/// - vector of edges, all edges between start and end nodes; | ||
/// - widget state with references to graph, style and metadata; | ||
/// - when you create a shape, add it to the layers. | ||
pub type FnCustomEdgeDraw<N, E, Ty> = | ||
fn(&Context, (NodeIndex, NodeIndex), Vec<&Edge<E>>, &WidgetState<N, E, Ty>, &mut Layers); |
Oops, something went wrong.