setzer22 / egui_node_graph

Build your node graph applications in Rust, using egui
MIT License
711 stars 132 forks source link

Expose UserState and the node id to value_widget #69

Closed setzer22 closed 1 year ago

setzer22 commented 1 year ago

This changes the signature for value_widget to provide additional information:

    fn value_widget(
        &mut self,
        param_name: &str,
        node_id: NodeId, // NEW
        ui: &mut egui::Ui,
        user_state: &mut Self::UserState, // NEW
    ) -> Vec<Self::Response>;

This allows more flexible implementations for inline widgets, where the behavior of the widget depends not only on the ValueType but additional data that might be stored in the UserState.

setzer22 commented 1 year ago

Also exposed UserState to the three methods in NodeTemplateTrait. This is useful for when the NodeTemplate struct does not contain the data, but some key to that data. Users can then store the actual table inside UserState and query it when needed.

setzer22 commented 1 year ago

Finally, this also adds the NodeData parameter when drawing the value widget. This required an extra Default trait bound, which hopefully shouldn't cause too much trouble on user crates. An unsafe solution exists that didn't require the trait bound, but I don't consider it worth it.