NodeTemplateTrait

Trait NodeTemplateTrait 

Source
pub trait NodeTemplateTrait: Clone {
    type NodeData;
    type DataType;
    type ValueType;
    type UserState;
    type CategoryType;

    // Required methods
    fn node_finder_label(
        &self,
        user_state: &mut Self::UserState,
    ) -> Cow<'_, str>;
    fn node_graph_label(&self, user_state: &mut Self::UserState) -> String;
    fn user_data(&self, user_state: &mut Self::UserState) -> Self::NodeData;
    fn build_node(
        &self,
        graph: &mut Graph<Self::NodeData, Self::DataType, Self::ValueType>,
        user_state: &mut Self::UserState,
        node_id: NodeId,
    );

    // Provided method
    fn node_finder_categories(
        &self,
        _user_state: &mut Self::UserState,
    ) -> Vec<Self::CategoryType> { ... }
}
Expand description

This trait must be implemented by the NodeTemplate generic parameter of the GraphEditorState. It allows the customization of node templates. A node template is what describes what kinds of nodes can be added to the graph, what is their name, and what are their input / output parameters.

Required Associated Types§

Source

type NodeData

Must be set to the custom user NodeData type

Source

type DataType

Must be set to the custom user DataType type

Source

type ValueType

Must be set to the custom user ValueType type

Source

type UserState

Must be set to the custom user UserState type

Source

type CategoryType

Must be a type that implements the CategoryTrait trait.

&'static str is a good default if you intend to simply type out the categories of your node. Use () if you don’t need categories at all.

Required Methods§

Source

fn node_finder_label(&self, user_state: &mut Self::UserState) -> Cow<'_, str>

Returns a descriptive name for the node kind, used in the node finder.

The return type is Cow to allow returning owned or borrowed values more flexibly. Refer to the documentation for DataTypeTrait::name for more information

Source

fn node_graph_label(&self, user_state: &mut Self::UserState) -> String

Returns a descriptive name for the node kind, used in the graph.

Source

fn user_data(&self, user_state: &mut Self::UserState) -> Self::NodeData

Returns the user data for this node kind.

Source

fn build_node( &self, graph: &mut Graph<Self::NodeData, Self::DataType, Self::ValueType>, user_state: &mut Self::UserState, node_id: NodeId, )

This function is run when this node kind gets added to the graph. The node will be empty by default, and this function can be used to fill its parameters.

Provided Methods§

Source

fn node_finder_categories( &self, _user_state: &mut Self::UserState, ) -> Vec<Self::CategoryType>

Vec of categories to which the node belongs.

It’s often useful to organize similar nodes into categories, which will then be used by the node finder to show a more manageable UI, especially if the node template are numerous.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§