Expose UserState and the node id to value_widget

This commit is contained in:
Setzer22 2022-10-29 15:43:55 +02:00
parent b65a780f35
commit 79fbe31482
3 changed files with 19 additions and 5 deletions

View File

@ -76,7 +76,7 @@ where
ValueType = ValueType, ValueType = ValueType,
>, >,
UserResponse: UserResponseTrait, UserResponse: UserResponseTrait,
ValueType: WidgetValueTrait<Response = UserResponse>, ValueType: WidgetValueTrait<Response = UserResponse, UserState = UserState>,
NodeTemplate: NodeTemplateTrait< NodeTemplate: NodeTemplateTrait<
NodeData = NodeData, NodeData = NodeData,
DataType = DataType, DataType = DataType,
@ -391,7 +391,7 @@ where
ValueType = ValueType, ValueType = ValueType,
>, >,
UserResponse: UserResponseTrait, UserResponse: UserResponseTrait,
ValueType: WidgetValueTrait<Response = UserResponse>, ValueType: WidgetValueTrait<Response = UserResponse, UserState = UserState>,
DataType: DataTypeTrait<UserState>, DataType: DataTypeTrait<UserState>,
{ {
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0]; pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
@ -472,7 +472,7 @@ where
responses.extend( responses.extend(
self.graph[param_id] self.graph[param_id]
.value .value
.value_widget(&param_name, ui) .value_widget(&param_name, self.node_id, ui, user_state)
.into_iter() .into_iter()
.map(NodeResponse::User), .map(NodeResponse::User),
); );

View File

@ -5,11 +5,18 @@ use super::*;
/// types of the node graph. /// types of the node graph.
pub trait WidgetValueTrait { pub trait WidgetValueTrait {
type Response; type Response;
type UserState;
/// This method will be called for each input parameter with a widget. The /// This method will be called for each input parameter with a widget. The
/// return value is a vector of custom response objects which can be used /// return value is a vector of custom response objects which can be used
/// to implement handling of side effects. If unsure, the response Vec can /// to implement handling of side effects. If unsure, the response Vec can
/// be empty. /// be empty.
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec<Self::Response>; fn value_widget(
&mut self,
param_name: &str,
node_id: NodeId,
ui: &mut egui::Ui,
user_state: &mut Self::UserState,
) -> Vec<Self::Response>;
} }
/// This trait must be implemented by the `DataType` generic parameter of the /// This trait must be implemented by the `DataType` generic parameter of the

View File

@ -258,7 +258,14 @@ impl NodeTemplateIter for AllMyNodeTemplates {
impl WidgetValueTrait for MyValueType { impl WidgetValueTrait for MyValueType {
type Response = MyResponse; type Response = MyResponse;
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec<MyResponse> { type UserState = MyGraphState;
fn value_widget(
&mut self,
param_name: &str,
_node_id: NodeId,
ui: &mut egui::Ui,
_user_state: &mut MyGraphState,
) -> Vec<MyResponse> {
// This trait is used to tell the library which UI to display for the // This trait is used to tell the library which UI to display for the
// inline parameter widgets. // inline parameter widgets.
match self { match self {