pub mod nodeeditor {
include!(concat!(env!("OUT_DIR"), "/node-editor.rs"));
}
pub mod controller;
pub mod graph;
pub mod grid;
pub mod hit_test;
#[cfg(feature = "layout")]
pub mod layout;
pub mod links;
pub mod path;
pub mod selection;
pub mod setup;
pub mod state;
pub mod tracking;
pub use nodeeditor::{
BoxSelectionModifier, LinkCreationState, LinkData, LinkPath, MinimapNode, MinimapPosition,
};
pub use grid::generate_grid_commands;
pub use hit_test::{
distance_to_polyline, find_link_at, find_link_route_at, find_pin_at, links_in_selection_box,
nodes_in_selection_box, BezierLinkRoute, LinkGeometry, LinkRoute, NodeGeometry, PinGeometry,
PolylineLinkRoute, SimpleLinkGeometry, SimpleNodeGeometry,
};
pub use path::{generate_bezier_path, generate_partial_bezier_path};
pub use state::{GeometryCache, StoredPin};
pub use controller::NodeEditorController;
pub use graph::{
validate_and_normalize_link,
BasicLinkValidator,
CompositeValidator,
GraphLogic,
LinkModel,
LinkValidator,
MovableNode,
NoDuplicatesValidator,
NormalizedLink,
SimpleLink,
ValidationError,
ValidationResult,
};
#[cfg(feature = "layout")]
pub use layout::{
sugiyama_layout, sugiyama_layout_from_cache, Direction, NodePosition, SugiyamaConfig,
};
pub use links::LinkManager;
pub use setup::NodeEditorSetup;
pub use tracking::GeometryTracker;
#[macro_export]
macro_rules! wire_node_editor {
($window:expr, $setup:expr) => {{
let gc = $window.global::<NodeEditorInternalCallbacks>();
gc.on_report_node_rect($setup.report_node_rect());
gc.on_report_pin_position($setup.report_pin_position());
gc.on_remove_node_from_cache($setup.remove_node());
gc.on_remove_pin_from_cache($setup.remove_pin());
gc.on_reset_graph_cache($setup.reset_graph());
gc.on_start_node_drag($setup.start_node_drag());
gc.on_cancel_node_drag($setup.cancel_node_drag());
gc.on_end_node_drag($setup.end_node_drag());
let w = $window.as_weak();
gc.on_take_editor_focus(move || {
if let Some(w) = w.upgrade() {
w.invoke_focus_editor();
}
});
let computations = $window.global::<NodeEditorComputations>();
computations.on_compute_link_path($setup.controller().compute_link_path_callback(
|commands, x, y, width, height| LinkPath {
commands: commands.into(),
x,
y,
width,
height,
},
));
let ctrl = $setup.controller().clone();
computations
.on_compute_pin_at(move |x, y, radius| ctrl.cache().borrow().find_pin_at(x, y, radius));
computations.on_compute_link_preview_path(
|start_x, start_y, end_x, end_y, zoom, bezier_offset| {
$crate::generate_bezier_path(start_x, start_y, end_x, end_y, zoom, bezier_offset)
.into()
},
);
$setup
.controller()
.set_grid_spacing(computations.get_grid_spacing());
$setup
.controller()
.set_bezier_offset(computations.get_bezier_min_offset());
let ctrl = $setup.controller().clone();
computations.on_configuration_changed(move |grid_spacing, bezier_offset| {
ctrl.set_grid_spacing(grid_spacing);
ctrl.set_bezier_offset(bezier_offset);
});
let ctrl = $setup.controller().clone();
computations.on_viewport_changed(move |zoom, pan_x, pan_y| {
ctrl.set_viewport(zoom, pan_x, pan_y);
});
let ctrl = $setup.controller().clone();
let w = $window.as_weak();
computations.on_request_grid_update(move || {
if let Some(w) = w.upgrade() {
w.set_grid_commands(ctrl.generate_current_grid(w.get_width_(), w.get_height_()));
}
});
let ctrl = $setup.controller().clone();
let w = $window.as_weak();
if let Some(w) = w.upgrade() {
w.set_grid_commands(ctrl.generate_current_grid(w.get_width_(), w.get_height_()));
}
}};
}
#[macro_export]
macro_rules! wire_selection {
($window:expr, $setup:expr, $nodes:expr) => {{
$window.on_node_selected({
let nodes = $nodes.clone();
move |node_id, shift| {
$crate::selection::apply_click(
&nodes,
|n| n.id,
|n| &mut n.selected,
node_id,
shift,
)
}
});
$window.on_selection_cleared({
let nodes = $nodes.clone();
move || $crate::selection::clear_selection(&nodes, |n| &mut n.selected)
});
$window.on_box_selection_committed({
let nodes = $nodes.clone();
let ctrl = $setup.controller().clone();
move |x, y, w, h, shift| {
let hits = ctrl.cache().borrow().nodes_in_selection_box(x, y, w, h);
$crate::selection::apply_box(&nodes, |n| n.id, |n| &mut n.selected, hits, shift)
}
});
}};
($window:expr, $setup:expr, $nodes:expr, $links:expr) => {{
$window.on_node_selected({
let nodes = $nodes.clone();
let links = $links.clone();
move |node_id, shift| {
if !shift {
$crate::selection::clear_selection(&links, |l| &mut l.selected);
}
$crate::selection::apply_click(
&nodes,
|n| n.id,
|n| &mut n.selected,
node_id,
shift,
)
}
});
$window.on_select_link({
let nodes = $nodes.clone();
let links = $links.clone();
move |link_id, shift| {
if !shift {
$crate::selection::clear_selection(&nodes, |n| &mut n.selected);
}
$crate::selection::apply_click(
&links,
|l| l.id,
|l| &mut l.selected,
link_id,
shift,
)
}
});
$window.on_selection_cleared({
let nodes = $nodes.clone();
let links = $links.clone();
move || {
$crate::selection::clear_selection(&nodes, |n| &mut n.selected);
$crate::selection::clear_selection(&links, |l| &mut l.selected);
}
});
$window.on_box_selection_committed({
let nodes = $nodes.clone();
let links = $links.clone();
let ctrl = $setup.controller().clone();
move |x, y, w, h, shift| {
let (node_hits, link_hits) = {
let cache = ctrl.cache();
let cache = cache.borrow();
let rows = (0..slint::Model::row_count(&*links))
.filter_map(|i| slint::Model::row_data(&*links, i))
.map(|l| (l.id, l.start_pin_id, l.end_pin_id));
(
cache.nodes_in_selection_box(x, y, w, h),
cache.links_in_selection_box(x, y, w, h, rows),
)
};
$crate::selection::apply_box(
&nodes,
|n| n.id,
|n| &mut n.selected,
node_hits,
shift,
);
$crate::selection::apply_box(
&links,
|l| l.id,
|l| &mut l.selected,
link_hits,
shift,
)
}
});
}};
}