Skip to main content

ContextMenuPlugin

Struct ContextMenuPlugin 

Source
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

Source

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
Hide additional 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}
Source

pub fn with_canvas_extras(canvas_extras: Vec<ContextMenuCanvasExtra>) -> Self

Source

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).

Source

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

Source§

fn name(&self) -> &'static str

Source§

fn setup(&mut self, _ctx: &mut InitPluginContext<'_, '_>)

Source§

fn priority(&self) -> i32

Source§

fn render_layer(&self) -> RenderLayer

Source§

fn render(&mut self, ctx: &mut RenderContext<'_>) -> Option<AnyElement>

Source§

fn on_event( &mut self, event: &FlowEvent, ctx: &mut PluginContext<'_>, ) -> EventResult

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more