Skip to content

Commit

Permalink
Refactor changes (#94)
Browse files Browse the repository at this point in the history
* Replace changes with events
* Add feature flag for the events functionality
* Small bug fixes and `configurable` example enhancements
  • Loading branch information
blitzarx1 authored Oct 19, 2023
1 parent dcab3f9 commit db80061
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 298 deletions.
31 changes: 28 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egui_graphs"
version = "0.13.3"
version = "0.14.0"
authors = ["Dmitrii Samsonov <[email protected]>"]
license = "MIT"
homepage = "https://github.com/blitzarx1/egui_graphs"
Expand All @@ -12,11 +12,13 @@ edition = "2021"
egui = "0.23"
rand = "0.8"
petgraph = "0.6"
crossbeam = "0.8"
serde = {version = "1.0", optional = true}
crossbeam = { version = "0.8", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }

[features]
egui_persistence = ["dep:serde"]
events = ["dep:serde", "dep:serde_json", "dep:crossbeam"]

[workspace]
members = ["examples/*"]
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@ The project implements a Widget for the egui framework, enabling easy visualizat
- [x] Node labels;
- [x] Node interactions and events reporting: click, double click, select, drag;
- [x] Style configuration via egui context styles;
- [x] egui dark/light theme support;
- [x] Dark/Light theme support via egui context styles;
- [x] Events reporting to extend the graph functionality by the user handling them;

## Status
The project is on track for a stable release v1.0.0. For the moment, breaking releases are still possible.

## Egui features support
## Features
### Events
Can be enabled with `events` feature.
- [x] Node click;
- [x] Node double click;
- [x] Node select;
- [x] Node move;
- [x] Node drag;
- [ ] Node hover;

Combining this feature with custom node draw function allows to implement custom node behavior and drawing according to the events happening.

## Egui crates features support
### Persistence
To use egui `persistence` feature you need to enable `egui_persistence` feature of this crate. For example:
```toml
Expand All @@ -30,7 +43,6 @@ egui = {version="0.23", features = ["persistence"]}
## Examples
### Basic setup example
#### Step 1: Setting up the BasicApp struct.

First, let's define the `BasicApp` struct that will hold the graph.
```rust
pub struct BasicApp {
Expand All @@ -39,7 +51,6 @@ pub struct BasicApp {
```

#### Step 2: Implementing the new() function.

Next, implement the `new()` function for the `BasicApp` struct.
```rust
impl BasicApp {
Expand All @@ -51,7 +62,6 @@ impl BasicApp {
```

#### Step 3: Generating the graph.

Create a helper function called `generate_graph()`. In this example, we create three nodes with and three edges connecting them in a triangular pattern.
```rust
fn generate_graph() -> StableGraph<(), (), Directed> {
Expand All @@ -70,7 +80,6 @@ fn generate_graph() -> StableGraph<(), (), Directed> {
```

#### Step 4: Implementing the update() function.

Now, lets implement the `update()` function for the `BasicApp`. This function creates a `GraphView` widget providing a mutable reference to the graph, and adds it to `egui::CentralPanel` using the `ui.add()` function for adding widgets.
```rust
impl App for BasicApp {
Expand All @@ -83,7 +92,6 @@ impl App for BasicApp {
```

#### Step 5: Running the application.

Finally, run the application using the `run_native()` function with the specified native options and the `BasicApp`.
```rust
fn main() {
Expand All @@ -98,9 +106,4 @@ fn main() {
```

![Screenshot 2023-10-14 at 23 49 49](https://github.com/blitzarx1/egui_graphs/assets/32969427/584b78de-bca3-421b-b003-9321fd3e1b13)

You can further customize the appearance and behavior of your graph by modifying the settings or adding more nodes and edges as needed.

### Docs
Docs can be found [here](https://docs.rs/egui_graphs/latest/egui_graphs/)

3 changes: 2 additions & 1 deletion examples/configurable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ license = "MIT"
edition = "2021"

[dependencies]
egui_graphs = { path = "../../" }
egui_graphs = { path = "../../", features = ["events"] }
egui = "0.23"
egui_plot = "0.23"
serde_json = "1.0"
eframe = "0.23"
petgraph = "0.6"
fdg-sim = "0.9"
Expand Down
Loading

0 comments on commit db80061

Please sign in to comment.