pub struct FitAllGraphPlugin;Expand description
Zoom and pan so all nodes fit in the window (⌘0 / Ctrl+0). Undo restores the previous view.
On Plugin::setup, fits once using InitPluginContext::drawable_size (does not push an undo
entry; the initial view is not recorded as a command).
Implementations§
Source§impl FitAllGraphPlugin
impl FitAllGraphPlugin
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/extension.rs (line 40)
8fn main() {
9 Application::new().run(|cx| {
10 let mut graph = Graph::new();
11
12 graph
13 .create_node("number")
14 .position(100.0, 100.0)
15 .size(300.0, 150.0)
16 .output()
17 .data(json!({ "label": "Number Node" }))
18 .build(&mut graph);
19
20 graph
21 .create_node("")
22 .position(300.0, 400.0)
23 .input()
24 .build(&mut graph);
25
26 graph
27 .create_node("undefined")
28 .position(500.0, 500.0)
29 .input()
30 .output()
31 .build(&mut graph);
32
33 cx.open_window(WindowOptions::default(), |window, cx| {
34 cx.new(|ctx| {
35 FlowCanvas::builder(graph, ctx, window)
36 .plugins_core()
37 .plugin(SnapGuidesPlugin::new())
38 .plugin(ZoomControlsPlugin::new())
39 .plugin(FocusSelectionPlugin::new())
40 .plugin(FitAllGraphPlugin::new())
41 .plugin(ClipboardPlugin::new())
42 .plugin(ContextMenuPlugin::new())
43 .node_renderer("number", NumberNode {})
44 .build()
45 })
46 })
47 .unwrap();
48 });
49}More examples
examples/bench.rs (line 35)
5fn main() {
6 Application::new().run(|cx| {
7 let mut graph = Graph::new();
8
9 for j in 0..100 {
10 for i in 0..100 {
11 graph
12 .create_node("")
13 .position(200.0 * i as f32, 200.0 * j as f32)
14 .input()
15 .output()
16 .data(json!({ "label": format!("Node {}", i * 100 + j) }))
17 .build(&mut graph);
18 }
19 }
20
21 let node_ids = graph.nodes().iter().map(|(id, _)| *id).collect::<Vec<_>>();
22
23 generate_chain_edges(&mut graph, node_ids);
24
25 cx.open_window(WindowOptions::default(), |window, cx| {
26 cx.new(|ctx| {
27 FlowCanvas::builder(graph, ctx, window)
28 .plugins_core()
29 .plugin(MinimapPlugin::new())
30 .plugin(ClipboardPlugin::new())
31 .plugin(ContextMenuPlugin::new())
32 .plugin(SelectAllViewportPlugin::new())
33 .plugin(AlignPlugin::new())
34 .plugin(FocusSelectionPlugin::new())
35 .plugin(FitAllGraphPlugin::new())
36 .plugin(SnapGuidesPlugin::new())
37 .plugin(ZoomControlsPlugin::new())
38 .build()
39 })
40 })
41 .unwrap();
42 });
43}examples/theme.rs (line 78)
47fn main() {
48 Application::new().run(|cx| {
49 let mut graph = Graph::new();
50
51 graph
52 .create_node("")
53 .position(100.0, 100.0)
54 .output()
55 .output()
56 .data(json!({ "label": "Themed" }))
57 .build(&mut graph);
58
59 cx.open_window(WindowOptions::default(), |window, cx| {
60 cx.new(|ctx| {
61 FlowCanvas::builder(graph, ctx, window)
62 .plugin(DarkGridThemePlugin)
63 .plugin(MinimapPlugin::new())
64 .plugin(SelectionPlugin::new())
65 .plugin(NodeInteractionPlugin::new())
66 .plugin(SnapGuidesPlugin::new())
67 .plugin(ViewportPlugin::new())
68 .plugin(ZoomControlsPlugin::new())
69 .plugin(BackgroundPlugin::new())
70 .plugin(NodePlugin::new())
71 .plugin(PortInteractionPlugin::new())
72 .plugin(EdgePlugin::new())
73 .plugin(ClipboardPlugin::new())
74 .plugin(ContextMenuPlugin::new())
75 .plugin(SelectAllViewportPlugin::new())
76 .plugin(AlignPlugin::new())
77 .plugin(FocusSelectionPlugin::new())
78 .plugin(FitAllGraphPlugin::new())
79 .plugin(DeletePlugin::new())
80 .plugin(HistoryPlugin::new())
81 .build()
82 })
83 })
84 .unwrap();
85 });
86}examples/basic.rs (line 51)
5fn main() {
6 Application::new().run(|cx| {
7 let mut graph = Graph::new();
8
9 graph
10 .create_node("")
11 .position(100.0, 100.0)
12 .output()
13 .output()
14 .output_with(PortPosition::Bottom, Size::new(px(20.0), px(20.0)))
15 .output_at(PortPosition::Bottom)
16 .data(json!({ "label": "Node 1" }))
17 .build(&mut graph);
18
19 graph
20 .create_node("")
21 .position(300.0, 400.0)
22 .input()
23 .input_at(PortPosition::Top)
24 .input_at(PortPosition::Top)
25 .output()
26 .output_at(PortPosition::Bottom)
27 .output_at(PortPosition::Bottom)
28 .data(json!({ "label": "Node 2" }))
29 .build(&mut graph);
30
31 graph
32 .create_node("")
33 .position(500.0, 500.0)
34 .input()
35 .output()
36 .data(json!({ "label": "Node 3" }))
37 .build(&mut graph);
38
39 cx.open_window(WindowOptions::default(), |window, cx| {
40 cx.new(|ctx| {
41 FlowCanvas::builder(graph, ctx, window)
42 .plugins_core()
43 .plugin(MinimapPlugin::new())
44 .plugin(SnapGuidesPlugin::new())
45 .plugin(ZoomControlsPlugin::new())
46 .plugin(ClipboardPlugin::new())
47 .plugin(ContextMenuPlugin::new())
48 .plugin(SelectAllViewportPlugin::new())
49 .plugin(AlignPlugin::new())
50 .plugin(FocusSelectionPlugin::new())
51 .plugin(FitAllGraphPlugin::new())
52 .build()
53 })
54 })
55 .unwrap();
56 });
57}Trait Implementations§
Source§impl Plugin for FitAllGraphPlugin
impl Plugin for FitAllGraphPlugin
fn name(&self) -> &'static str
fn setup(&mut self, ctx: &mut InitPluginContext<'_, '_>)
fn priority(&self) -> i32
fn on_event( &mut self, event: &FlowEvent, ctx: &mut PluginContext<'_>, ) -> EventResult
fn render(&mut self, _ctx: &mut RenderContext<'_>) -> Option<AnyElement>
fn render_layer(&self) -> RenderLayer
Auto Trait Implementations§
impl Freeze for FitAllGraphPlugin
impl RefUnwindSafe for FitAllGraphPlugin
impl Send for FitAllGraphPlugin
impl Sync for FitAllGraphPlugin
impl Unpin for FitAllGraphPlugin
impl UnsafeUnpin for FitAllGraphPlugin
impl UnwindSafe for FitAllGraphPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more