Skip to content

Commit 789e47e

Browse files
authored
Renaming and API stabilization (#240)
1 parent e74a366 commit 789e47e

9 files changed

Lines changed: 25 additions & 28 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "egui_graphs"
3-
version = "0.25.1"
3+
version = "0.26.0"
44
authors = ["Dmitrii Samsonov <blitzarx1@gmail.com>"]
55
license = "MIT"
66
homepage = "https://github.com/blitzarx1/egui_graphs"

examples/demo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ license = "MIT"
66
edition = "2021"
77

88
[dependencies]
9-
egui_graphs = { version = "0.25", features = ["events"] }
9+
egui_graphs = { version = "0.24", features = ["events"] }
1010
egui = "0.31"
1111
eframe = "0.31"
1212
serde_json = "1.0"
1313
petgraph = "0.7"
14+
# TODO: need to implement fdg to upgrade to newer petgraph and egui_graphs
1415
fdg = { git = "https://github.com/grantshandy/fdg" }
1516
rand = "0.9"
1617
crossbeam = "0.8"

examples/demo/src/drawers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct ValuesConfigButtonsStartReset {
77
pub fn draw_start_reset_buttons(
88
ui: &mut egui::Ui,
99
mut values: ValuesConfigButtonsStartReset,
10-
mut on_change: impl FnMut(bool, bool),
10+
mut on_change: impl FnMut(&mut egui::Ui, bool, bool),
1111
) {
1212
ui.vertical(|ui| {
1313
ui.label("Stop or start simulation again or reset to default settings.");
@@ -29,7 +29,7 @@ pub fn draw_start_reset_buttons(
2929
}
3030

3131
if start_simulation_stopped != values.simulation_stopped || reset_pressed {
32-
on_change(values.simulation_stopped, reset_pressed);
32+
on_change(ui, values.simulation_stopped, reset_pressed);
3333
}
3434
});
3535
});

examples/demo/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ impl DemoApp {
248248
drawers::ValuesConfigButtonsStartReset {
249249
simulation_stopped: self.simulation_stopped,
250250
},
251-
|simulation_stopped: bool, reset_pressed: bool| {
251+
|ui: &mut egui::Ui, simulation_stopped: bool, reset_pressed: bool| {
252252
self.simulation_stopped = simulation_stopped;
253253
if reset_pressed {
254-
self.reset()
254+
self.reset(ui)
255255
};
256256
},
257257
);
@@ -443,7 +443,7 @@ impl DemoApp {
443443
);
444444
}
445445

446-
fn reset(&mut self) {
446+
fn reset(&mut self, ui: &mut egui::Ui) {
447447
let settings_graph = settings::SettingsGraph::default();
448448
let settings_simulation = settings::SettingsSimulation::default();
449449

@@ -464,6 +464,8 @@ impl DemoApp {
464464
self.sim = sim;
465465
self.g = g;
466466
self.force = force;
467+
468+
DefaultGraphView::clear_cache(ui);
467469
}
468470
}
469471

examples/layouts/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl LayoutsApp {
3636
}
3737
}
3838

39-
fn clear_cache(&mut self, ui: &mut egui::Ui) {
39+
fn reset(&mut self, ui: &mut egui::Ui) {
4040
match self.settings.layout {
4141
Layout::Hierarchical => {
4242
GraphView::<
@@ -48,7 +48,7 @@ impl LayoutsApp {
4848
DefaultEdgeShape,
4949
LayoutStateHierarchical,
5050
LayoutHierarchical,
51-
>::clear_cache(ui);
51+
>::reset(ui);
5252
}
5353
Layout::Random => {
5454
GraphView::<
@@ -60,7 +60,7 @@ impl LayoutsApp {
6060
DefaultEdgeShape,
6161
LayoutStateRandom,
6262
LayoutRandom,
63-
>::clear_cache(ui);
63+
>::reset(ui);
6464
}
6565
};
6666
}
@@ -82,13 +82,13 @@ impl App for LayoutsApp {
8282
)
8383
.changed()
8484
{
85-
self.clear_cache(ui);
85+
self.reset(ui);
8686
};
8787
if ui
8888
.radio_value(&mut self.settings.layout, Layout::Random, "Random")
8989
.changed()
9090
{
91-
self.clear_cache(ui);
91+
self.reset(ui);
9292
};
9393
});
9494
ui.horizontal(|ui| {
@@ -97,7 +97,7 @@ impl App for LayoutsApp {
9797
.add(egui::Slider::new(&mut self.settings.num_nodes, 1..=250))
9898
.changed()
9999
{
100-
self.clear_cache(ui);
100+
self.reset(ui);
101101
self.g = random_graph(self.settings.num_nodes, self.settings.num_edges);
102102
};
103103
});
@@ -107,7 +107,7 @@ impl App for LayoutsApp {
107107
.add(egui::Slider::new(&mut self.settings.num_edges, 1..=250))
108108
.changed()
109109
{
110-
self.clear_cache(ui);
110+
self.reset(ui);
111111
self.g = random_graph(self.settings.num_nodes, self.settings.num_edges);
112112
};
113113
});

src/elements/node.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ where
2323

2424
color: Option<Color32>,
2525
location: Pos2,
26-
location_user: Option<Pos2>,
2726
}
2827

2928
impl<N> NodeProps<N>
3029
where
3130
N: Clone,
3231
{
3332
pub fn location(&self) -> Pos2 {
34-
self.location_user.unwrap_or(self.location)
33+
self.location
3534
}
3635

3736
pub fn color(&self) -> Option<Color32> {
@@ -103,7 +102,6 @@ where
103102
payload,
104103
location: Pos2::default(),
105104
color: Option::default(),
106-
location_user: Option::default(),
107105
label: String::default(),
108106
selected: bool::default(),
109107
dragged: bool::default(),
@@ -166,11 +164,6 @@ where
166164
}
167165

168166
pub fn set_location(&mut self, loc: Pos2) {
169-
self.props.location_user = Some(loc);
170-
}
171-
172-
// TODO: why crate? how to use by external layoyuts?? do we need this func???
173-
pub(crate) fn set_layout_location(&mut self, loc: Pos2) {
174167
self.props.location = loc;
175168
}
176169

src/graph_view.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,19 @@ where
174174
self
175175
}
176176

177-
/// Clears cached values of layout and metadata.
178-
pub fn clear_cache(ui: &mut Ui) {
177+
/// Helper to reset both [`Metadata`] and [`Layout`] cache. Can be useful when you want to change layout
178+
/// in runtime
179+
pub fn reset(ui: &mut Ui) {
179180
GraphView::<N, E, Ty, Ix, Dn, De, S, L>::reset_metadata(ui);
180181
GraphView::<N, E, Ty, Ix, Dn, De, S, L>::reset_layout(ui);
181182
}
182183

183-
/// Resets navigation metadata
184+
/// Resets [`Metadata`] state
184185
pub fn reset_metadata(ui: &mut Ui) {
185186
Metadata::default().save(ui);
186187
}
187188

188-
/// Resets layout state
189+
/// Resets [`Layout`] state
189190
pub fn reset_layout(ui: &mut Ui) {
190191
ui.data_mut(|data| {
191192
data.insert_persisted(Id::new(KEY_LAYOUT), S::default());

src/layouts/hierarchical/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
let x = start_col * NODE_DIST;
9090

9191
let node = &mut g.g[*root_idx];
92-
node.set_layout_location(Pos2::new(x as f32, y as f32));
92+
node.set_location(Pos2::new(x as f32, y as f32));
9393

9494
let mut max_col = start_col;
9595
g.g.neighbors_directed(*root_idx, Outgoing)

src/layouts/random/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Layout<State> for Random {
3838

3939
let mut rng = rand::rng();
4040
for node in g.g.node_weights_mut() {
41-
node.set_layout_location(Pos2::new(
41+
node.set_location(Pos2::new(
4242
rng.random_range(0. ..SPAWN_SIZE),
4343
rng.random_range(0. ..SPAWN_SIZE),
4444
));

0 commit comments

Comments
 (0)