nodui_egui/context_menu.rs
1//! Contextual information for context menu of the graph editor.
2
3use egui::Ui;
4use nodui_core::adapter::{GraphAdapter, Pos};
5
6/* -------------------------------------------------------------------------- */
7
8/// A boxed dynamic callback for the visual editor context menu.
9pub(crate) type ContextMenuContent<'a, G> = Box<dyn FnMut(&mut Ui, MenuContext<'_, G>) + 'a>;
10
11/// Contextual information for graph editor context menu.
12pub struct MenuContext<'a, G: GraphAdapter> {
13 /// A mutable reference of the [`GraphAdapter`] used by the editor.
14 pub graph: &'a mut G,
15
16 /// The graph position of the pointer.
17 pub pos: Pos,
18}
19
20/* -------------------------------------------------------------------------- */
21
22/// A boxed dynamic callback for a node context menu.
23pub(crate) type NodeContextMenuContent<'a, G> =
24 Box<dyn FnMut(&mut Ui, NodeMenuContext<'_, G>) + 'a>;
25
26/// Contextual information for graph editor's node context menu.
27pub struct NodeMenuContext<'a, G: GraphAdapter> {
28 /// A mutable reference of the [`GraphAdapter`] used by the editor.
29 pub graph: &'a mut G,
30
31 /// The identifier of the node.
32 pub node_id: G::NodeId,
33}
34
35/* -------------------------------------------------------------------------- */
36
37/// A boxed dynamic callback for a socket context menu.
38pub(crate) type SocketContextMenuContent<'a, G> =
39 Box<dyn FnMut(&mut Ui, SocketMenuContext<'_, G>) + 'a>;
40
41/// Contextual information for graph editor's socket context menu.
42pub struct SocketMenuContext<'a, G: GraphAdapter> {
43 /// A mutable reference of the [`GraphAdapter`] used by the editor.
44 pub graph: &'a mut G,
45
46 /// The identifier of the socket.
47 pub socket_id: G::SocketId,
48}
49
50/* -------------------------------------------------------------------------- */