pub struct ContextMenuPlugin { /* private fields */ }Expand description
Right-click menu on the canvas (empty area) or on a node. Optional ContextMenuCanvasExtra rows
are appended after built-in canvas actions.
Implementations§
Source§impl ContextMenuPlugin
impl ContextMenuPlugin
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/extension.rs (line 42)
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 31)
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 74)
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 47)
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}pub fn with_canvas_extras(canvas_extras: Vec<ContextMenuCanvasExtra>) -> Self
Sourcepub fn canvas_row(
self,
label: impl Into<SharedString>,
on_select: impl for<'a> Fn(&mut PluginContext<'a>, Point<Pixels>) + Send + Sync + 'static,
) -> Self
pub fn canvas_row( self, label: impl Into<SharedString>, on_select: impl for<'a> Fn(&mut PluginContext<'a>, Point<Pixels>) + Send + Sync + 'static, ) -> Self
Append a canvas-background row with a custom label (e.g. “Add node…” → show input in meili).
Sourcepub fn canvas_row_with_shortcut(
self,
label: impl Into<SharedString>,
shortcut: impl Into<SharedString>,
on_select: impl for<'a> Fn(&mut PluginContext<'a>, Point<Pixels>) + Send + Sync + 'static,
) -> Self
pub fn canvas_row_with_shortcut( self, label: impl Into<SharedString>, shortcut: impl Into<SharedString>, on_select: impl for<'a> Fn(&mut PluginContext<'a>, Point<Pixels>) + Send + Sync + 'static, ) -> Self
Same as Self::canvas_row but with a shortcut hint string shown on the right.
Trait Implementations§
Source§impl Plugin for ContextMenuPlugin
impl Plugin for ContextMenuPlugin
fn name(&self) -> &'static str
fn setup(&mut self, _ctx: &mut InitPluginContext<'_, '_>)
fn priority(&self) -> i32
fn render_layer(&self) -> RenderLayer
fn render(&mut self, ctx: &mut RenderContext<'_>) -> Option<AnyElement>
fn on_event( &mut self, event: &FlowEvent, ctx: &mut PluginContext<'_>, ) -> EventResult
Auto Trait Implementations§
impl Freeze for ContextMenuPlugin
impl !RefUnwindSafe for ContextMenuPlugin
impl Send for ContextMenuPlugin
impl Sync for ContextMenuPlugin
impl Unpin for ContextMenuPlugin
impl UnsafeUnpin for ContextMenuPlugin
impl !UnwindSafe for ContextMenuPlugin
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