Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
blitzarx1 committed Jan 13, 2025
1 parent d30a4c4 commit 88da04b
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions src/graph_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,8 @@ where

self.sync_state(&mut meta);

let mut last_layout_events = vec![];
if let Some(events) = &meta.last_layout_events {
last_layout_events = events.clone();
};

let not_placed = &self.g.new_nodes_no_location().iter().copied().collect();

GraphView::<N, E, Ty, Ix, Nd, Ed, S, L>::sync_layout(
ui,
self.g,
last_layout_events.as_slice(),
not_placed,
);

meta.last_layout_events = if let Some(events) = meta.last_layout_events {
Some(
events
.iter()
.cloned()
.filter_map(|el| {
if el == LayoutEvent::NextCalledOnce {
return None;
}

Some(el)
})
.collect(),
)
} else {
Some(vec![LayoutEvent::NextCalledOnce, LayoutEvent::NextCalled])
};
GraphView::<N, E, Ty, Ix, Nd, Ed, S, L>::sync_layout(ui, &mut meta, self.g, not_placed);

let (resp, p) = ui.allocate_painter(ui.available_size(), Sense::click_and_drag());
self.handle_fit_to_screen(&resp, &mut meta);
Expand Down Expand Up @@ -232,18 +203,41 @@ where

fn sync_layout(
ui: &mut Ui,
meta: &mut Metadata,
g: &mut Graph<N, E, Ty, Ix, Dn, De>,
last_layout_events: &[LayoutEvent],
not_placed: &HashSet<NodeIndex<Ix>>,
) {
ui.data_mut(|data| {
let state = data
.get_persisted::<S>(Id::new(KEY_LAYOUT))
.unwrap_or_default();

let mut layout = L::from_state(state, last_layout_events);
let mut last_layout_events = vec![];
if let Some(events) = &meta.last_layout_events {
last_layout_events.clone_from(events);
};

let mut layout = L::from_state(state, last_layout_events.as_slice());
layout.next(g, not_placed);

meta.last_layout_events = if let Some(events) = &meta.last_layout_events {
Some(
events
.iter()
.cloned()
.filter_map(|el| {
if el == LayoutEvent::NextCalledOnce {
return None;
}

Some(el)
})
.collect(),
)
} else {
Some(vec![LayoutEvent::NextCalledOnce, LayoutEvent::NextCalled])
};

data.insert_persisted(Id::new(KEY_LAYOUT), layout.state());
});
}
Expand Down

0 comments on commit 88da04b

Please sign in to comment.